Commit 3847b1b2 authored by tnurnberg@white.intern.koehntopp.de's avatar tnurnberg@white.intern.koehntopp.de
Browse files

Merge tnurnberg@bk-internal.mysql.com:/home/bk/mysql-5.0-opt

into  mysql.com:/misc/mysql/31700/50-31700
parents 4c1ff7b5 8b21045f
Loading
Loading
Loading
Loading
+65 −0
Original line number Diff line number Diff line
@@ -1113,3 +1113,68 @@ c b
3	1
3	2
DROP TABLE t1;
CREATE TABLE t1(
id INT AUTO_INCREMENT PRIMARY KEY, 
c1 INT NOT NULL, 
c2 INT NOT NULL,
UNIQUE KEY (c2,c1));
INSERT INTO t1(c1,c2) VALUES (5,1), (4,1), (3,5), (2,3), (1,3);
SELECT * FROM t1 ORDER BY c1;
id	c1	c2
5	1	3
4	2	3
3	3	5
2	4	1
1	5	1
SELECT * FROM t1 GROUP BY id ORDER BY c1;
id	c1	c2
5	1	3
4	2	3
3	3	5
2	4	1
1	5	1
SELECT * FROM t1 GROUP BY id ORDER BY id DESC;
id	c1	c2
5	1	3
4	2	3
3	3	5
2	4	1
1	5	1
SELECT * FROM t1 GROUP BY c2 ,c1, id ORDER BY c2, c1;
id	c1	c2
2	4	1
1	5	1
5	1	3
4	2	3
3	3	5
SELECT * FROM t1 GROUP BY c2, c1, id ORDER BY c2 DESC, c1;
id	c1	c2
3	3	5
5	1	3
4	2	3
2	4	1
1	5	1
SELECT * FROM t1 GROUP BY c2, c1, id ORDER BY c2 DESC, c1 DESC;
id	c1	c2
3	3	5
4	2	3
5	1	3
1	5	1
2	4	1
SELECT * FROM t1 GROUP BY c2  ORDER BY c2, c1;
id	c1	c2
1	5	1
4	2	3
3	3	5
SELECT * FROM t1 GROUP BY c2  ORDER BY c2 DESC, c1;
id	c1	c2
3	3	5
4	2	3
1	5	1
SELECT * FROM t1 GROUP BY c2  ORDER BY c2 DESC, c1 DESC;
id	c1	c2
3	3	5
4	2	3
1	5	1
DROP TABLE t1;
End of 5.0 tests
+49 −0
Original line number Diff line number Diff line
@@ -4150,4 +4150,53 @@ SELECT ((a1,a2) IN (SELECT * FROM t2 WHERE b2 > 0)) IS NULL FROM t1;
0
0
DROP TABLE t1, t2;
CREATE TABLE t1 (s1 BINARY(5), s2 VARBINARY(5));
INSERT INTO t1 VALUES (0x41,0x41), (0x42,0x42), (0x43,0x43);
SELECT s1, s2 FROM t1 WHERE s2 IN (SELECT s1 FROM t1);
s1	s2
SELECT s1, s2 FROM t1 WHERE (s2, 10) IN (SELECT s1, 10 FROM t1);
s1	s2
CREATE INDEX I1 ON t1 (s1);
CREATE INDEX I2 ON t1 (s2);
SELECT s1, s2 FROM t1 WHERE s2 IN (SELECT s1 FROM t1);
s1	s2
SELECT s1, s2 FROM t1 WHERE (s2, 10) IN (SELECT s1, 10 FROM t1);
s1	s2
TRUNCATE t1;
INSERT INTO t1 VALUES (0x41,0x41);
SELECT * FROM t1 WHERE s1 = (SELECT s2 FROM t1);
s1	s2
DROP TABLE t1;
CREATE TABLE t1 (a1 VARBINARY(2) NOT NULL DEFAULT '0', PRIMARY KEY (a1));
CREATE TABLE t2 (a2 BINARY(2) default '0', INDEX (a2));
CREATE TABLE t3 (a3 BINARY(2) default '0');
INSERT INTO t1 VALUES (1),(2),(3),(4);
INSERT INTO t2 VALUES (1),(2),(3);
INSERT INTO t3 VALUES (1),(2),(3);
SELECT LEFT(t2.a2, 1) FROM t2,t3 WHERE t3.a3=t2.a2;
LEFT(t2.a2, 1)
1
2
3
SELECT t1.a1, t1.a1 in (SELECT t2.a2 FROM t2,t3 WHERE t3.a3=t2.a2) FROM t1;
a1	t1.a1 in (SELECT t2.a2 FROM t2,t3 WHERE t3.a3=t2.a2)
1	0
2	0
3	0
4	0
DROP TABLE t1,t2,t3;
CREATE TABLE t1 (a1 BINARY(3) PRIMARY KEY, b1 VARBINARY(3));
CREATE TABLE t2 (a2 VARBINARY(3) PRIMARY KEY);
CREATE TABLE t3 (a3 VARBINARY(3) PRIMARY KEY);
INSERT INTO t1 VALUES (1,10), (2,20), (3,30), (4,40);
INSERT INTO t2 VALUES (2), (3), (4), (5);
INSERT INTO t3 VALUES (10), (20), (30);
SELECT LEFT(t1.a1,1) FROM t1,t3 WHERE t1.b1=t3.a3;
LEFT(t1.a1,1)
1
2
3
SELECT a2 FROM t2 WHERE t2.a2 IN (SELECT t1.a1 FROM t1,t3 WHERE t1.b1=t3.a3);
a2
DROP TABLE t1, t2, t3;
End of 5.0 tests.
+35 −0
Original line number Diff line number Diff line
@@ -815,3 +815,38 @@ EXPLAIN SELECT c,b FROM t1 GROUP BY c,b;
SELECT c,b   FROM t1 GROUP BY c,b;

DROP TABLE t1;

#
# Bug #32202: ORDER BY not working with GROUP BY
#

CREATE TABLE t1(
  id INT AUTO_INCREMENT PRIMARY KEY, 
  c1 INT NOT NULL, 
  c2 INT NOT NULL,
  UNIQUE KEY (c2,c1));

INSERT INTO t1(c1,c2) VALUES (5,1), (4,1), (3,5), (2,3), (1,3);

# Show that the test cases from the bug report pass
SELECT * FROM t1 ORDER BY c1;
SELECT * FROM t1 GROUP BY id ORDER BY c1;

# Show that DESC is handled correctly
SELECT * FROM t1 GROUP BY id ORDER BY id DESC;

# Show that results are correctly ordered when ORDER BY fields
# are a subset of GROUP BY ones
SELECT * FROM t1 GROUP BY c2 ,c1, id ORDER BY c2, c1;
SELECT * FROM t1 GROUP BY c2, c1, id ORDER BY c2 DESC, c1;
SELECT * FROM t1 GROUP BY c2, c1, id ORDER BY c2 DESC, c1 DESC;

# Show that results are correctly ordered when GROUP BY fields
# are a subset of ORDER BY ones
SELECT * FROM t1 GROUP BY c2  ORDER BY c2, c1;
SELECT * FROM t1 GROUP BY c2  ORDER BY c2 DESC, c1;
SELECT * FROM t1 GROUP BY c2  ORDER BY c2 DESC, c1 DESC;

DROP TABLE t1;

--echo End of 5.0 tests
+42 −0
Original line number Diff line number Diff line
@@ -3002,4 +3002,46 @@ INSERT INTO t2 VALUES (103, 203);
SELECT ((a1,a2) IN (SELECT * FROM t2 WHERE b2 > 0)) IS NULL FROM t1;
DROP TABLE t1, t2;

#
# Bug #28076: inconsistent binary/varbinary comparison
#

CREATE TABLE t1 (s1 BINARY(5), s2 VARBINARY(5));
INSERT INTO t1 VALUES (0x41,0x41), (0x42,0x42), (0x43,0x43);

SELECT s1, s2 FROM t1 WHERE s2 IN (SELECT s1 FROM t1);
SELECT s1, s2 FROM t1 WHERE (s2, 10) IN (SELECT s1, 10 FROM t1);

CREATE INDEX I1 ON t1 (s1);
CREATE INDEX I2 ON t1 (s2);

SELECT s1, s2 FROM t1 WHERE s2 IN (SELECT s1 FROM t1);
SELECT s1, s2 FROM t1 WHERE (s2, 10) IN (SELECT s1, 10 FROM t1);

TRUNCATE t1;
INSERT INTO t1 VALUES (0x41,0x41);
SELECT * FROM t1 WHERE s1 = (SELECT s2 FROM t1);

DROP TABLE t1;

CREATE TABLE t1 (a1 VARBINARY(2) NOT NULL DEFAULT '0', PRIMARY KEY (a1));
CREATE TABLE t2 (a2 BINARY(2) default '0', INDEX (a2));
CREATE TABLE t3 (a3 BINARY(2) default '0');
INSERT INTO t1 VALUES (1),(2),(3),(4);
INSERT INTO t2 VALUES (1),(2),(3);
INSERT INTO t3 VALUES (1),(2),(3);
SELECT LEFT(t2.a2, 1) FROM t2,t3 WHERE t3.a3=t2.a2;
SELECT t1.a1, t1.a1 in (SELECT t2.a2 FROM t2,t3 WHERE t3.a3=t2.a2) FROM t1;
DROP TABLE t1,t2,t3;

CREATE TABLE t1 (a1 BINARY(3) PRIMARY KEY, b1 VARBINARY(3));
CREATE TABLE t2 (a2 VARBINARY(3) PRIMARY KEY);
CREATE TABLE t3 (a3 VARBINARY(3) PRIMARY KEY);
INSERT INTO t1 VALUES (1,10), (2,20), (3,30), (4,40);
INSERT INTO t2 VALUES (2), (3), (4), (5);
INSERT INTO t3 VALUES (10), (20), (30);
SELECT LEFT(t1.a1,1) FROM t1,t3 WHERE t1.b1=t3.a3;
SELECT a2 FROM t2 WHERE t2.a2 IN (SELECT t1.a1 FROM t1,t3 WHERE t1.b1=t3.a3);
DROP TABLE t1, t2, t3;

--echo End of 5.0 tests.
+12 −4
Original line number Diff line number Diff line
@@ -6259,9 +6259,9 @@ bool field_is_equal_to_item(Field *field,Item *item)
  return result == field->val_real();
}

Item_cache* Item_cache::get_cache(Item_result type)
Item_cache* Item_cache::get_cache(const Item *item)
{
  switch (type) {
  switch (item->result_type()) {
  case INT_RESULT:
    return new Item_cache_int();
  case REAL_RESULT:
@@ -6269,7 +6269,7 @@ Item_cache* Item_cache::get_cache(Item_result type)
  case DECIMAL_RESULT:
    return new Item_cache_decimal();
  case STRING_RESULT:
    return new Item_cache_str();
    return new Item_cache_str(item);
  case ROW_RESULT:
    return new Item_cache_row();
  default:
@@ -6447,6 +6447,14 @@ my_decimal *Item_cache_str::val_decimal(my_decimal *decimal_val)
}


int Item_cache_str::save_in_field(Field *field, bool no_conversions)
{
  int res= Item_cache::save_in_field(field, no_conversions);
  return (is_varbinary && field->type() == MYSQL_TYPE_STRING &&
          value->length() < field->field_length) ? 1 : res;
}


bool Item_cache_row::allocate(uint num)
{
  item_count= num;
@@ -6465,7 +6473,7 @@ bool Item_cache_row::setup(Item * item)
  {
    Item *el= item->element_index(i);
    Item_cache *tmp;
    if (!(tmp= values[i]= Item_cache::get_cache(el->result_type())))
    if (!(tmp= values[i]= Item_cache::get_cache(el)))
      return 1;
    tmp->setup(el);
  }
Loading