Commit 946c48ba authored by unknown's avatar unknown
Browse files

Merge sanja.is.com.ua:/home/bell/mysql/bk/mysql-4.1

into sanja.is.com.ua:/home/bell/mysql/bk/work-bugs-4.1

parents 8f405690 43821a83
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -294,6 +294,21 @@ grp
select group_concat(c order by (select mid(group_concat(c order by a),1,5) from t2 where t2.a=t1.a) desc) as grp from t1;
grp
2,4,3,5
select t1.a, group_concat(c order by (select c from t2 where t2.a=t1.a limit 1)) as grp from t1 group by 1;
a	grp
1	2
2	4,3
3	5
select t1.a, group_concat(c order by (select mid(group_concat(c order by a),1,5) from t2 where t2.a=t1.a)) as grp from t1 group by 1;
a	grp
1	2
2	4,3
3	5
select t1.a, group_concat(c order by (select mid(group_concat(c order by a),1,5) from t2 where t2.a=t1.a) desc) as grp from t1 group by 1;
a	grp
1	2
2	4,3
3	5
select a,c,(select group_concat(c order by a) from t2 where a=t1.a) as grp from t1 order by grp;
a	c	grp
3	5	3,3
+51 −0
Original line number Diff line number Diff line
@@ -1912,3 +1912,54 @@ a
1
2
drop table t1,t2;
CREATE TABLE `t1` ( `aid` int(11) NOT NULL default '0', `bid` int(11) NOT NULL default '0', PRIMARY KEY  (`aid`,`bid`));
CREATE TABLE `t2` ( `aid` int(11) NOT NULL default '0', `bid` int(11) NOT NULL default '0', PRIMARY KEY  (`aid`,`bid`));
insert into t1 values (1,1),(1,2),(2,1),(2,2);
insert into t2 values (1,2),(2,2);
select * from t1 where t1.aid not in (select aid from t2 where bid=t1.bid);
aid	bid
1	1
2	1
alter table t2 drop primary key;
alter table t2 add key KEY1 (aid, bid);
select * from t1 where t1.aid not in (select aid from t2 where bid=t1.bid);
aid	bid
1	1
2	1
alter table t2 drop key KEY1;
alter table t2 add primary key (bid, aid);
select * from t1 where t1.aid not in (select aid from t2 where bid=t1.bid);
aid	bid
1	1
2	1
drop table t1,t2;
CREATE TABLE t1 (howmanyvalues bigint, avalue int);
INSERT INTO t1 VALUES (1, 1),(2, 1),(2, 2),(3, 1),(3, 2),(3, 3),(4, 1),(4, 2),(4, 3),(4, 4);
SELECT howmanyvalues, count(*) from t1 group by howmanyvalues;
howmanyvalues	count(*)
1	1
2	2
3	3
4	4
SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues = a.howmanyvalues) as mycount from t1 a group by a.howmanyvalues;
howmanyvalues	mycount
1	1
2	2
3	3
4	4
CREATE INDEX t1_howmanyvalues_idx ON t1 (howmanyvalues);
SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues+1 = a.howmanyvalues+1) as mycount from t1 a group by a.howmanyvalues;
howmanyvalues	mycount
1	1
2	2
3	3
4	4
SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues = a.howmanyvalues) as mycount from t1 a group by a.howmanyvalues;
howmanyvalues	mycount
1	1
2	2
3	3
4	4
SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues = a.avalue) as mycount from t1 a group by a.howmanyvalues;
ERROR 42S22: Unknown column 'a.avalue' in 'where clause'
drop table t1;
+3 −1
Original line number Diff line number Diff line
@@ -169,9 +169,11 @@ create table t2 (a int, c int);
insert into t2 values (1, 5), (2, 4), (3, 3), (3,3);
select group_concat(c) from t1;
select group_concat(c order by (select c from t2 where t2.a=t1.a limit 1)) as grp from t1;

select group_concat(c order by (select mid(group_concat(c order by a),1,5) from t2 where t2.a=t1.a)) as grp from t1;
select group_concat(c order by (select mid(group_concat(c order by a),1,5) from t2 where t2.a=t1.a) desc) as grp from t1;
select t1.a, group_concat(c order by (select c from t2 where t2.a=t1.a limit 1)) as grp from t1 group by 1;
select t1.a, group_concat(c order by (select mid(group_concat(c order by a),1,5) from t2 where t2.a=t1.a)) as grp from t1 group by 1;
select t1.a, group_concat(c order by (select mid(group_concat(c order by a),1,5) from t2 where t2.a=t1.a) desc) as grp from t1 group by 1;

# The following returns random results as we are sorting on blob addresses
# select group_concat(c order by (select group_concat(c order by a) from t2 where t2.a=t1.a)) as grp from t1;
+28 −0
Original line number Diff line number Diff line
@@ -1234,4 +1234,32 @@ select a,b from t1 where match(b) against ('Ball') > 0;
select a from t2 where a in (select a from t1 where match(b) against ('Ball') > 0); 
drop table t1,t2;

#
# Optimized IN with compound index
#
CREATE TABLE `t1` ( `aid` int(11) NOT NULL default '0', `bid` int(11) NOT NULL default '0', PRIMARY KEY  (`aid`,`bid`));
CREATE TABLE `t2` ( `aid` int(11) NOT NULL default '0', `bid` int(11) NOT NULL default '0', PRIMARY KEY  (`aid`,`bid`));
insert into t1 values (1,1),(1,2),(2,1),(2,2);
insert into t2 values (1,2),(2,2);
select * from t1 where t1.aid not in (select aid from t2 where bid=t1.bid);
alter table t2 drop primary key;
alter table t2 add key KEY1 (aid, bid);
select * from t1 where t1.aid not in (select aid from t2 where bid=t1.bid);
alter table t2 drop key KEY1;
alter table t2 add primary key (bid, aid);
select * from t1 where t1.aid not in (select aid from t2 where bid=t1.bid);
drop table t1,t2;

#
# resolving fields of grouped outer SELECT
#
CREATE TABLE t1 (howmanyvalues bigint, avalue int);
INSERT INTO t1 VALUES (1, 1),(2, 1),(2, 2),(3, 1),(3, 2),(3, 3),(4, 1),(4, 2),(4, 3),(4, 4);
SELECT howmanyvalues, count(*) from t1 group by howmanyvalues;
SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues = a.howmanyvalues) as mycount from t1 a group by a.howmanyvalues;
CREATE INDEX t1_howmanyvalues_idx ON t1 (howmanyvalues);
SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues+1 = a.howmanyvalues+1) as mycount from t1 a group by a.howmanyvalues;
SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues = a.howmanyvalues) as mycount from t1 a group by a.howmanyvalues;
-- error 1054
SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues = a.avalue) as mycount from t1 a group by a.howmanyvalues;
drop table t1;
+46 −24
Original line number Diff line number Diff line
@@ -60,10 +60,10 @@ Item::Item():
  */
  if (thd->lex->current_select)
  {
    SELECT_LEX_NODE::enum_parsing_place place= 
    enum_parsing_place place= 
      thd->lex->current_select->parsing_place;
    if (place == SELECT_LEX_NODE::SELECT_LIST ||
	place == SELECT_LEX_NODE::IN_HAVING)
    if (place == SELECT_LIST ||
	place == IN_HAVING)
      thd->lex->current_select->select_n_having_items++;
  }
}
@@ -1233,12 +1233,25 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
	  table_list= (last= sl)->get_table_list();
	  if (sl->resolve_mode == SELECT_LEX::INSERT_MODE && table_list)
	  {
	    // it is primary INSERT st_select_lex => skip first table resolving
            /*
              it is primary INSERT st_select_lex => skip first table
              resolving
            */
	    table_list= table_list->next;
	  }

	  Item_subselect *prev_subselect_item= prev_unit->item;
	  if ((tmp= find_field_in_tables(thd, this,
          enum_parsing_place place=
            prev_subselect_item->parsing_place;
          /*
            check table fields only if subquery used somewhere out of HAVING
            or SELECT list or outer SELECT do not use groupping (i.e. tables
            are accessable)
          */
          if (((place != IN_HAVING &&
                place != SELECT_LIST) ||
               (sl->with_sum_func == 0 && sl->group_list.elements == 0)) &&
              (tmp= find_field_in_tables(thd, this,
                                         table_list, &where,
                                         0)) != not_found_field)
          {
@@ -1906,7 +1919,17 @@ bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference)
	  // it is primary INSERT st_select_lex => skip first table resolving
	  table_list= table_list->next;
	}
	if ((tmp= find_field_in_tables(thd, this,
        enum_parsing_place place=
            prev_subselect_item->parsing_place;
        /*
          check table fields only if subquery used somewhere out of HAVING
          or SELECT list or outer SELECT do not use groupping (i.e. tables
          are accessable)
        */
        if (((place != IN_HAVING &&
              place != SELECT_LIST) ||
             (sl->with_sum_func == 0 && sl->group_list.elements == 0)) &&
            (tmp= find_field_in_tables(thd, this,
                                       table_list, &where,
                                       0)) != not_found_field)
        {
@@ -1914,7 +1937,6 @@ bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference)
          prev_subselect_item->const_item_cache= 0;
          break;
        }

        // Reference is not found => depend from outer (or just error)
	prev_subselect_item->used_tables_cache|= OUTER_REF_TABLE_BIT;
	prev_subselect_item->const_item_cache= 0;
Loading