From e0c9de6e62a199ec48ac1c910de4bcad28425c76 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 31 May 2003 15:44:19 +0600 Subject: [PATCH 1/4] URGENT SCRUM BUG correct wrong code in group_concat mysql-test/r/func_gconcat.result: add new tests mysql-test/t/func_gconcat.test: add new tests sql/field.cc: add new variable for group_concat sql/field.h: add new variable for group_concat sql/item_sum.cc: correct wrong code sql/item_sum.h: correct wrong code --- mysql-test/r/func_gconcat.result | 20 ++++++- mysql-test/t/func_gconcat.test | 16 +++++- sql/field.cc | 2 +- sql/field.h | 1 + sql/item_sum.cc | 97 ++++++++++++++++++-------------- sql/item_sum.h | 29 +++++++--- 6 files changed, 111 insertions(+), 54 deletions(-) diff --git a/mysql-test/r/func_gconcat.result b/mysql-test/r/func_gconcat.result index 0dc84f090f1..f2246f2e514 100644 --- a/mysql-test/r/func_gconcat.result +++ b/mysql-test/r/func_gconcat.result @@ -154,8 +154,26 @@ Warning 1258 1 line(s) was(were) cut by group_concat() show warnings; Level Code Message Warning 1258 1 line(s) was(were) cut by group_concat() +set group_concat_max_len = 1024; +drop table if exists T_URL; +Warnings: +Note 1051 Unknown table 'T_URL' +create table T_URL ( URL_ID int(11), URL varchar(80)); +drop table if exists T_REQUEST; +Warnings: +Note 1051 Unknown table 'T_REQUEST' +create table T_REQUEST ( REQ_ID int(11), URL_ID int(11)); +insert into T_URL values (4,'www.host.com'), (5,'www.google.com'),(5,'www.help.com'); +insert into T_REQUEST values (1,4), (5,4), (5,5); +select REQ_ID, Group_Concat(URL) as URL from T_URL, T_REQUEST where +T_REQUEST.URL_ID = T_URL.URL_ID group by REQ_ID; +REQ_ID URL +1 www.host.com +5 www.host.com,www.google.com,www.help.com +drop table T_URL; +drop table T_REQUEST; select group_concat(sum(a)) from t1 group by grp; Invalid use of group function select grp,group_concat(c order by 2) from t1 group by grp; Unknown column '2' in 'group statement' -drop table if exists t1; +drop table t1; diff --git a/mysql-test/t/func_gconcat.test b/mysql-test/t/func_gconcat.test index 0a95410e842..a5a7abe3b01 100644 --- a/mysql-test/t/func_gconcat.test +++ b/mysql-test/t/func_gconcat.test @@ -68,6 +68,20 @@ select grp,group_concat(c order by c) from t1 group by grp; set group_concat_max_len = 5; select grp,group_concat(c) from t1 group by grp; show warnings; +set group_concat_max_len = 1024; + +# Test variable length + +drop table if exists T_URL; +create table T_URL ( URL_ID int(11), URL varchar(80)); +drop table if exists T_REQUEST; +create table T_REQUEST ( REQ_ID int(11), URL_ID int(11)); +insert into T_URL values (4,'www.host.com'), (5,'www.google.com'),(5,'www.help.com'); +insert into T_REQUEST values (1,4), (5,4), (5,5); +select REQ_ID, Group_Concat(URL) as URL from T_URL, T_REQUEST where +T_REQUEST.URL_ID = T_URL.URL_ID group by REQ_ID; +drop table T_URL; +drop table T_REQUEST; # Test errors @@ -76,4 +90,4 @@ select group_concat(sum(a)) from t1 group by grp; --error 1054 select grp,group_concat(c order by 2) from t1 group by grp; -drop table if exists t1; +drop table t1; diff --git a/sql/field.cc b/sql/field.cc index 3695268a888..e54986ded22 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -175,7 +175,7 @@ Field::Field(char *ptr_arg,uint32 length_arg,uchar *null_ptr_arg, field_name(field_name_arg), query_id(0),key_start(0),part_of_key(0),part_of_sortkey(0), unireg_check(unireg_check_arg), - field_length(length_arg),null_bit(null_bit_arg) + field_length(length_arg),null_bit(null_bit_arg),abs_offset(0) { flags=null_ptr ? 0: NOT_NULL_FLAG; comment.str= (char*) ""; diff --git a/sql/field.h b/sql/field.h index 80bfc516ef7..088dae49c6f 100644 --- a/sql/field.h +++ b/sql/field.h @@ -62,6 +62,7 @@ public: uint32 field_length; // Length of field uint16 flags; uchar null_bit; // Bit used to test null bit + uint abs_offset; // use only in group_concat Field(char *ptr_arg,uint32 length_arg,uchar *null_ptr_arg,uchar null_bit_arg, utype unireg_check_arg, const char *field_name_arg, diff --git a/sql/item_sum.cc b/sql/item_sum.cc index 11c850f9d5f..8bd3e36b5db 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -1344,27 +1344,28 @@ String *Item_sum_udf_str::val_str(String *str) GROUP_CONCAT(DISTINCT expr,...) */ -static int group_concat_key_cmp_with_distinct(void* arg, byte* key1, - byte* key2) +int group_concat_key_cmp_with_distinct(void* arg, byte* key1, + byte* key2) { Item_func_group_concat* item= (Item_func_group_concat*)arg; + for (uint i= 0; i < item->arg_count_field; i++) { - Item *field_item= item->expr[i]; + Item *field_item= item->args[i]; Field *field= field_item->tmp_table_field(); if (field) { - uint offset= field->offset(); + uint offset= field->abs_offset; int res= field->key_cmp(key1 + offset, key2 + offset); /* if key1 and key2 is not equal than field->key_cmp return offset. This - function must return value 1 for this case. + function must return value 1 for this case. */ if (res) return 1; } - } + } return 0; } @@ -1374,9 +1375,10 @@ static int group_concat_key_cmp_with_distinct(void* arg, byte* key1, GROUP_CONCAT(expr,... ORDER BY col,... ) */ -static int group_concat_key_cmp_with_order(void* arg, byte* key1, byte* key2) +int group_concat_key_cmp_with_order(void* arg, byte* key1, byte* key2) { Item_func_group_concat* item= (Item_func_group_concat*)arg; + for (uint i=0; i < item->arg_count_order; i++) { ORDER *order_item= item->order[i]; @@ -1384,14 +1386,14 @@ static int group_concat_key_cmp_with_order(void* arg, byte* key1, byte* key2) Field *field= item->tmp_table_field(); if (field) { - uint offset= field->offset(); + uint offset= field->abs_offset; bool dir= order_item->asc; int res= field->key_cmp(key1 + offset, key2 + offset); if (res) return dir ? res : -res; } - } + } /* We can't return 0 because tree class remove this item as double value. */ @@ -1404,9 +1406,8 @@ static int group_concat_key_cmp_with_order(void* arg, byte* key1, byte* key2) GROUP_CONCAT(DISTINCT expr,... ORDER BY col,... ) */ -static int group_concat_key_cmp_with_distinct_and_order(void* arg, - byte* key1, - byte* key2) +int group_concat_key_cmp_with_distinct_and_order(void* arg,byte* key1, + byte* key2) { if (!group_concat_key_cmp_with_distinct(arg,key1,key2)) return 0; @@ -1419,24 +1420,23 @@ static int group_concat_key_cmp_with_distinct_and_order(void* arg, item is pointer to Item_func_group_concat */ -static int dump_leaf_key(byte* key, uint32 count __attribute__((unused)), +int dump_leaf_key(byte* key, uint32 count __attribute__((unused)), Item_func_group_concat *group_concat_item) { char buff[MAX_FIELD_WIDTH]; String tmp((char *)&buff,sizeof(buff),default_charset_info); String tmp2((char *)&buff,sizeof(buff),default_charset_info); - + tmp.length(0); for (uint i= 0; i < group_concat_item->arg_show_fields; i++) { - Item *show_item= group_concat_item->expr[i]; + Item *show_item= group_concat_item->args[i]; if (!show_item->const_item()) { Field *f= show_item->tmp_table_field(); - uint offset= f->offset(); char *sv= f->ptr; - f->ptr= (char *)key + offset; + f->ptr= (char *)key + f->abs_offset; String *res= f->val_str(&tmp,&tmp2); group_concat_item->result.append(*res); f->ptr= sv; @@ -1486,9 +1486,14 @@ Item_func_group_concat::Item_func_group_concat(bool is_distinct, List *is_select, SQL_LIST *is_order, String *is_separator) - :Item_sum(), tmp_table_param(0), warning_available(false), - separator(is_separator), tree(&tree_base), table(0), - count_cut_values(0), tree_mode(0), distinct(is_distinct) + :Item_sum(), tmp_table_param(0), max_elements_in_tree(0), warning(0), + warning_available(0), key_length(0), rec_offset(0), + tree_mode(0), distinct(is_distinct), warning_for_row(0), + separator(is_separator), tree(&tree_base), table(0), + order(0), tables_list(0), group_concat_max_len(0), + show_elements(0), arg_count_order(0), arg_count_field(0), + arg_show_fields(0), count_cut_values(0) + { original= 0; quick_group= 0; @@ -1504,16 +1509,12 @@ Item_func_group_concat::Item_func_group_concat(bool is_distinct, We need to allocate: args - arg_count+arg_count_order (for possible order items in temporare tables) - expr - arg_count_field order - arg_count_order */ - args= (Item**) sql_alloc(sizeof(Item*)*(arg_count+arg_count_order+ - arg_count_field)+ + args= (Item**) sql_alloc(sizeof(Item*)*(arg_count+arg_count_order)+ sizeof(ORDER*)*arg_count_order); if (!args) - return; // thd->fatal is set - expr= args; - expr+= arg_count+arg_count_order; + return; /* fill args items of show and sort */ int i= 0; @@ -1521,12 +1522,12 @@ Item_func_group_concat::Item_func_group_concat(bool is_distinct, Item *item_select; for ( ; (item_select= li++) ; i++) - args[i]= expr[i]= item_select; + args[i]= item_select; if (arg_count_order) { i= 0; - order= (ORDER**)(expr + arg_count_field); + order= (ORDER**)(args + arg_count + arg_count_order); for (ORDER *order_item= (ORDER*) is_order->first; order_item != NULL; order_item= order_item->next) @@ -1587,7 +1588,7 @@ bool Item_func_group_concat::add() bool record_is_null= TRUE; for (uint i= 0; i < arg_show_fields; i++) { - Item *show_item= expr[i]; + Item *show_item= args[i]; if (!show_item->const_item()) { Field *f= show_item->tmp_table_field(); @@ -1603,13 +1604,13 @@ bool Item_func_group_concat::add() null_value= FALSE; if (tree_mode) { - if (!tree_insert(tree, table->record[0], 0,tree->custom_arg)) + if (!tree_insert(tree, table->record[0] + rec_offset, 0, tree->custom_arg)) return 1; } else { if (result.length() <= group_concat_max_len && !warning_for_row) - dump_leaf_key(table->record[0],1, + dump_leaf_key(table->record[0] + rec_offset, 1, (Item_func_group_concat*)this); } return 0; @@ -1642,12 +1643,6 @@ Item_func_group_concat::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) return 1; maybe_null |= args[i]->maybe_null; } - for (i= 0 ; i < arg_count_field ; i++) - { - if (expr[i]->fix_fields(thd, tables, expr + i) || expr[i]->check_cols(1)) - return 1; - maybe_null |= expr[i]->maybe_null; - } /* Fix fields for order clause in function: GROUP_CONCAT(expr,... ORDER BY col,... ) @@ -1712,12 +1707,25 @@ bool Item_func_group_concat::setup(THD *thd) return 1; table->file->extra(HA_EXTRA_NO_ROWS); table->no_rows= 1; - qsort_cmp2 compare_key; - - tree_mode= distinct || arg_count_order; + + + Field** field, **field_end; + field_end = (field = table->field) + table->fields; + uint offset = 0; + for (key_length = 0; field < field_end; ++field) + { + uint32 length= (*field)->pack_length(); + (*field)->abs_offset= offset; + offset+= length; + key_length += length; + } + rec_offset = table->reclength - key_length; + /* choise function of sort */ + tree_mode= distinct || arg_count_order; + qsort_cmp2 compare_key; if (tree_mode) { if (arg_count_order) @@ -1741,9 +1749,9 @@ bool Item_func_group_concat::setup(THD *thd) */ init_tree(tree, min(thd->variables.max_heap_table_size, thd->variables.sortbuff_size/16), 0, - table->reclength, compare_key, 0, NULL, (void*) this); - max_elements_in_tree= ((table->reclength) ? - thd->variables.max_heap_table_size/table->reclength : 1); + key_length, compare_key, 0, NULL, (void*) this); + max_elements_in_tree= ((key_length) ? + thd->variables.max_heap_table_size/key_length : 1); }; item_thd= thd; @@ -1784,3 +1792,6 @@ String* Item_func_group_concat::val_str(String* str) } return &result; } + + + diff --git a/sql/item_sum.h b/sql/item_sum.h index 37d7e7f79d0..e306a42c6bc 100644 --- a/sql/item_sum.h +++ b/sql/item_sum.h @@ -640,13 +640,28 @@ class Item_func_group_concat : public Item_sum uint max_elements_in_tree; MYSQL_ERROR *warning; bool warning_available; + uint key_length; + int rec_offset; + bool tree_mode; + bool distinct; + bool warning_for_row; + bool always_null; + + friend int group_concat_key_cmp_with_distinct(void* arg, byte* key1, + byte* key2); + friend int group_concat_key_cmp_with_order(void* arg, byte* key1, byte* key2); + friend int group_concat_key_cmp_with_distinct_and_order(void* arg, + byte* key1, + byte* key2); + friend int dump_leaf_key(byte* key, uint32 count __attribute__((unused)), + Item_func_group_concat *group_concat_item); + public: String result; String *separator; TREE tree_base; TREE *tree; TABLE *table; - Item **expr; ORDER **order; TABLE_LIST *tables_list; ulong group_concat_max_len; @@ -655,9 +670,6 @@ class Item_func_group_concat : public Item_sum uint arg_count_field; uint arg_show_fields; uint count_cut_values; - bool tree_mode, distinct; - bool warning_for_row; - bool always_null; /* Following is 0 normal object and pointer to original one for copy (to correctly free resources) @@ -673,10 +685,14 @@ class Item_func_group_concat : public Item_sum max_elements_in_tree(item.max_elements_in_tree), warning(item.warning), warning_available(item.warning_available), + key_length(item.key_length), + rec_offset(item.rec_offset), + tree_mode(0), + distinct(item.distinct), + warning_for_row(item.warning_for_row), separator(item.separator), tree(item.tree), table(item.table), - expr(item.expr), order(item.order), tables_list(item.tables_list), group_concat_max_len(item.group_concat_max_len), @@ -685,9 +701,6 @@ class Item_func_group_concat : public Item_sum arg_count_field(item.arg_count_field), arg_show_fields(item.arg_show_fields), count_cut_values(item.count_cut_values), - tree_mode(0), - distinct(item.distinct), - warning_for_row(item.warning_for_row), original(&item) { quick_group = 0; From fbd157fa5754c5c1dac01ad824531aeb434426d7 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 3 Jun 2003 17:02:51 +0600 Subject: [PATCH 2/4] BUG correct bug with empty table sql/item_sum.cc: correct bug with empty table --- sql/item_sum.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sql/item_sum.cc b/sql/item_sum.cc index 8bd3e36b5db..60976ab993a 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -1582,6 +1582,8 @@ void Item_func_group_concat::reset() bool Item_func_group_concat::add() { + if (always_null) + return 0; copy_fields(tmp_table_param); copy_funcs(tmp_table_param->items_to_copy); @@ -1676,6 +1678,7 @@ bool Item_func_group_concat::setup(THD *thd) /* all not constant fields are push to list and create temp table */ + always_null= 0; for (uint i= 0; i < arg_count; i++) { Item *item= args[i]; @@ -1688,6 +1691,8 @@ bool Item_func_group_concat::setup(THD *thd) always_null= 1; } } + if (always_null) + return 0; List all_fields(list); if (arg_count_order) From 11e9c572ad1d81536902dd01d48c68ef00ce9018 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 26 Jun 2003 09:39:23 +0500 Subject: [PATCH 3/4] Bug fixed: mysql-test failure on rpl tests scripts/mysql_create_system_tables.sh: Fixed bug: mysql-test failure on rpl tests --- scripts/mysql_create_system_tables.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/mysql_create_system_tables.sh b/scripts/mysql_create_system_tables.sh index a98e1739260..2739c45e750 100644 --- a/scripts/mysql_create_system_tables.sh +++ b/scripts/mysql_create_system_tables.sh @@ -145,6 +145,7 @@ then then i_u="INSERT INTO user VALUES ('localhost','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0); INSERT INTO user VALUES ('$hostname','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0); + REPLACE INTO user VALUES ('127.0.0.1','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0); INSERT INTO user (host,user) values ('localhost',''); INSERT INTO user (host,user) values ('$hostname','');" else From 54cd790bf3bfb57624d516ad22c432c5a1ff7958 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 26 Jun 2003 11:09:11 +0300 Subject: [PATCH 4/4] cond_count moved to SELECT_LEX_NODE fixed BUG #726 mysql-test/r/subselect.result: test of bug #726 mysql-test/t/subselect.test: test of bug #726 sql/item_cmpfunc.cc: cond_count moved to SELECT_LEX_NODE sql/item_subselect.cc: fixed current_select pointer sql/sql_base.cc: cond_count moved to SELECT_LEX_NODE sql/sql_class.cc: cond_count moved to SELECT_LEX_NODE sql/sql_class.h: cond_count moved to SELECT_LEX_NODE sql/sql_lex.cc: cond_count moved to SELECT_LEX_NODE sql/sql_lex.h: cond_count moved to SELECT_LEX_NODE sql/sql_select.cc: cond_count moved to SELECT_LEX_NODE --- mysql-test/r/subselect.result | 25 +++++++++++++++++++++++++ mysql-test/t/subselect.test | 28 ++++++++++++++++++++++++++++ sql/item_cmpfunc.cc | 2 +- sql/item_subselect.cc | 9 ++++++--- sql/sql_base.cc | 6 +++--- sql/sql_class.cc | 1 - sql/sql_class.h | 2 +- sql/sql_lex.cc | 1 + sql/sql_lex.h | 1 + sql/sql_select.cc | 3 ++- 10 files changed, 68 insertions(+), 10 deletions(-) diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index c41434336e5..0f0ab501951 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -1151,3 +1151,28 @@ INSERT INTO t1 VALUES (1,0,NULL,NULL),(2,0,NULL,NULL); SELECT DISTINCT REF_ID FROM t1 WHERE ID= (SELECT DISTINCT REF_ID FROM t1 WHERE ID=2); REF_ID DROP TABLE t1; +CREATE TABLE t1 +( +FOLDERID VARCHAR(32)BINARY NOT NULL +, FOLDERNAME VARCHAR(255)BINARY NOT NULL +, CREATOR VARCHAR(255)BINARY +, CREATED TIMESTAMP NOT NULL +, DESCRIPTION VARCHAR(255)BINARY +, FOLDERTYPE INTEGER NOT NULL +, MODIFIED TIMESTAMP +, MODIFIER VARCHAR(255)BINARY +, FOLDERSIZE INTEGER NOT NULL +, PARENTID VARCHAR(32)BINARY +, REPID VARCHAR(32)BINARY +, ORIGINATOR INTEGER +, PRIMARY KEY ( FOLDERID ) +) TYPE=InnoDB; +CREATE INDEX FFOLDERID_IDX ON t1 (FOLDERID); +CREATE INDEX CMFLDRPARNT_IDX ON t1 (PARENTID); +INSERT INTO t1 VALUES("0c9aab05b15048c59bc35c8461507deb", "System", "System", "2003-06-05 16:30:00", "The system content repository folder.", "3", "2003-06-05 16:30:00", "System", "0", NULL, "9c9aab05b15048c59bc35c8461507deb", "1"); +INSERT INTO t1 VALUES("2f6161e879db43c1a5b82c21ddc49089", "Default", "System", "2003-06-09 10:52:02", "The default content repository folder.", "3", "2003-06-05 16:30:00", "System", "0", NULL, "03eea05112b845949f3fd03278b5fe43", "1"); +INSERT INTO t1 VALUES("c373e9f5ad0791724315444553544200", "AddDocumentTest", "admin", "2003-06-09 10:51:25", "Movie Reviews", "0", "2003-06-09 10:51:25", "admin", "0", "2f6161e879db43c1a5b82c21ddc49089", "03eea05112b845949f3fd03278b5fe43", NULL); +SELECT 'c373e9f5ad0791a0dab5444553544200' IN(SELECT t1.FOLDERID FROM t1 WHERE t1.PARENTID='2f6161e879db43c1a5b82c21ddc49089' AND t1.FOLDERNAME = 'Level1'); +'c373e9f5ad0791a0dab5444553544200' IN(SELECT t1.FOLDERID FROM t1 WHERE t1.PARENTID='2f6161e879db43c1a5b82c21ddc49089' AND t1.FOLDERNAME = 'Level1') +0 +drop table t1; diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test index 1528f53ff0d..cd51b8c4880 100644 --- a/mysql-test/t/subselect.test +++ b/mysql-test/t/subselect.test @@ -732,3 +732,31 @@ CREATE TABLE t1 ( INSERT INTO t1 VALUES (1,0,NULL,NULL),(2,0,NULL,NULL); SELECT DISTINCT REF_ID FROM t1 WHERE ID= (SELECT DISTINCT REF_ID FROM t1 WHERE ID=2); DROP TABLE t1; + +# +# key field overflow test +# +CREATE TABLE t1 +( +FOLDERID VARCHAR(32)BINARY NOT NULL +, FOLDERNAME VARCHAR(255)BINARY NOT NULL +, CREATOR VARCHAR(255)BINARY +, CREATED TIMESTAMP NOT NULL +, DESCRIPTION VARCHAR(255)BINARY +, FOLDERTYPE INTEGER NOT NULL +, MODIFIED TIMESTAMP +, MODIFIER VARCHAR(255)BINARY +, FOLDERSIZE INTEGER NOT NULL +, PARENTID VARCHAR(32)BINARY +, REPID VARCHAR(32)BINARY +, ORIGINATOR INTEGER + +, PRIMARY KEY ( FOLDERID ) +) TYPE=InnoDB; +CREATE INDEX FFOLDERID_IDX ON t1 (FOLDERID); +CREATE INDEX CMFLDRPARNT_IDX ON t1 (PARENTID); +INSERT INTO t1 VALUES("0c9aab05b15048c59bc35c8461507deb", "System", "System", "2003-06-05 16:30:00", "The system content repository folder.", "3", "2003-06-05 16:30:00", "System", "0", NULL, "9c9aab05b15048c59bc35c8461507deb", "1"); +INSERT INTO t1 VALUES("2f6161e879db43c1a5b82c21ddc49089", "Default", "System", "2003-06-09 10:52:02", "The default content repository folder.", "3", "2003-06-05 16:30:00", "System", "0", NULL, "03eea05112b845949f3fd03278b5fe43", "1"); +INSERT INTO t1 VALUES("c373e9f5ad0791724315444553544200", "AddDocumentTest", "admin", "2003-06-09 10:51:25", "Movie Reviews", "0", "2003-06-09 10:51:25", "admin", "0", "2f6161e879db43c1a5b82c21ddc49089", "03eea05112b845949f3fd03278b5fe43", NULL); +SELECT 'c373e9f5ad0791a0dab5444553544200' IN(SELECT t1.FOLDERID FROM t1 WHERE t1.PARENTID='2f6161e879db43c1a5b82c21ddc49089' AND t1.FOLDERNAME = 'Level1'); +drop table t1; diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 52bd14ed515..1713997e350 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -1638,7 +1638,7 @@ Item_cond::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) maybe_null=1; } if (thd) - thd->cond_count+=list.elements; + thd->lex.current_select->cond_count+=list.elements; fix_length_and_dec(); fixed= 1; return 0; diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index 11f218341bd..cd78edfee7b 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -824,6 +824,8 @@ int subselect_single_select_engine::exec() { DBUG_ENTER("subselect_single_select_engine::exec"); char const *save_where= join->thd->where; + SELECT_LEX_NODE *save_select= join->thd->lex.current_select; + join->thd->lex.current_select= select_lex; if (!optimized) { optimized=1; @@ -831,6 +833,7 @@ int subselect_single_select_engine::exec() { join->thd->where= save_where; executed= 1; + join->thd->lex.current_select= save_select; DBUG_RETURN(join->error?join->error:1); } } @@ -839,6 +842,7 @@ int subselect_single_select_engine::exec() if (join->reinit()) { join->thd->where= save_where; + join->thd->lex.current_select= save_select; DBUG_RETURN(1); } item->reset(); @@ -846,15 +850,14 @@ int subselect_single_select_engine::exec() } if (!executed) { - SELECT_LEX_NODE *save_select= join->thd->lex.current_select; - join->thd->lex.current_select= select_lex; join->exec(); - join->thd->lex.current_select= save_select; executed= 1; join->thd->where= save_where; + join->thd->lex.current_select= save_select; DBUG_RETURN(join->error||thd->is_fatal_error); } join->thd->where= save_where; + join->thd->lex.current_select= save_select; DBUG_RETURN(0); } diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 37bf94800d7..641ab46e5e0 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -2151,7 +2151,7 @@ int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds) DBUG_ENTER("setup_conds"); thd->set_query_id=1; - thd->cond_count= 0; + thd->lex.current_select->cond_count= 0; if (*conds) { thd->where="where clause"; @@ -2169,7 +2169,7 @@ int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds) if (table->on_expr->fix_fields(thd, tables, &table->on_expr) || table->on_expr->check_cols(1)) DBUG_RETURN(1); - thd->cond_count++; + thd->lex.current_select->cond_count++; /* If it's a normal join, add the ON/USING expression to the WHERE */ if (!table->outer_join) @@ -2215,7 +2215,7 @@ int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds) } } cond_and->used_tables_cache= t1->map | t2->map; - thd->cond_count+=cond_and->list.elements; + thd->lex.current_select->cond_count+=cond_and->list.elements; if (!table->outer_join) // Not left join { if (!(*conds=and_conds(*conds, cond_and))) diff --git a/sql/sql_class.cc b/sql/sql_class.cc index fb088b602b1..c233ffd422a 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -107,7 +107,6 @@ THD::THD():user_time(0), is_fatal_error(0), slave_thread = 0; variables.pseudo_thread_id= 0; file_id = 0; - cond_count=0; warn_id= 0; db_charset= global_system_variables.character_set_database; mysys_var=0; diff --git a/sql/sql_class.h b/sql/sql_class.h index db99fb443c8..ccfe2555518 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -520,7 +520,7 @@ public: ulong row_count; // Row counter, mainly for errors and warnings long dbug_thread_id; pthread_t real_id; - uint current_tablenr,tmp_table,cond_count; + uint current_tablenr,tmp_table; uint server_status,open_options; uint32 query_length; uint32 db_length; diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index bc9ad4f36b0..ba95d747ba2 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -967,6 +967,7 @@ void st_select_lex_node::init_query() linkage= UNSPECIFIED_TYPE; no_table_names_allowed= uncacheable= dependent= 0; ref_pointer_array= 0; + cond_count= 0; } void st_select_lex_node::init_select() diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 6226fbe1bb5..caeb0e67769 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -207,6 +207,7 @@ public: Item **ref_pointer_array; uint select_items; /* number of items in select_list */ + uint cond_count; /* number of arguments of and/or/xor in where/having */ enum_parsing_place parsing_place; /* where we are parsing expression */ bool with_sum_func; /* sum function indicator */ bool dependent; /* dependent from outer select subselect */ diff --git a/sql/sql_select.cc b/sql/sql_select.cc index cc80f80739b..642b3c8af88 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -2156,7 +2156,8 @@ update_ref_and_keys(THD *thd, DYNAMIC_ARRAY *keyuse,JOIN_TAB *join_tab, KEY_FIELD *key_fields,*end; if (!(key_fields=(KEY_FIELD*) - thd->alloc(sizeof(key_fields[0])*(thd->cond_count+1)*2))) + thd->alloc(sizeof(key_fields[0])* + (thd->lex.current_select->cond_count+1)*2))) return TRUE; /* purecov: inspected */ and_level=0; end=key_fields; if (cond)