Skip to content

Commit 3115f77

Browse files
author
Sreeharsha Ramanavarapu
committed
1 parent 23bc295 commit 3115f77

File tree

5 files changed

+60
-49
lines changed

5 files changed

+60
-49
lines changed

mysql-test/r/partition_locking.result

+18-18
Original file line numberDiff line numberDiff line change
@@ -5612,7 +5612,7 @@ HANDLER_WRITE 17
56125612
UNLOCK TABLES;
56135613
EXPLAIN PARTITIONS SELECT * FROM t2 WHERE a = sf_a_from_t1b_d('1') AND a = 2;
56145614
id select_type table partitions type possible_keys key key_len ref rows Extra
5615-
1 SIMPLE t2 p2 const PRIMARY PRIMARY 4 const # NULL
5615+
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL # Impossible WHERE
56165616
FLUSH STATUS;
56175617
START TRANSACTION;
56185618
SELECT * FROM t2 WHERE a = sf_a_from_t1b_d('1') AND a = 2;
@@ -5622,7 +5622,7 @@ WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
56225622
VARIABLE_NAME VARIABLE_VALUE
56235623
HANDLER_COMMIT 1
56245624
HANDLER_EXTERNAL_LOCK 12
5625-
HANDLER_READ_KEY 4
5625+
HANDLER_READ_KEY 3
56265626
HANDLER_READ_NEXT 1
56275627
HANDLER_WRITE 17
56285628
FLUSH STATUS;
@@ -5635,7 +5635,7 @@ WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
56355635
VARIABLE_NAME VARIABLE_VALUE
56365636
HANDLER_COMMIT 2
56375637
HANDLER_EXTERNAL_LOCK 8
5638-
HANDLER_READ_KEY 4
5638+
HANDLER_READ_KEY 3
56395639
HANDLER_READ_NEXT 1
56405640
HANDLER_WRITE 17
56415641
UNLOCK TABLES;
@@ -5945,7 +5945,7 @@ HANDLER_WRITE 17
59455945
UNLOCK TABLES;
59465946
EXPLAIN PARTITIONS SELECT sf_add_1(a) - 1, sf_add_hello(b) FROM t2 WHERE a = sf_a_from_t1b_d('1') AND a = 2;
59475947
id select_type table partitions type possible_keys key key_len ref rows Extra
5948-
1 SIMPLE t2 p2 const PRIMARY PRIMARY 4 const # NULL
5948+
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL # Impossible WHERE
59495949
FLUSH STATUS;
59505950
START TRANSACTION;
59515951
SELECT sf_add_1(a) - 1, sf_add_hello(b) FROM t2 WHERE a = sf_a_from_t1b_d('1') AND a = 2;
@@ -5955,7 +5955,7 @@ WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
59555955
VARIABLE_NAME VARIABLE_VALUE
59565956
HANDLER_COMMIT 1
59575957
HANDLER_EXTERNAL_LOCK 12
5958-
HANDLER_READ_KEY 4
5958+
HANDLER_READ_KEY 3
59595959
HANDLER_READ_NEXT 1
59605960
HANDLER_WRITE 17
59615961
FLUSH STATUS;
@@ -5968,7 +5968,7 @@ WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
59685968
VARIABLE_NAME VARIABLE_VALUE
59695969
HANDLER_COMMIT 2
59705970
HANDLER_EXTERNAL_LOCK 8
5971-
HANDLER_READ_KEY 4
5971+
HANDLER_READ_KEY 3
59725972
HANDLER_READ_NEXT 1
59735973
HANDLER_WRITE 17
59745974
UNLOCK TABLES;
@@ -6352,7 +6352,7 @@ ROLLBACK;
63526352
UNLOCK TABLES;
63536353
EXPLAIN PARTITIONS UPDATE t2 SET b = CONCAT('+', b) WHERE a = sf_a_from_t1b_d('1') AND a = 2;
63546354
id select_type table partitions type possible_keys key key_len ref rows Extra
6355-
1 SIMPLE t2 p2 range PRIMARY PRIMARY 4 const # Using where
6355+
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL # Impossible WHERE
63566356
FLUSH STATUS;
63576357
START TRANSACTION;
63586358
UPDATE t2 SET b = CONCAT('+', b) WHERE a = sf_a_from_t1b_d('1') AND a = 2;
@@ -6361,7 +6361,7 @@ WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
63616361
VARIABLE_NAME VARIABLE_VALUE
63626362
HANDLER_COMMIT 1
63636363
HANDLER_EXTERNAL_LOCK 12
6364-
HANDLER_READ_KEY 4
6364+
HANDLER_READ_KEY 3
63656365
HANDLER_READ_NEXT 1
63666366
HANDLER_WRITE 17
63676367
SELECT * FROM t2;
@@ -6379,7 +6379,7 @@ WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
63796379
VARIABLE_NAME VARIABLE_VALUE
63806380
HANDLER_COMMIT 2
63816381
HANDLER_EXTERNAL_LOCK 8
6382-
HANDLER_READ_KEY 4
6382+
HANDLER_READ_KEY 3
63836383
HANDLER_READ_NEXT 1
63846384
HANDLER_WRITE 17
63856385
SELECT * FROM t2;
@@ -6790,7 +6790,7 @@ ROLLBACK;
67906790
UNLOCK TABLES;
67916791
EXPLAIN PARTITIONS UPDATE t2 SET b = sf_add_hello(b) WHERE a = sf_a_from_t1b_d('1') AND a = 2;
67926792
id select_type table partitions type possible_keys key key_len ref rows Extra
6793-
1 SIMPLE t2 p2 range PRIMARY PRIMARY 4 const # Using where
6793+
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL # Impossible WHERE
67946794
FLUSH STATUS;
67956795
START TRANSACTION;
67966796
UPDATE t2 SET b = sf_add_hello(b) WHERE a = sf_a_from_t1b_d('1') AND a = 2;
@@ -6799,7 +6799,7 @@ WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
67996799
VARIABLE_NAME VARIABLE_VALUE
68006800
HANDLER_COMMIT 1
68016801
HANDLER_EXTERNAL_LOCK 12
6802-
HANDLER_READ_KEY 4
6802+
HANDLER_READ_KEY 3
68036803
HANDLER_READ_NEXT 1
68046804
HANDLER_WRITE 17
68056805
SELECT * FROM t2;
@@ -6817,7 +6817,7 @@ WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
68176817
VARIABLE_NAME VARIABLE_VALUE
68186818
HANDLER_COMMIT 2
68196819
HANDLER_EXTERNAL_LOCK 8
6820-
HANDLER_READ_KEY 4
6820+
HANDLER_READ_KEY 3
68216821
HANDLER_READ_NEXT 1
68226822
HANDLER_WRITE 17
68236823
SELECT * FROM t2;
@@ -7236,7 +7236,7 @@ ROLLBACK;
72367236
UNLOCK TABLES;
72377237
EXPLAIN PARTITIONS UPDATE t2 SET a = sf_add_1(a) + 4 WHERE a = sf_a_from_t1b_d('1') AND a = 2;
72387238
id select_type table partitions type possible_keys key key_len ref rows Extra
7239-
1 SIMPLE t2 p2 range PRIMARY PRIMARY 4 const # Using where; Using temporary
7239+
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL # Impossible WHERE
72407240
FLUSH STATUS;
72417241
START TRANSACTION;
72427242
UPDATE t2 SET a = sf_add_1(a) + 4 WHERE a = sf_a_from_t1b_d('1') AND a = 2;
@@ -7245,7 +7245,7 @@ WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
72457245
VARIABLE_NAME VARIABLE_VALUE
72467246
HANDLER_COMMIT 1
72477247
HANDLER_EXTERNAL_LOCK 16
7248-
HANDLER_READ_KEY 4
7248+
HANDLER_READ_KEY 3
72497249
HANDLER_READ_NEXT 1
72507250
HANDLER_WRITE 17
72517251
SELECT * FROM t2;
@@ -7263,7 +7263,7 @@ WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
72637263
VARIABLE_NAME VARIABLE_VALUE
72647264
HANDLER_COMMIT 2
72657265
HANDLER_EXTERNAL_LOCK 8
7266-
HANDLER_READ_KEY 4
7266+
HANDLER_READ_KEY 3
72677267
HANDLER_READ_NEXT 1
72687268
HANDLER_WRITE 17
72697269
SELECT * FROM t2;
@@ -7665,7 +7665,7 @@ ROLLBACK;
76657665
UNLOCK TABLES;
76667666
EXPLAIN PARTITIONS DELETE FROM t2 WHERE a = sf_a_from_t1b_d('1') AND a = 2;
76677667
id select_type table partitions type possible_keys key key_len ref rows Extra
7668-
1 SIMPLE t2 p2 range PRIMARY PRIMARY 4 const # Using where
7668+
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL # Impossible WHERE
76697669
FLUSH STATUS;
76707670
START TRANSACTION;
76717671
DELETE FROM t2 WHERE a = sf_a_from_t1b_d('1') AND a = 2;
@@ -7674,7 +7674,7 @@ WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
76747674
VARIABLE_NAME VARIABLE_VALUE
76757675
HANDLER_COMMIT 1
76767676
HANDLER_EXTERNAL_LOCK 12
7677-
HANDLER_READ_KEY 4
7677+
HANDLER_READ_KEY 3
76787678
HANDLER_READ_NEXT 1
76797679
HANDLER_WRITE 17
76807680
SELECT * FROM t2;
@@ -7692,7 +7692,7 @@ WHERE VARIABLE_NAME LIKE 'HANDLER_%' AND VARIABLE_VALUE > 0;
76927692
VARIABLE_NAME VARIABLE_VALUE
76937693
HANDLER_COMMIT 2
76947694
HANDLER_EXTERNAL_LOCK 8
7695-
HANDLER_READ_KEY 4
7695+
HANDLER_READ_KEY 3
76967696
HANDLER_READ_NEXT 1
76977697
HANDLER_WRITE 17
76987698
SELECT * FROM t2;

mysql-test/suite/opt_trace/r/general_no_prot_all.result

+13-13
Original file line numberDiff line numberDiff line change
@@ -7894,15 +7894,15 @@ select * from t6 where d in (select f1() from t2 where s="c") {
78947894
"steps": [
78957895
{
78967896
"transformation": "equality_propagation",
7897-
"resulting_condition": "(1 and multiple equal('c', `t2`.`s`) and multiple equal(`f1`(), `t6`.`d`))"
7897+
"resulting_condition": "(1 and (`t6`.`d` = `f1`()) and multiple equal('c', `t2`.`s`))"
78987898
},
78997899
{
79007900
"transformation": "constant_propagation",
7901-
"resulting_condition": "(1 and multiple equal('c', `t2`.`s`) and multiple equal(`f1`(), `t6`.`d`))"
7901+
"resulting_condition": "(1 and (`t6`.`d` = `f1`()) and multiple equal('c', `t2`.`s`))"
79027902
},
79037903
{
79047904
"transformation": "trivial_condition_removal",
7905-
"resulting_condition": "(multiple equal('c', `t2`.`s`) and multiple equal(`f1`(), `t6`.`d`))"
7905+
"resulting_condition": "((`t6`.`d` = `f1`()) and multiple equal('c', `t2`.`s`))"
79067906
}
79077907
] /* steps */
79087908
} /* condition_processing */
@@ -8030,7 +8030,7 @@ select * from t6 where d in (select f1() from t2 where s="c") {
80308030
},
80318031
{
80328032
"attaching_conditions_to_tables": {
8033-
"original_condition": "((`t6`.`d` = `f1`()) and (`t2`.`s` = 'c'))",
8033+
"original_condition": "((`t2`.`s` = 'c') and (`t6`.`d` = `f1`()))",
80348034
"attached_conditions_computation": [
80358035
] /* attached_conditions_computation */,
80368036
"attached_conditions_summary": [
@@ -8757,15 +8757,15 @@ select d into res from t6 where d in (select f1() from t2 where s=arg) {
87578757
"steps": [
87588758
{
87598759
"transformation": "equality_propagation",
8760-
"resulting_condition": "(1 and multiple equal(arg@0, `t2`.`s`) and multiple equal(`f1`(), `t6`.`d`))"
8760+
"resulting_condition": "(1 and (`t6`.`d` = `f1`()) and multiple equal(arg@0, `t2`.`s`))"
87618761
},
87628762
{
87638763
"transformation": "constant_propagation",
8764-
"resulting_condition": "(1 and multiple equal(arg@0, `t2`.`s`) and multiple equal(`f1`(), `t6`.`d`))"
8764+
"resulting_condition": "(1 and (`t6`.`d` = `f1`()) and multiple equal(arg@0, `t2`.`s`))"
87658765
},
87668766
{
87678767
"transformation": "trivial_condition_removal",
8768-
"resulting_condition": "(multiple equal(arg@0, `t2`.`s`) and multiple equal(`f1`(), `t6`.`d`))"
8768+
"resulting_condition": "((`t6`.`d` = `f1`()) and multiple equal(arg@0, `t2`.`s`))"
87698769
}
87708770
] /* steps */
87718771
} /* condition_processing */
@@ -8893,7 +8893,7 @@ select d into res from t6 where d in (select f1() from t2 where s=arg) {
88938893
},
88948894
{
88958895
"attaching_conditions_to_tables": {
8896-
"original_condition": "((`t6`.`d` = `f1`()) and (`t2`.`s` = arg@0))",
8896+
"original_condition": "((`t2`.`s` = arg@0) and (`t6`.`d` = `f1`()))",
88978897
"attached_conditions_computation": [
88988898
] /* attached_conditions_computation */,
88998899
"attached_conditions_summary": [
@@ -10571,15 +10571,15 @@ select d into res from t6 where d in (select f1() from t2 where s=arg) {
1057110571
"steps": [
1057210572
{
1057310573
"transformation": "equality_propagation",
10574-
"resulting_condition": "(1 and multiple equal(arg@0, `t2`.`s`) and multiple equal(`f1`(), `t6`.`d`))"
10574+
"resulting_condition": "(1 and (`t6`.`d` = `f1`()) and multiple equal(arg@0, `t2`.`s`))"
1057510575
},
1057610576
{
1057710577
"transformation": "constant_propagation",
10578-
"resulting_condition": "(1 and multiple equal(arg@0, `t2`.`s`) and multiple equal(`f1`(), `t6`.`d`))"
10578+
"resulting_condition": "(1 and (`t6`.`d` = `f1`()) and multiple equal(arg@0, `t2`.`s`))"
1057910579
},
1058010580
{
1058110581
"transformation": "trivial_condition_removal",
10582-
"resulting_condition": "(multiple equal(arg@0, `t2`.`s`) and multiple equal(`f1`(), `t6`.`d`))"
10582+
"resulting_condition": "((`t6`.`d` = `f1`()) and multiple equal(arg@0, `t2`.`s`))"
1058310583
}
1058410584
] /* steps */
1058510585
} /* condition_processing */
@@ -10781,7 +10781,7 @@ select d into res from t6 where d in (select f1() from t2 where s=arg) {
1078110781
},
1078210782
{
1078310783
"attaching_conditions_to_tables": {
10784-
"original_condition": "((`t6`.`d` = `f1`()) and (`t2`.`s` = arg@0))",
10784+
"original_condition": "((`t2`.`s` = arg@0) and (`t6`.`d` = `<subquery2>`.`f1()`))",
1078510785
"attached_conditions_computation": [
1078610786
] /* attached_conditions_computation */,
1078710787
"attached_conditions_summary": [
@@ -10791,7 +10791,7 @@ select d into res from t6 where d in (select f1() from t2 where s=arg) {
1079110791
},
1079210792
{
1079310793
"table": "``.`<subquery2>`",
10794-
"attached": "(`t6`.`d` = `f1`())"
10794+
"attached": null
1079510795
},
1079610796
{
1079710797
"table": "`t2`",

mysql-test/suite/opt_trace/r/general_ps_prot_all.result

+13-13
Original file line numberDiff line numberDiff line change
@@ -7850,15 +7850,15 @@ select * from t6 where d in (select f1() from t2 where s="c") {
78507850
"steps": [
78517851
{
78527852
"transformation": "equality_propagation",
7853-
"resulting_condition": "(1 and multiple equal('c', `t2`.`s`) and multiple equal(`f1`(), `t6`.`d`))"
7853+
"resulting_condition": "(1 and (`t6`.`d` = `f1`()) and multiple equal('c', `t2`.`s`))"
78547854
},
78557855
{
78567856
"transformation": "constant_propagation",
7857-
"resulting_condition": "(1 and multiple equal('c', `t2`.`s`) and multiple equal(`f1`(), `t6`.`d`))"
7857+
"resulting_condition": "(1 and (`t6`.`d` = `f1`()) and multiple equal('c', `t2`.`s`))"
78587858
},
78597859
{
78607860
"transformation": "trivial_condition_removal",
7861-
"resulting_condition": "(multiple equal('c', `t2`.`s`) and multiple equal(`f1`(), `t6`.`d`))"
7861+
"resulting_condition": "((`t6`.`d` = `f1`()) and multiple equal('c', `t2`.`s`))"
78627862
}
78637863
] /* steps */
78647864
} /* condition_processing */
@@ -7986,7 +7986,7 @@ select * from t6 where d in (select f1() from t2 where s="c") {
79867986
},
79877987
{
79887988
"attaching_conditions_to_tables": {
7989-
"original_condition": "((`t6`.`d` = `f1`()) and (`t2`.`s` = 'c'))",
7989+
"original_condition": "((`t2`.`s` = 'c') and (`t6`.`d` = `f1`()))",
79907990
"attached_conditions_computation": [
79917991
] /* attached_conditions_computation */,
79927992
"attached_conditions_summary": [
@@ -8684,15 +8684,15 @@ select d into res from t6 where d in (select f1() from t2 where s=arg) {
86848684
"steps": [
86858685
{
86868686
"transformation": "equality_propagation",
8687-
"resulting_condition": "(1 and multiple equal(arg@0, `t2`.`s`) and multiple equal(`f1`(), `t6`.`d`))"
8687+
"resulting_condition": "(1 and (`t6`.`d` = `f1`()) and multiple equal(arg@0, `t2`.`s`))"
86888688
},
86898689
{
86908690
"transformation": "constant_propagation",
8691-
"resulting_condition": "(1 and multiple equal(arg@0, `t2`.`s`) and multiple equal(`f1`(), `t6`.`d`))"
8691+
"resulting_condition": "(1 and (`t6`.`d` = `f1`()) and multiple equal(arg@0, `t2`.`s`))"
86928692
},
86938693
{
86948694
"transformation": "trivial_condition_removal",
8695-
"resulting_condition": "(multiple equal(arg@0, `t2`.`s`) and multiple equal(`f1`(), `t6`.`d`))"
8695+
"resulting_condition": "((`t6`.`d` = `f1`()) and multiple equal(arg@0, `t2`.`s`))"
86968696
}
86978697
] /* steps */
86988698
} /* condition_processing */
@@ -8820,7 +8820,7 @@ select d into res from t6 where d in (select f1() from t2 where s=arg) {
88208820
},
88218821
{
88228822
"attaching_conditions_to_tables": {
8823-
"original_condition": "((`t6`.`d` = `f1`()) and (`t2`.`s` = arg@0))",
8823+
"original_condition": "((`t2`.`s` = arg@0) and (`t6`.`d` = `f1`()))",
88248824
"attached_conditions_computation": [
88258825
] /* attached_conditions_computation */,
88268826
"attached_conditions_summary": [
@@ -10512,15 +10512,15 @@ select d into res from t6 where d in (select f1() from t2 where s=arg) {
1051210512
"steps": [
1051310513
{
1051410514
"transformation": "equality_propagation",
10515-
"resulting_condition": "(1 and multiple equal(arg@0, `t2`.`s`) and multiple equal(`f1`(), `t6`.`d`))"
10515+
"resulting_condition": "(1 and (`t6`.`d` = `f1`()) and multiple equal(arg@0, `t2`.`s`))"
1051610516
},
1051710517
{
1051810518
"transformation": "constant_propagation",
10519-
"resulting_condition": "(1 and multiple equal(arg@0, `t2`.`s`) and multiple equal(`f1`(), `t6`.`d`))"
10519+
"resulting_condition": "(1 and (`t6`.`d` = `f1`()) and multiple equal(arg@0, `t2`.`s`))"
1052010520
},
1052110521
{
1052210522
"transformation": "trivial_condition_removal",
10523-
"resulting_condition": "(multiple equal(arg@0, `t2`.`s`) and multiple equal(`f1`(), `t6`.`d`))"
10523+
"resulting_condition": "((`t6`.`d` = `f1`()) and multiple equal(arg@0, `t2`.`s`))"
1052410524
}
1052510525
] /* steps */
1052610526
} /* condition_processing */
@@ -10722,7 +10722,7 @@ select d into res from t6 where d in (select f1() from t2 where s=arg) {
1072210722
},
1072310723
{
1072410724
"attaching_conditions_to_tables": {
10725-
"original_condition": "((`t6`.`d` = `f1`()) and (`t2`.`s` = arg@0))",
10725+
"original_condition": "((`t2`.`s` = arg@0) and (`t6`.`d` = `<subquery2>`.`f1()`))",
1072610726
"attached_conditions_computation": [
1072710727
] /* attached_conditions_computation */,
1072810728
"attached_conditions_summary": [
@@ -10732,7 +10732,7 @@ select d into res from t6 where d in (select f1() from t2 where s=arg) {
1073210732
},
1073310733
{
1073410734
"table": "``.`<subquery2>`",
10735-
"attached": "(`t6`.`d` = `f1`())"
10735+
"attached": null
1073610736
},
1073710737
{
1073810738
"table": "`t2`",

sql/item_func.cc

-5
Original file line numberDiff line numberDiff line change
@@ -7093,8 +7093,6 @@ Item_func_sp::fix_fields(THD *thd, Item **ref)
70937093

70947094
/* These is reset/set by Item_func::fix_fields. */
70957095
with_stored_program= true;
7096-
if (!m_sp->m_chistics->detistic || !tables_locked_cache)
7097-
const_item_cache= false;
70987096

70997097
if (res)
71007098
DBUG_RETURN(res);
@@ -7132,9 +7130,6 @@ void Item_func_sp::update_used_tables()
71327130
{
71337131
Item_func::update_used_tables();
71347132

7135-
if (!m_sp->m_chistics->detistic)
7136-
const_item_cache= false;
7137-
71387133
/* This is reset by Item_func::update_used_tables(). */
71397134
with_stored_program= true;
71407135
}

sql/item_func.h

+16
Original file line numberDiff line numberDiff line change
@@ -2198,6 +2198,22 @@ class Item_func_sp :public Item_func
21982198
}
21992199

22002200
virtual void update_null_value();
2201+
2202+
/**
2203+
Ensure that deterministic functions are not evaluated in preparation phase
2204+
by returning false before tables are locked and true after they are locked.
2205+
(can_be_evaluated_now() handles this because a function has the
2206+
has_subquery() property).
2207+
2208+
@retval true if tables are locked for deterministic functions
2209+
@retval false Otherwise
2210+
*/
2211+
bool const_item() const
2212+
{
2213+
if (used_tables() == 0)
2214+
return can_be_evaluated_now();
2215+
return false;
2216+
}
22012217
};
22022218

22032219

0 commit comments

Comments
 (0)