From 2d120d32fa66a24cfec5d083205a434ec617bb1a Mon Sep 17 00:00:00 2001 From: "bell@sanja.is.com.ua" <> Date: Thu, 26 Jun 2003 11:09:11 +0300 Subject: [PATCH] cond_count moved to SELECT_LEX_NODE fixed BUG #726 --- 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)