summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <gkodinov/kgeorge@macbook.gmz>2007-06-03 09:40:00 +0300
committerunknown <gkodinov/kgeorge@macbook.gmz>2007-06-03 09:40:00 +0300
commitf9a41f9f35b2ac1fd00e3a2d227ed5b96391bf1c (patch)
treee4b5b1d164e55e3fadeccad259b36d93b0cff970
parentd7a90fa1724a047d8b9cf81e974c39a9ae64ff84 (diff)
downloadmariadb-git-f9a41f9f35b2ac1fd00e3a2d227ed5b96391bf1c.tar.gz
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: Bug #26162: moved reading of the LOW PRIORITY flag at run time mysql-test/r/trigger.result: Bug #26162: test case mysql-test/t/trigger.test: Bug #26162: test case sql/set_var.cc: Bug #26162: fixed the handling of the "low-priority-updates" option sql/sql_base.cc: Bug #26162: moved reading of the LOW PRIORITY flag at run time sql/sql_yacc.yy: Bug #26162: moved reading of the LOW PRIORITY flag at run time
-rw-r--r--include/thr_lock.h5
-rw-r--r--mysql-test/r/trigger.result24
-rw-r--r--mysql-test/t/trigger.test55
-rw-r--r--sql/set_var.cc6
-rw-r--r--sql/sql_base.cc7
-rw-r--r--sql/sql_yacc.yy12
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; }
;