@@ -5826,3 +5826,149 @@ SELECT LOAD_FILE('') AS f, a FROM t1 GROUP BY f, a HAVING f = a;
5826
5826
f a
5827
5827
DROP TABLE t1;
5828
5828
End of 10.5 tests
5829
+ #
5830
+ # MDEV-19269 Pushdown into IN subquery is not made on the second
5831
+ # execution of stmt
5832
+ #
5833
+ create table t1 (a int, b int);
5834
+ create table t2 (x int, y int);
5835
+ insert into t1 values (1,1),(2,2);
5836
+ insert into t2 values (1,1),(2,2),(2,3);
5837
+ prepare stmt from "
5838
+ EXPLAIN FORMAT=JSON
5839
+ SELECT * FROM t1
5840
+ WHERE a = b
5841
+ AND (a,b) IN (SELECT t2.x, COUNT(t2.y) FROM t2 WHERE @a=1 GROUP BY t2.x);";
5842
+ set @a=2;
5843
+ execute stmt;
5844
+ EXPLAIN
5845
+ {
5846
+ "query_block": {
5847
+ "select_id": 1,
5848
+ "table": {
5849
+ "message": "Impossible WHERE noticed after reading const tables"
5850
+ },
5851
+ "subqueries": [
5852
+ {
5853
+ "materialization": {
5854
+ "query_block": {
5855
+ "select_id": 2,
5856
+ "table": {
5857
+ "message": "Impossible WHERE"
5858
+ }
5859
+ }
5860
+ }
5861
+ }
5862
+ ]
5863
+ }
5864
+ }
5865
+ set @a=1;
5866
+ # we expect to see having_condition in both the below statements
5867
+ execute stmt;
5868
+ EXPLAIN
5869
+ {
5870
+ "query_block": {
5871
+ "select_id": 1,
5872
+ "nested_loop": [
5873
+ {
5874
+ "table": {
5875
+ "table_name": "t1",
5876
+ "access_type": "ALL",
5877
+ "rows": 2,
5878
+ "filtered": 100,
5879
+ "attached_condition": "t1.b = t1.a and t1.a is not null and t1.a is not null"
5880
+ }
5881
+ },
5882
+ {
5883
+ "table": {
5884
+ "table_name": "<subquery2>",
5885
+ "access_type": "eq_ref",
5886
+ "possible_keys": ["distinct_key"],
5887
+ "key": "distinct_key",
5888
+ "key_length": "12",
5889
+ "used_key_parts": ["x", "COUNT(t2.y)"],
5890
+ "ref": ["test.t1.a", "test.t1.a"],
5891
+ "rows": 1,
5892
+ "filtered": 100,
5893
+ "attached_condition": "t1.a = `<subquery2>`.`COUNT(t2.y)`",
5894
+ "materialized": {
5895
+ "unique": 1,
5896
+ "materialization": {
5897
+ "query_block": {
5898
+ "select_id": 2,
5899
+ "having_condition": "`COUNT(t2.y)` = t2.x",
5900
+ "temporary_table": {
5901
+ "nested_loop": [
5902
+ {
5903
+ "table": {
5904
+ "table_name": "t2",
5905
+ "access_type": "ALL",
5906
+ "rows": 3,
5907
+ "filtered": 100
5908
+ }
5909
+ }
5910
+ ]
5911
+ }
5912
+ }
5913
+ }
5914
+ }
5915
+ }
5916
+ }
5917
+ ]
5918
+ }
5919
+ }
5920
+ execute stmt;
5921
+ EXPLAIN
5922
+ {
5923
+ "query_block": {
5924
+ "select_id": 1,
5925
+ "nested_loop": [
5926
+ {
5927
+ "table": {
5928
+ "table_name": "t1",
5929
+ "access_type": "ALL",
5930
+ "rows": 2,
5931
+ "filtered": 100,
5932
+ "attached_condition": "t1.b = t1.a and t1.a is not null and t1.a is not null"
5933
+ }
5934
+ },
5935
+ {
5936
+ "table": {
5937
+ "table_name": "<subquery2>",
5938
+ "access_type": "eq_ref",
5939
+ "possible_keys": ["distinct_key"],
5940
+ "key": "distinct_key",
5941
+ "key_length": "12",
5942
+ "used_key_parts": ["x", "COUNT(t2.y)"],
5943
+ "ref": ["test.t1.a", "test.t1.a"],
5944
+ "rows": 1,
5945
+ "filtered": 100,
5946
+ "attached_condition": "t1.a = `<subquery2>`.`COUNT(t2.y)`",
5947
+ "materialized": {
5948
+ "unique": 1,
5949
+ "materialization": {
5950
+ "query_block": {
5951
+ "select_id": 2,
5952
+ "having_condition": "`COUNT(t2.y)` = t2.x",
5953
+ "temporary_table": {
5954
+ "nested_loop": [
5955
+ {
5956
+ "table": {
5957
+ "table_name": "t2",
5958
+ "access_type": "ALL",
5959
+ "rows": 3,
5960
+ "filtered": 100
5961
+ }
5962
+ }
5963
+ ]
5964
+ }
5965
+ }
5966
+ }
5967
+ }
5968
+ }
5969
+ }
5970
+ ]
5971
+ }
5972
+ }
5973
+ drop table t1, t2;
5974
+ End of 10.11 tests
0 commit comments