Note: I'm filing it separately from MDEV-6486, because the test case in MDEV-6486 does not cause a crash on 10.1 and 10.2, while this one does.
CREATE TABLE t1 (pk INT, f1 INT NOT NULL, f2 VARCHAR(3), f3 INT NULL, PRIMARY KEY(pk)) ENGINE=MyISAM;
|
INSERT INTO t1 VALUES (1,1,'foo',8), (2,5,'bar',7);
|
|
SELECT STRAIGHT_JOIN sq1.f2 FROM ( SELECT * FROM t1 ) AS sq1
|
WHERE EXISTS ( SELECT * FROM t1 AS sq2 WHERE sq1.`pk` IN ( SELECT f1 FROM t1 ) AND sq2.f1 = sq1.f1 );
|
Stack trace from 10.0 commit cee9ab9d85a8d75290b0d60bc7af26c8cf179a1d
|
mysqld: /src/10.0/sql/field.cc:3794: virtual longlong Field_long::val_int(): Assertion `!table || (!table->read_set || bitmap_is_set(table->read_set, field_index))' failed.
|
160511 1:10:11 [ERROR] mysqld got signal 6 ;
|
|
#7 0x00007feeb507e1d2 in __assert_fail () from /lib64/libc.so.6
|
#8 0x0000000000838184 in Field_long::val_int (this=0x7feeafb28fe0) at /src/10.0/sql/field.cc:3794
|
#9 0x0000000000873d42 in Item_field::val_int (this=0x7feeada2ec28) at /src/10.0/sql/item.cc:2592
|
#10 0x0000000000880e7f in Item_direct_ref::val_int (this=0x7feeada30be8) at /src/10.0/sql/item.cc:7519
|
#11 0x000000000088ad5b in Item_direct_view_ref::val_int (this=0x7feeada30be8) at /src/10.0/sql/item.h:3821
|
#12 0x0000000000891e59 in Arg_comparator::compare_int_signed (this=0x7feeada8f608) at /src/10.0/sql/item_cmpfunc.cc:1201
|
#13 0x00000000008a265a in Arg_comparator::compare (this=0x7feeada8f608) at /src/10.0/sql/item_cmpfunc.h:81
|
#14 0x0000000000894169 in Item_func_eq::val_int (this=0x7feeada8f540) at /src/10.0/sql/item_cmpfunc.cc:1976
|
#15 0x00000000006cd016 in evaluate_join_record (join=0x7feeada304b8, join_tab=0x7feeada8e120, error=0) at /src/10.0/sql/sql_select.cc:17938
|
#16 0x00000000006ccc55 in sub_select (join=0x7feeada304b8, join_tab=0x7feeada8e120, end_of_records=false) at /src/10.0/sql/sql_select.cc:17841
|
#17 0x00000000006cc4c9 in do_select (join=0x7feeada304b8, fields=0x7feeada78cd0, table=0x0, procedure=0x0) at /src/10.0/sql/sql_select.cc:17503
|
#18 0x00000000006a973a in JOIN::exec_inner (this=0x7feeada304b8) at /src/10.0/sql/sql_select.cc:3084
|
#19 0x00000000006a6c0a in JOIN::exec (this=0x7feeada304b8) at /src/10.0/sql/sql_select.cc:2373
|
#20 0x00000000007d8ccd in join_tab_execution_startup (tab=0x7feead860968) at /src/10.0/sql/opt_subselect.cc:5119
|
#21 0x00000000006ccb85 in sub_select (join=0x7feeada2e5e0, join_tab=0x7feead860968, end_of_records=false) at /src/10.0/sql/sql_select.cc:17829
|
#22 0x00000000006cd333 in evaluate_join_record (join=0x7feeada2e5e0, join_tab=0x7feead860640, error=0) at /src/10.0/sql/sql_select.cc:18063
|
#23 0x00000000006ccc55 in sub_select (join=0x7feeada2e5e0, join_tab=0x7feead860640, end_of_records=false) at /src/10.0/sql/sql_select.cc:17841
|
#24 0x00000000006cc4c9 in do_select (join=0x7feeada2e5e0, fields=0x7feeb11ee128, table=0x0, procedure=0x0) at /src/10.0/sql/sql_select.cc:17503
|
#25 0x00000000006a973a in JOIN::exec_inner (this=0x7feeada2e5e0) at /src/10.0/sql/sql_select.cc:3084
|
#26 0x00000000006a6c0a in JOIN::exec (this=0x7feeada2e5e0) at /src/10.0/sql/sql_select.cc:2373
|
#27 0x00000000006a9fb7 in mysql_select (thd=0x7feeb11e9fb0, rref_pointer_array=0x7feeb11ee288, tables=0x7feeada79ed0, wild_num=0, fields=..., conds=0x7feeada2e398, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2147748610, result=0x7feeada2e5c0, unit=0x7feeb11ed920, select_lex=0x7feeb11ee010) at /src/10.0/sql/sql_select.cc:3308
|
#28 0x00000000006a0333 in handle_select (thd=0x7feeb11e9fb0, lex=0x7feeb11ed858, result=0x7feeada2e5c0, setup_tables_done_option=0) at /src/10.0/sql/sql_select.cc:373
|
#29 0x0000000000674b85 in execute_sqlcom_select (thd=0x7feeb11e9fb0, all_tables=0x7feeada79ed0) at /src/10.0/sql/sql_parse.cc:5293
|
#30 0x000000000066d09f in mysql_execute_command (thd=0x7feeb11e9fb0) at /src/10.0/sql/sql_parse.cc:2562
|
#31 0x00000000006777cd in mysql_parse (thd=0x7feeb11e9fb0, rawbuf=0x7feeada77088 "SELECT STRAIGHT_JOIN sq1.f2 FROM ( SELECT * FROM t1 ) AS sq1\nWHERE EXISTS ( SELECT * FROM t1 AS sq2 WHERE sq1.`pk` IN ( SELECT f1 FROM t1 ) AND sq2.f1 = sq1.f1 )", length=161, parser_state=0x7feeb7128650) at /src/10.0/sql/sql_parse.cc:6574
|
#32 0x000000000066a309 in dispatch_command (command=COM_QUERY, thd=0x7feeb11e9fb0, packet=0x7feeafb3a1b1 "", packet_length=161) at /src/10.0/sql/sql_parse.cc:1308
|
#33 0x00000000006695d6 in do_command (thd=0x7feeb11e9fb0) at /src/10.0/sql/sql_parse.cc:998
|
#34 0x0000000000787cb2 in do_handle_one_connection (thd_arg=0x7feeb11e9fb0) at /src/10.0/sql/sql_connect.cc:1378
|
#35 0x0000000000787a24 in handle_one_connection (arg=0x7feeb11e9fb0) at /src/10.0/sql/sql_connect.cc:1293
|
#36 0x0000000000df561c in pfs_spawn_thread (arg=0x7feeaebbf4f0) at /src/10.0/storage/perfschema/pfs.cc:1860
|
#37 0x00007feeb6da10a4 in start_thread () from /lib64/libpthread.so.0
|
#38 0x00007feeb513504d in clone () from /lib64/libc.so.6
|
EXPLAIN
|
EXPLAIN EXTENDED
|
SELECT STRAIGHT_JOIN sq1.f2 FROM ( SELECT * FROM t1 ) AS sq1
|
WHERE EXISTS ( SELECT * FROM t1 AS sq2 WHERE sq1.`pk` IN ( SELECT f1 FROM t1 ) AND sq2.f1 = sq1.f1 );
|
id select_type table type possible_keys key key_len ref rows filtered Extra
|
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
|
1 PRIMARY <subquery3> eq_ref distinct_key distinct_key 4 test.t1.f1 1 100.00
|
3 MATERIALIZED <subquery4> eq_ref distinct_key distinct_key 4 func 1 100.00
|
3 MATERIALIZED sq2 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (flat, BNL join)
|
4 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 100.00
|
Warnings:
|
Note 1276 Field or reference 'sq1.pk' of SELECT #3 was resolved in SELECT #1
|
Note 1276 Field or reference 'sq1.f1' of SELECT #3 was resolved in SELECT #1
|
Note 1003 select straight_join `test`.`t1`.`f2` AS `f2` from <materialize> (select `test`.`sq2`.`f1` from `test`.`t1` `sq2` semi join (`test`.`t1`) where (`test`.`t1`.`pk` = `test`.`t1`.`f1`)) join `test`.`t1` where (`<subquery3>`.`f1` = `test`.`t1`.`f1`)
|
5.5 does not fail.
- relates to
-
MDEV-6486
Assertion `!table || (!table->read_set || bitmap_is_set(table->read_set, field_index))' failed with SELECT SQ, TEXT field
-
-
Closed
{"report":{"fcp":1759.9000000953674,"ttfb":641.8000001907349,"pageVisibility":"visible","entityId":56697,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"e6f5093e-737e-4d54-971d-47590c53d2af","navigationType":0,"readyForUser":1857.8000001907349,"redirectCount":0,"resourceLoadedEnd":2223.300000190735,"resourceLoadedStart":647.5,"resourceTiming":[{"duration":634.5999999046326,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":647.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":647.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1282.0999999046326,"responseStart":0,"secureConnectionStart":0},{"duration":634.6999998092651,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/download/contextbatch/css/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":647.7000002861023,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":647.7000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1282.4000000953674,"responseStart":0,"secureConnectionStart":0},{"duration":645.6999998092651,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":647.8000001907349,"connectEnd":647.8000001907349,"connectStart":647.8000001907349,"domainLookupEnd":647.8000001907349,"domainLookupStart":647.8000001907349,"fetchStart":647.8000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":647.8000001907349,"responseEnd":1293.5,"responseStart":1293.5,"secureConnectionStart":647.8000001907349},{"duration":693.1000003814697,"initiatorType":"script","name":"https://jira.mariadb.org/s/2d8175ec2fa4c816e8023260bd8c1786-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/download/contextbatch/js/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true&whisper-enabled=true","startTime":648.0999999046326,"connectEnd":648.0999999046326,"connectStart":648.0999999046326,"domainLookupEnd":648.0999999046326,"domainLookupStart":648.0999999046326,"fetchStart":648.0999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":648.0999999046326,"responseEnd":1341.2000002861023,"responseStart":1341.2000002861023,"secureConnectionStart":648.0999999046326},{"duration":697.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/a9324d6758d385eb45c462685ad88f1d-CDN/lu2cib/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":648.2000002861023,"connectEnd":648.2000002861023,"connectStart":648.2000002861023,"domainLookupEnd":648.2000002861023,"domainLookupStart":648.2000002861023,"fetchStart":648.2000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":648.2000002861023,"responseEnd":1345.7000002861023,"responseStart":1345.7000002861023,"secureConnectionStart":648.2000002861023},{"duration":698.4000000953674,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":648.3000001907349,"connectEnd":648.3000001907349,"connectStart":648.3000001907349,"domainLookupEnd":648.3000001907349,"domainLookupStart":648.3000001907349,"fetchStart":648.3000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":648.3000001907349,"responseEnd":1346.7000002861023,"responseStart":1346.7000002861023,"secureConnectionStart":648.3000001907349},{"duration":698.8000001907349,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":648.5,"connectEnd":648.5,"connectStart":648.5,"domainLookupEnd":648.5,"domainLookupStart":648.5,"fetchStart":648.5,"redirectEnd":0,"redirectStart":0,"requestStart":648.5,"responseEnd":1347.3000001907349,"responseStart":1347.3000001907349,"secureConnectionStart":648.5},{"duration":786.8999996185303,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2cib/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":648.7000002861023,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":648.7000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1435.5999999046326,"responseStart":0,"secureConnectionStart":0},{"duration":698.9000000953674,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":648.9000000953674,"connectEnd":648.9000000953674,"connectStart":648.9000000953674,"domainLookupEnd":648.9000000953674,"domainLookupStart":648.9000000953674,"fetchStart":648.9000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":648.9000000953674,"responseEnd":1347.8000001907349,"responseStart":1347.8000001907349,"secureConnectionStart":648.9000000953674},{"duration":786.7000002861023,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/css/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.css?jira.create.linked.issue=true","startTime":649.0999999046326,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":649.0999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1435.8000001907349,"responseStart":0,"secureConnectionStart":0},{"duration":699.1999998092651,"initiatorType":"script","name":"https://jira.mariadb.org/s/5d5e8fe91fbc506585e83ea3b62ccc4b-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/js/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.js?jira.create.linked.issue=true&locale=en","startTime":649.3000001907349,"connectEnd":649.3000001907349,"connectStart":649.3000001907349,"domainLookupEnd":649.3000001907349,"domainLookupStart":649.3000001907349,"fetchStart":649.3000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":649.3000001907349,"responseEnd":1348.5,"responseStart":1348.5,"secureConnectionStart":649.3000001907349},{"duration":987.6999998092651,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":655.2000002861023,"connectEnd":655.2000002861023,"connectStart":655.2000002861023,"domainLookupEnd":655.2000002861023,"domainLookupStart":655.2000002861023,"fetchStart":655.2000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":655.2000002861023,"responseEnd":1642.9000000953674,"responseStart":1642.9000000953674,"secureConnectionStart":655.2000002861023},{"duration":1566.0999999046326,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":657.2000002861023,"connectEnd":657.2000002861023,"connectStart":657.2000002861023,"domainLookupEnd":657.2000002861023,"domainLookupStart":657.2000002861023,"fetchStart":657.2000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":657.2000002861023,"responseEnd":2223.300000190735,"responseStart":2223.300000190735,"secureConnectionStart":657.2000002861023},{"duration":198.39999961853027,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":1447.2000002861023,"connectEnd":1447.2000002861023,"connectStart":1447.2000002861023,"domainLookupEnd":1447.2000002861023,"domainLookupStart":1447.2000002861023,"fetchStart":1447.2000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":1447.2000002861023,"responseEnd":1645.5999999046326,"responseStart":1645.5999999046326,"secureConnectionStart":1447.2000002861023},{"duration":582.1999998092651,"initiatorType":"link","name":"https://jira.mariadb.org/s/d5715adaadd168a9002b108b2b039b50-CDN/lu2cib/820016/12ta74/be4b45e9cec53099498fa61c8b7acba4/_/download/contextbatch/css/jira.project.sidebar,-_super,-project.issue.navigator,-jira.general,-jira.browse.project,-jira.view.issue,-jira.global,-atl.general,-com.atlassian.jira.projects.sidebar.init/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":1710.7000002861023,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1710.7000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":2292.9000000953674,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":468,"responseStart":642,"responseEnd":657,"domLoading":645,"domInteractive":2244,"domContentLoadedEventStart":2245,"domContentLoadedEventEnd":2293,"domComplete":2919,"loadEventStart":2919,"loadEventEnd":2920,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":2225.300000190735},{"name":"bigPipe.sidebar-id.end","time":2226.0999999046326},{"name":"bigPipe.activity-panel-pipe-id.start","time":2226.2000002861023},{"name":"bigPipe.activity-panel-pipe-id.end","time":2227.7000002861023},{"name":"activityTabFullyLoaded","time":2309.4000000953674}],"measures":[],"correlationId":"2abe3aab2fc504","effectiveType":"4g","downlink":9.8,"rtt":0,"serverDuration":107,"dbReadsTimeInMs":13,"dbConnsTimeInMs":22,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
Here's what happened with this query.
After merging with derived table sq1
the EXIST subquery was re-written into an IN sibquery:
SELECT STRAIGHT_JOIN sq1.f2 FROM t1 AS sq1
WHERE EXISTS ( SELECT * FROM t1 AS sq2 WHERE sq1.`pk` IN ( SELECT f1 FROM t1 ) AND sq2.f1 = sq1.f1 );
=>
SELECT STRAIGHT_JOIN sq1.f2 FROM t1 AS sq1
WHERE sq1.f1 IN ( SELECT sq2.f1 t1 AS sq2 WHERE sq1.`pk` IN ( SELECT f1 FROM t1 ) );
It was done in Item_exists_subselect::exists2in_processor. When doing this the function checked whether the subquery under IN will be correlated. This check was done incorrectly: the outer reference sq1.`pk` was not taken into account because Item::collect_outer_ref_processor was never called for it.
The Item_exists_subselect::exists2in_processor called check_and_do_in_subquery_rewrites().
Here it was found out that the optimization for the obtained IN subquery cannot be applied
due to STRAIGHT_JOIN and the subquery is re-written back into an EXIST subquery.
SELECT STRAIGHT_JOIN sq1.f2 FROM t1 AS sq1
WHERE sq1.f1 IN ( SELECT sq2.f1 t1 AS sq2 WHERE sq1.`pk` IN ( SELECT f1 FROM t1 ) );
=>
SELECT STRAIGHT_JOIN sq1.f2 FROM t1 AS sq1
WHERE EXISTS ( SELECT sq2.f1 t1 AS sq2 WHERE sq1.`pk` IN ( SELECT f1 FROM t1 ) AND sq1.f1=sq2.f1);
Having misled by the bug the optimizer decided that the subquery predicate
sq1.`pk` IN ( SELECT f1 FROM t1 )
(noformat}
has no outer references and it can be evaluated with materialization of the subquery
(noformat}
SELECT f1 FROM t1
Yet, when the executer tried to get the first key for a look-up into this table it discovered
that the field sq1.`pk` is not among read fields of sq2.