From b685909d6a9e928885ee3e8fb266077718660f3e Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 15 Nov 2004 14:37:40 +0200 Subject: [PATCH 1/3] moved procedure list initialization (BUG#6517) mysql-test/r/subselect.result: Subselect in non-select command just after connection mysql-test/t/subselect.test: Subselect in non-select command just after connection sql/sql_lex.cc: moved procedure initialization sql/sql_parse.cc: moved procedure initialization --- mysql-test/r/subselect.result | 1 + mysql-test/t/subselect.test | 7 +++++++ sql/sql_lex.cc | 1 + sql/sql_parse.cc | 1 - 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index 32d482f5a32..9c8a237468a 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -1990,3 +1990,4 @@ ac 700 NULL drop tables t1,t2; +set @got_val= (SELECT 1 FROM (SELECT 'A' as my_col) as T1 ) ; diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test index e0f6fcbf515..19803f6e3ba 100644 --- a/mysql-test/t/subselect.test +++ b/mysql-test/t/subselect.test @@ -1282,3 +1282,10 @@ INSERT INTO `t2` VALUES (6,5,12,7,'a'),(12,0,0,7,'a'),(12,1,0,7,'a'),(12,5,5,7,' SELECT b.sc FROM (SELECT (SELECT a.access FROM t1 a WHERE a.map = op.map AND a.slave = op.pid AND a.master = 1) ac FROM t2 op WHERE op.id = 12 AND op.map = 0) b; SELECT b.ac FROM (SELECT (SELECT a.access FROM t1 a WHERE a.map = op.map AND a.slave = op.pid AND a.master = 1) ac FROM t2 op WHERE op.id = 12 AND op.map = 0) b; drop tables t1,t2; + +# +# Subselect in non-select command just after connection +# +connect (root,localhost,root,,test,$MASTER_MYPORT,$MASTER_MYSOCK); +connection root; +set @got_val= (SELECT 1 FROM (SELECT 'A' as my_col) as T1 ) ; diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 679ffb2140e..b5cb8735875 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -157,6 +157,7 @@ void lex_start(THD *thd, uchar *buf,uint length) lex->ignore_space=test(thd->variables.sql_mode & MODE_IGNORE_SPACE); lex->sql_command=SQLCOM_END; lex->duplicates= DUP_ERROR; + lex->proc_list.first= 0; } void lex_end(LEX *lex) diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 7420f9de100..078333c9552 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -3940,7 +3940,6 @@ mysql_init_select(LEX *lex) { DBUG_ASSERT(lex->result == 0); lex->exchange= 0; - lex->proc_list.first= 0; } } From dd93baa00da5e27f1a27df5762fe112f777f53c1 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 16 Nov 2004 00:16:04 +0200 Subject: [PATCH 2/3] fixed joincleunup to avoid double deletin tables, and too earlyfull cleanup in case of EXPLAIN fixed cleunup of TMP_TABLE_PARAM (BUG#6406) mysql-test/r/subselect.result: primary query with temporary table and subquery with groupping mysql-test/t/subselect.test: primary query with temporary table and subquery with groupping sql/sql_class.h: fixed cleunup of TMP_TABLE_PARAM sql/sql_select.cc: uncacheable test made simplier fixed joincleunup to avoid double deletin tables, and too earlyfull cleanup in case of EXPLAIN --- mysql-test/r/subselect.result | 12 ++++++++++++ mysql-test/t/subselect.test | 10 ++++++++++ sql/sql_class.h | 2 +- sql/sql_select.cc | 6 ++++-- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index 9c8a237468a..2d686285050 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -1991,3 +1991,15 @@ ac NULL drop tables t1,t2; set @got_val= (SELECT 1 FROM (SELECT 'A' as my_col) as T1 ) ; +create table t1 (a int, b int); +create table t2 (a int, b int); +insert into t1 values (1,1),(1,2),(1,3),(2,4),(2,5); +insert into t2 values (1,3),(2,1); +select distinct a,b, (select max(b) from t2 where t1.b=t2.a) from t1 order by t1.b; +a b (select max(b) from t2 where t1.b=t2.a) +1 1 3 +1 2 1 +1 3 NULL +2 4 NULL +2 5 NULL +drop table t1, t2; diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test index 19803f6e3ba..976ce7bf6b0 100644 --- a/mysql-test/t/subselect.test +++ b/mysql-test/t/subselect.test @@ -1289,3 +1289,13 @@ drop tables t1,t2; connect (root,localhost,root,,test,$MASTER_MYPORT,$MASTER_MYSOCK); connection root; set @got_val= (SELECT 1 FROM (SELECT 'A' as my_col) as T1 ) ; + +# +# primary query with temporary table and subquery with groupping +# +create table t1 (a int, b int); +create table t2 (a int, b int); +insert into t1 values (1,1),(1,2),(1,3),(2,4),(2,5); +insert into t2 values (1,3),(2,1); +select distinct a,b, (select max(b) from t2 where t1.b=t2.a) from t1 order by t1.b; +drop table t1, t2; diff --git a/sql/sql_class.h b/sql/sql_class.h index 312d9de9794..6d77b75d70f 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -1305,7 +1305,7 @@ public: if (copy_field) /* Fix for Intel compiler */ { delete [] copy_field; - copy_field=0; + save_copy_field= copy_field= 0; } } }; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 9162cd30d63..06731d26073 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -936,7 +936,7 @@ JOIN::optimize() } } - if (select_lex->master_unit()->uncacheable) + if (select_lex->uncacheable) { if (!(tmp_join= (JOIN*)thd->alloc(sizeof(JOIN)))) DBUG_RETURN(-1); @@ -3833,7 +3833,8 @@ JOIN::join_free(bool full) JOIN_TAB *tab,*end; DBUG_ENTER("JOIN::join_free"); - full= full || !select_lex->uncacheable; + full= full || (!select_lex->uncacheable && + !thd->lex->describe); if (table) { @@ -3862,6 +3863,7 @@ JOIN::join_free(bool full) for (tab= join_tab, end= tab+tables; tab != end; tab++) tab->cleanup(); table= 0; + tables= 0; } else { From 70ed3160d97d66da74ab031dde64217d501abd6e Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 16 Nov 2004 22:58:02 +0200 Subject: [PATCH 3/3] backport Serg's fix of FT interface (BUG#6523) mysql-test/r/subselect.result: subqueries with full text search mysql-test/t/subselect.test: subqueries with full text search sql/ha_myisam.h: backport Serg's fix of FT interface sql/handler.h: backport Serg's fix of FT interface sql/opt_range.h: backport Serg's fix of FT interface sql/sql_select.cc: comment for previous patch --- mysql-test/r/subselect.result | 8 ++++++++ mysql-test/t/subselect.test | 10 ++++++++++ sql/ha_myisam.h | 1 - sql/handler.h | 1 + sql/opt_range.h | 2 +- sql/sql_select.cc | 2 +- 6 files changed, 21 insertions(+), 3 deletions(-) diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index 2d686285050..f3c4be847ea 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -2003,3 +2003,11 @@ a b (select max(b) from t2 where t1.b=t2.a) 2 4 NULL 2 5 NULL drop table t1, t2; +create table t1 (id int); +create table t2 (id int, body text, fulltext (body)); +insert into t1 values(1),(2),(3); +insert into t2 values (1,'test'), (2,'mysql'), (3,'test'), (4,'test'); +select count(distinct id) from t1 where id in (select id from t2 where match(body) against ('mysql' in boolean mode)); +count(distinct id) +1 +drop table t2,t1; diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test index 976ce7bf6b0..18f7d96b236 100644 --- a/mysql-test/t/subselect.test +++ b/mysql-test/t/subselect.test @@ -1299,3 +1299,13 @@ insert into t1 values (1,1),(1,2),(1,3),(2,4),(2,5); insert into t2 values (1,3),(2,1); select distinct a,b, (select max(b) from t2 where t1.b=t2.a) from t1 order by t1.b; drop table t1, t2; + +# +# subqueries with full text search +# +create table t1 (id int); +create table t2 (id int, body text, fulltext (body)); +insert into t1 values(1),(2),(3); +insert into t2 values (1,'test'), (2,'mysql'), (3,'test'), (4,'test'); +select count(distinct id) from t1 where id in (select id from t2 where match(body) against ('mysql' in boolean mode)); +drop table t2,t1; diff --git a/sql/ha_myisam.h b/sql/ha_myisam.h index 6fde84d6f6f..972d6b18e19 100644 --- a/sql/ha_myisam.h +++ b/sql/ha_myisam.h @@ -81,7 +81,6 @@ class ha_myisam: public handler int index_first(byte * buf); int index_last(byte * buf); int index_next_same(byte *buf, const byte *key, uint keylen); - int index_end() { ft_handler=NULL; return 0; } int ft_init() { if (!ft_handler) diff --git a/sql/handler.h b/sql/handler.h index 252861e5c37..245defe61e0 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -372,6 +372,7 @@ public: virtual int read_range_next(); int compare_key(key_range *range); virtual int ft_init() { return HA_ERR_WRONG_COMMAND; } + void ft_end() { ft_handler=NULL; } virtual FT_INFO *ft_init_ext(uint flags,uint inx,const byte *key, uint keylen) { return NULL; } diff --git a/sql/opt_range.h b/sql/opt_range.h index 9b2e9e45bac..5a2044a59f4 100644 --- a/sql/opt_range.h +++ b/sql/opt_range.h @@ -154,7 +154,7 @@ class FT_SELECT: public QUICK_SELECT { public: FT_SELECT(THD *thd, TABLE *table, uint key): QUICK_SELECT (thd, table, key, 1) { init(); } - + ~FT_SELECT() { file->ft_end(); } int init() { return error= file->ft_init(); } int get_next() { return error= file->ft_read(record); } }; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 06731d26073..5809bd2b7be 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -3834,7 +3834,7 @@ JOIN::join_free(bool full) DBUG_ENTER("JOIN::join_free"); full= full || (!select_lex->uncacheable && - !thd->lex->describe); + !thd->lex->describe); // do not cleanup too early on EXPLAIN if (table) {