From 3ee16518618ee73cc0d4e0b2e47124dc83adfe5d Mon Sep 17 00:00:00 2001 From: "mhansson@dl145s.mysql.com" <> Date: Thu, 31 May 2007 14:22:21 +0200 Subject: [PATCH 1/4] bug#27741: udf test fails on AIX < 5.3 problem #1: udf_example.so does not get built on AIX solution#1: build it yourself using cd sql; gcc -g -I ../include/ -I /usr/include/ -lpthread \ -shared -o udf_example.so udf_example.c; mv udf_example.so \ .libs/ problem#2 (the bug): udf_example fails because it does not recognize the variable LD_LIBRARY_PATH when doing dl_open(), it looks at LIBPATH solution#2: add the library path to LIBPATH problem#3: udf_example returns the wrong result length since it relies on strmov to return a pointer to the end of the string that it copies. On AIX builds, where m_string.h is not included (m_string defines a macro expanding strmov to stpcpy), there is a macro expanding strmov to strcpy, which returns a pointer to the first character. solution#3: define strmov as stpcpy. problem#4: #2 applies on hp-ux as well, but this platform looks at SHLIB_PATH solution#4: added the library path to SHLIB_PATH --- mysql-test/mysql-test-run.pl | 11 +++++++++++ sql/udf_example.c | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index c494626bbae..85191a0be00 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -1784,6 +1784,17 @@ sub environment_setup () { split(':', $ENV{'DYLD_LIBRARY_PATH'}) : ()); mtr_debug("DYLD_LIBRARY_PATH: $ENV{'DYLD_LIBRARY_PATH'}"); + # The environment variable used for shared libs on AIX + $ENV{'SHLIB_PATH'}= join(":", @ld_library_paths, + $ENV{'SHLIB_PATH'} ? + split(':', $ENV{'SHLIB_PATH'}) : ()); + mtr_debug("SHLIB_PATH: $ENV{'SHLIB_PATH'}"); + + # The environment variable used for shared libs on hp-ux + $ENV{'LIBPATH'}= join(":", @ld_library_paths, + $ENV{'LIBPATH'} ? + split(':', $ENV{'LIBPATH'}) : ()); + mtr_debug("LIBPATH: $ENV{'LIBPATH'}"); # -------------------------------------------------------------------------- # Also command lines in .opt files may contain env vars diff --git a/sql/udf_example.c b/sql/udf_example.c index 2bb4fe92d2f..0f28c2a14b0 100644 --- a/sql/udf_example.c +++ b/sql/udf_example.c @@ -130,7 +130,8 @@ typedef long long longlong; #include /* To get strmov() */ #else /* when compiled as standalone */ -#define strmov(a,b) strcpy(a,b) +#include +#define strmov(a,b) stpcpy(a,b) #define bzero(a,b) memset(a,0,b) #define memcpy_fixed(a,b,c) memcpy(a,b,c) #endif From 5a5410e40e53721d8e1ba259f1bf9bd802ff5bcf Mon Sep 17 00:00:00 2001 From: "igor@olga.mysql.com" <> Date: Fri, 1 Jun 2007 17:58:46 -0700 Subject: [PATCH 2/4] Post-merge fix. --- sql/sql_view.cc | 109 ++++-------------------------------------------- 1 file changed, 7 insertions(+), 102 deletions(-) diff --git a/sql/sql_view.cc b/sql/sql_view.cc index 3c15f9c6494..40f54799295 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -709,10 +709,11 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view, view->query.str= str.c_ptr_safe(); view->query.length= str.length(); view->source.str= thd->query + thd->lex->create_view_select_start; - view->source.length= skip_rear_comments((char *)view->source.str, - (char *)thd->query + - thd->query_length) - - view->source.str; + view->source.length= (char *)skip_rear_comments(thd->charset(), + (char *)view->source.str, + (char *)thd->query + + thd->query_length) - + view->source.str; view->file_version= 1; view->calc_md5(md5); view->md5.str= md5; @@ -815,7 +816,7 @@ loop_out: } } else - { + { if (mode == VIEW_ALTER) { my_error(ER_NO_SUCH_TABLE, MYF(0), view->db, view->alias); @@ -824,103 +825,7 @@ loop_out: } } } - /* fill structure */ - view->query.str= (char*)str.ptr(); - view->query.length= str.length()-1; // we do not need last \0 - view->source.str= thd->query + thd->lex->create_view_select_start; - view->source.length= (char *)skip_rear_comments((char *)view->source.str, - (char *)thd->query + - thd->query_length) - - view->source.str; - view->file_version= 1; - view->calc_md5(md5); - view->md5.str= md5; - view->md5.length= 32; - can_be_merged= lex->can_be_merged(); - if (lex->create_view_algorithm == VIEW_ALGORITHM_MERGE && - !lex->can_be_merged()) - { - push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_VIEW_MERGE, - ER(ER_WARN_VIEW_MERGE)); - lex->create_view_algorithm= VIEW_ALGORITHM_UNDEFINED; - } - view->algorithm= lex->create_view_algorithm; - view->definer.user= lex->definer->user; - view->definer.host= lex->definer->host; - view->view_suid= lex->create_view_suid; - view->with_check= lex->create_view_check; - if ((view->updatable_view= (can_be_merged && - view->algorithm != VIEW_ALGORITHM_TMPTABLE))) - { - /* TODO: change here when we will support UNIONs */ - for (TABLE_LIST *tbl= (TABLE_LIST *)lex->select_lex.table_list.first; - tbl; - tbl= tbl->next_local) - { - if ((tbl->view && !tbl->updatable_view) || tbl->schema_table) - { - view->updatable_view= 0; - break; - } - for (TABLE_LIST *up= tbl; up; up= up->embedding) - { - if (up->outer_join) - { - view->updatable_view= 0; - goto loop_out; - } - } - } - } - /* fill structure */ - view->query.str= (char*)str.ptr(); - view->query.length= str.length()-1; // we do not need last \0 - view->source.str= thd->query + thd->lex->create_view_select_start; - view->source.length= (char *)skip_rear_comments(thd->charset(), - (char *)view->source.str, - (char *)thd->query + - thd->query_length) - - view->source.str; - view->file_version= 1; - view->calc_md5(md5); - view->md5.str= md5; - view->md5.length= 32; - can_be_merged= lex->can_be_merged(); - if (lex->create_view_algorithm == VIEW_ALGORITHM_MERGE && - !lex->can_be_merged()) - { - push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_VIEW_MERGE, - ER(ER_WARN_VIEW_MERGE)); - lex->create_view_algorithm= VIEW_ALGORITHM_UNDEFINED; - } - view->algorithm= lex->create_view_algorithm; - view->definer.user= lex->definer->user; - view->definer.host= lex->definer->host; - view->view_suid= lex->create_view_suid; - view->with_check= lex->create_view_check; - if ((view->updatable_view= (can_be_merged && - view->algorithm != VIEW_ALGORITHM_TMPTABLE))) - { - /* TODO: change here when we will support UNIONs */ - for (TABLE_LIST *tbl= (TABLE_LIST *)lex->select_lex.table_list.first; - tbl; - tbl= tbl->next_local) - { - if ((tbl->view && !tbl->updatable_view) || tbl->schema_table) - { - view->updatable_view= 0; - break; - } - for (TABLE_LIST *up= tbl; up; up= up->embedding) - { - if (up->outer_join) - { - view->updatable_view= 0; - goto loop_out; - } - } - } - } + /* Check that table of main select do not used in subqueries. From 5cbebf0a188564be7578824408c481636b73bbf3 Mon Sep 17 00:00:00 2001 From: "igor@olga.mysql.com" <> Date: Sat, 2 Jun 2007 11:44:16 -0700 Subject: [PATCH 3/4] Fixed bug #28728: a crash when executing EXPLAIN EXTENDED for a query using a derived table over a grouping subselect. This crash happens only when materialization of the derived tables requires creation of auxiliary temporary table, for example when a grouping operation is carried out with usage of a temporary table. The crash happened because EXPLAIN EXTENDED when printing the query expression made an attempt to use the objects created in the mem_root of the temporary table which has been already freed by the moment when printing is called. This bug appeared after the method Item_field::print() had been introduced. --- mysql-test/r/subselect.result | 10 ++++++++++ mysql-test/t/subselect.test | 14 ++++++++++++++ sql/sql_select.cc | 11 +++++++++++ 3 files changed, 35 insertions(+) diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index 92a4a6f3f5a..ba487cb859d 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -4071,4 +4071,14 @@ id st 2 GA 4 FL DROP TABLE t1,t2; +CREATE TABLE t1 (a int); +INSERT INTO t1 VALUES (1), (2); +EXPLAIN EXTENDED +SELECT * FROM (SELECT count(*) FROM t1 GROUP BY a) as res; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY ALL NULL NULL NULL NULL 2 +2 DERIVED t1 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort +Warnings: +Note 1003 select `res`.`count(*)` AS `count(*)` from (select count(0) AS `count(*)` from `test`.`t1` group by `test`.`t1`.`a`) `res` +DROP TABLE t1; End of 5.0 tests. diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test index 5840e434b64..d565070835e 100644 --- a/mysql-test/t/subselect.test +++ b/mysql-test/t/subselect.test @@ -2906,4 +2906,18 @@ SELECT id, st FROM t1 DROP TABLE t1,t2; +# +# Bug #28728: crash with EXPLAIN EXTENDED for a query with a derived table +# over a grouping subselect +# + +CREATE TABLE t1 (a int); + +INSERT INTO t1 VALUES (1), (2); + +EXPLAIN EXTENDED +SELECT * FROM (SELECT count(*) FROM t1 GROUP BY a) as res; + +DROP TABLE t1; + --echo End of 5.0 tests. diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 78d213a45c4..41688794721 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -2075,6 +2075,17 @@ JOIN::exec() thd->examined_row_count+= curr_join->examined_rows; DBUG_PRINT("counts", ("thd->examined_row_count: %lu", (ulong) thd->examined_row_count)); + + /* + With EXPLAIN EXTENDED we have to restore original ref_array + for a derived table which is always materialized. + Otherwise we would not be able to print the query correctly. + */ + if (items0 && + (thd->lex->describe & DESCRIBE_EXTENDED) && + select_lex->linkage == DERIVED_TABLE_TYPE) + set_items_ref_array(items0); + DBUG_VOID_RETURN; } From 9a1d8adc9d25018664cf8fefdde2bde6d85a7814 Mon Sep 17 00:00:00 2001 From: "gkodinov/kgeorge@macbook.gmz" <> Date: Sun, 3 Jun 2007 09:40:00 +0300 Subject: [PATCH 4/4] Bug #26162: Trigger DML ignores low_priority_updates setting The value of "low-priority-updates" option and the LOW PRIORITY prefix was taken into account at parse time. This caused triggers (among others) to ignore this flag (if supplied for the DML statement). Moved reading of the LOW_PRIORITY flag at run time. Fixed an incosistency when handling SET GLOBAL LOW_PRIORITY_UPDATES : now it is in effect for delayed INSERTs. Tested by checking the effect of LOW_PRIORITY flag via a trigger. --- include/thr_lock.h | 5 ++++ mysql-test/r/trigger.result | 24 ++++++++++++++++ mysql-test/t/trigger.test | 55 +++++++++++++++++++++++++++++++++++++ sql/set_var.cc | 6 +++- sql/sql_base.cc | 7 +++++ sql/sql_yacc.yy | 12 ++++---- 6 files changed, 102 insertions(+), 7 deletions(-) diff --git a/include/thr_lock.h b/include/thr_lock.h index 966522fe3e3..aa5eb7426ae 100644 --- a/include/thr_lock.h +++ b/include/thr_lock.h @@ -54,6 +54,11 @@ enum thr_lock_type { TL_IGNORE=-1, TL_WRITE_CONCURRENT_INSERT, /* Write used by INSERT DELAYED. Allows READ locks */ TL_WRITE_DELAYED, + /* + parser only! Late bound low_priority flag. + At open_tables() becomes thd->update_lock_default. + */ + TL_WRITE_DEFAULT, /* WRITE lock that has lower priority than TL_READ */ TL_WRITE_LOW_PRIORITY, /* Normal WRITE lock */ diff --git a/mysql-test/r/trigger.result b/mysql-test/r/trigger.result index 3e6a901dc00..e95485eb80a 100644 --- a/mysql-test/r/trigger.result +++ b/mysql-test/r/trigger.result @@ -1449,4 +1449,28 @@ isave 1 2 drop table t1, t2, t3; +CREATE TABLE t1 (id INTEGER); +CREATE TABLE t2 (id INTEGER); +INSERT INTO t2 VALUES (1),(2); +CREATE TRIGGER t1_test AFTER INSERT ON t1 FOR EACH ROW +INSERT INTO t2 VALUES (new.id); +SELECT GET_LOCK('B26162',20); +GET_LOCK('B26162',20) +1 +SELECT 'rl_acquirer', GET_LOCK('B26162',5), id FROM t2 WHERE id = 1; +SET SESSION LOW_PRIORITY_UPDATES=1; +SET GLOBAL LOW_PRIORITY_UPDATES=1; +INSERT INTO t1 VALUES (5); +SELECT 'rl_contender', id FROM t2 WHERE id > 1; +SELECT RELEASE_LOCK('B26162'); +RELEASE_LOCK('B26162') +0 +rl_acquirer GET_LOCK('B26162',5) id +rl_acquirer 0 1 +rl_contender id +rl_contender 2 +DROP TRIGGER t1_test; +DROP TABLE t1,t2; +SET SESSION LOW_PRIORITY_UPDATES=DEFAULT; +SET GLOBAL LOW_PRIORITY_UPDATES=DEFAULT; End of 5.0 tests diff --git a/mysql-test/t/trigger.test b/mysql-test/t/trigger.test index 82de4dac111..24817de66be 100644 --- a/mysql-test/t/trigger.test +++ b/mysql-test/t/trigger.test @@ -1763,4 +1763,59 @@ select * from t1; select * from t3; drop table t1, t2, t3; +# +# Bug #26162: Trigger DML ignores low_priority_updates setting +# +CREATE TABLE t1 (id INTEGER); +CREATE TABLE t2 (id INTEGER); + +INSERT INTO t2 VALUES (1),(2); + +# trigger that produces the high priority insert, but should be low, adding +# LOW_PRIORITY fixes this +CREATE TRIGGER t1_test AFTER INSERT ON t1 FOR EACH ROW + INSERT INTO t2 VALUES (new.id); + +CONNECT (rl_acquirer, localhost, root,,); +CONNECT (wl_acquirer, localhost, root,,); +CONNECT (rl_contender, localhost, root,,); + +SELECT GET_LOCK('B26162',20); + +CONNECTION rl_acquirer; +--send +SELECT 'rl_acquirer', GET_LOCK('B26162',5), id FROM t2 WHERE id = 1; + +CONNECTION wl_acquirer; +SET SESSION LOW_PRIORITY_UPDATES=1; +SET GLOBAL LOW_PRIORITY_UPDATES=1; +--send +INSERT INTO t1 VALUES (5); + +CONNECTION rl_contender; +# must not "see" the row inserted by the INSERT (as it must run before the +# INSERT) +--send +SELECT 'rl_contender', id FROM t2 WHERE id > 1; + +CONNECTION default; +SELECT RELEASE_LOCK('B26162'); + +CONNECTION wl_acquirer; +--reap +CONNECTION rl_acquirer; +--reap +CONNECTION rl_contender; +--reap + +CONNECTION default; +DISCONNECT rl_acquirer; +DISCONNECT wl_acquirer; +DISCONNECT rl_contender; + +DROP TRIGGER t1_test; +DROP TABLE t1,t2; +SET SESSION LOW_PRIORITY_UPDATES=DEFAULT; +SET GLOBAL LOW_PRIORITY_UPDATES=DEFAULT; + --echo End of 5.0 tests diff --git a/sql/set_var.cc b/sql/set_var.cc index 8808327ce0a..daebd924a89 100644 --- a/sql/set_var.cc +++ b/sql/set_var.cc @@ -1226,7 +1226,11 @@ static void sys_default_ftb_syntax(THD *thd, enum_var_type type) static void fix_low_priority_updates(THD *thd, enum_var_type type) { - if (type != OPT_GLOBAL) + if (type == OPT_GLOBAL) + thr_upgraded_concurrent_insert_lock= + (global_system_variables.low_priority_updates ? + TL_WRITE_LOW_PRIORITY : TL_WRITE); + else thd->update_lock_default= (thd->variables.low_priority_updates ? TL_WRITE_LOW_PRIORITY : TL_WRITE); } diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 999a05ca616..b2f21749d64 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -1505,6 +1505,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root, HASH_SEARCH_STATE state; DBUG_ENTER("open_table"); + DBUG_ASSERT (table_list->lock_type != TL_WRITE_DEFAULT); /* find a unused table in the open table cache */ if (refresh) *refresh=0; @@ -2667,6 +2668,12 @@ int open_tables(THD *thd, TABLE_LIST **start, uint *counter, uint flags) for (tables= *start; tables ;tables= tables->next_global) { safe_to_ignore_table= FALSE; // 'FALSE', as per coding style + + if (tables->lock_type == TL_WRITE_DEFAULT) + { + tables->lock_type= thd->update_lock_default; + DBUG_ASSERT (tables->lock_type >= TL_WRITE_ALLOW_WRITE); + } /* Ignore placeholders for derived tables. After derived tables processing, link to created temporary table will be put here. diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index c1da870960b..38679c81e75 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -6561,7 +6561,7 @@ insert_lock_option: insert visible only after the table unlocking but everyone can read table. */ - $$= (Lex->sphead ? TL_WRITE :TL_WRITE_CONCURRENT_INSERT); + $$= (Lex->sphead ? TL_WRITE_DEFAULT : TL_WRITE_CONCURRENT_INSERT); #else $$= TL_WRITE_CONCURRENT_INSERT; #endif @@ -6739,7 +6739,7 @@ insert_update_elem: }; opt_low_priority: - /* empty */ { $$= YYTHD->update_lock_default; } + /* empty */ { $$= TL_WRITE_DEFAULT; } | LOW_PRIORITY { $$= TL_WRITE_LOW_PRIORITY; }; /* Delete rows from a table */ @@ -6750,7 +6750,7 @@ delete: LEX *lex= Lex; lex->sql_command= SQLCOM_DELETE; mysql_init_select(lex); - lex->lock_option= lex->thd->update_lock_default; + lex->lock_option= TL_WRITE_DEFAULT; lex->ignore= 0; lex->select_lex.init_order(); } @@ -7415,7 +7415,7 @@ opt_local: | LOCAL_SYM { $$=1;}; load_data_lock: - /* empty */ { $$= YYTHD->update_lock_default; } + /* empty */ { $$= TL_WRITE_DEFAULT; } | CONCURRENT { #ifdef HAVE_QUERY_CACHE @@ -7423,7 +7423,7 @@ load_data_lock: Ignore this option in SP to avoid problem with query cache */ if (Lex->sphead != 0) - $$= YYTHD->update_lock_default; + $$= TL_WRITE_DEFAULT; else #endif $$= TL_WRITE_CONCURRENT_INSERT; @@ -8736,7 +8736,7 @@ table_lock: lock_option: READ_SYM { $$=TL_READ_NO_INSERT; } - | WRITE_SYM { $$=YYTHD->update_lock_default; } + | WRITE_SYM { $$=TL_WRITE_DEFAULT; } | LOW_PRIORITY WRITE_SYM { $$=TL_WRITE_LOW_PRIORITY; } | READ_SYM LOCAL_SYM { $$= TL_READ; } ;