I got some strange behaviour with subselect and missing rows.
following select produces 2 rows, and is_blacklisted equals 0 in both:
SELECT anon_1.shop_id AS shop_id,
|
anon_1.is_blacklisted AS is_blacklisted
|
FROM
|
(SELECT anon_2.shop_id AS shop_id,
|
CASE
|
WHEN (
|
(
|
(
|
anon_2.shop_white_flag IS NOT NULL
|
AND (anon_2.white_flags IS NULL
|
OR anon_2.white_flags NOT LIKE concat(concat('%|', anon_2.shop_white_flag), '|%')))
|
)
|
) THEN 1
|
ELSE 0
|
END AS is_blacklisted
|
FROM
|
(SELECT
|
customer_data.shop_id AS shop_id,
|
syndication_white_flags_1.code AS shop_white_flag,
|
group_concat(DISTINCT concat('|', syndication_white_flags.code, '|')) AS white_flags
|
FROM customer_data
|
INNER JOIN syndication_partners
|
LEFT OUTER JOIN syndication_partner_white_flags ON syndication_partner_white_flags.partner_id = syndication_partners.id
|
LEFT OUTER JOIN syndication_white_flags ON syndication_white_flags.id = syndication_partner_white_flags.flag_id
|
LEFT OUTER JOIN syndication_shop_white_flags ON syndication_shop_white_flags.customer_data_id = customer_data.id
|
LEFT OUTER JOIN syndication_white_flags AS syndication_white_flags_1 ON syndication_white_flags_1.id = syndication_shop_white_flags.white_flag_id
|
WHERE
|
syndication_partners.id = 427
|
GROUP BY customer_data.shop_id,
|
syndication_white_flags_1.code
|
) AS anon_2
|
) AS anon_1
|
;
|
Now I add a condition on is_blacklisted and I only get 1 row. (I tried several versions, "IS false", "= 0", "IS NOT true", all with the same behaviour)
SELECT anon_1.shop_id AS shop_id,
|
anon_1.is_blacklisted AS is_blacklisted
|
FROM
|
(SELECT anon_2.shop_id AS shop_id,
|
CASE
|
WHEN (
|
(
|
(
|
anon_2.shop_white_flag IS NOT NULL
|
AND (anon_2.white_flags IS NULL
|
OR anon_2.white_flags NOT LIKE concat(concat('%|', anon_2.shop_white_flag), '|%')))
|
)
|
) THEN 1
|
ELSE 0
|
END AS is_blacklisted
|
FROM
|
(SELECT
|
customer_data.shop_id AS shop_id,
|
syndication_white_flags_1.code AS shop_white_flag,
|
group_concat(DISTINCT concat('|', syndication_white_flags.code, '|')) AS white_flags
|
FROM customer_data
|
INNER JOIN syndication_partners
|
LEFT OUTER JOIN syndication_partner_white_flags ON syndication_partner_white_flags.partner_id = syndication_partners.id
|
LEFT OUTER JOIN syndication_white_flags ON syndication_white_flags.id = syndication_partner_white_flags.flag_id
|
LEFT OUTER JOIN syndication_shop_white_flags ON syndication_shop_white_flags.customer_data_id = customer_data.id
|
LEFT OUTER JOIN syndication_white_flags AS syndication_white_flags_1 ON syndication_white_flags_1.id = syndication_shop_white_flags.white_flag_id
|
WHERE
|
syndication_partners.id = 427
|
GROUP BY customer_data.shop_id,
|
syndication_white_flags_1.code
|
) AS anon_2
|
) AS anon_1
|
WHERE anon_1.is_blacklisted IS false
|
;
|
When I select into a temporary table, I get 2 rows again.
CREATE TEMPORARY TABLE foo SELECT anon_1.shop_id AS shop_id,
|
anon_1.is_blacklisted AS is_blacklisted
|
FROM
|
(SELECT anon_2.shop_id AS shop_id,
|
CASE
|
WHEN (
|
(
|
(
|
anon_2.shop_white_flag IS NOT NULL
|
AND (anon_2.white_flags IS NULL
|
OR anon_2.white_flags NOT LIKE concat(concat('%|', anon_2.shop_white_flag), '|%')))
|
)
|
) THEN 1
|
ELSE 0
|
END AS is_blacklisted
|
FROM
|
(SELECT
|
customer_data.shop_id AS shop_id,
|
syndication_white_flags_1.code AS shop_white_flag,
|
group_concat(DISTINCT concat('|', syndication_white_flags.code, '|')) AS white_flags
|
FROM customer_data
|
INNER JOIN syndication_partners
|
LEFT OUTER JOIN syndication_partner_white_flags ON syndication_partner_white_flags.partner_id = syndication_partners.id
|
LEFT OUTER JOIN syndication_white_flags ON syndication_white_flags.id = syndication_partner_white_flags.flag_id
|
LEFT OUTER JOIN syndication_shop_white_flags ON syndication_shop_white_flags.customer_data_id = customer_data.id
|
LEFT OUTER JOIN syndication_white_flags AS syndication_white_flags_1 ON syndication_white_flags_1.id = syndication_shop_white_flags.white_flag_id
|
WHERE
|
syndication_partners.id = 427
|
GROUP BY customer_data.shop_id,
|
syndication_white_flags_1.code
|
) AS anon_2
|
) AS anon_1
|
WHERE anon_1.is_blacklisted IS false
|
;
|
If I remove the syndication_white_flags_1.code in the group_by, it works too.
This bug didn't exist in 10.0.35.
We skipped the versions in between, so I can't say if this bug already existed in 10.1 or 10.2
Possibly related to: https://bugs.mysql.com/bug.php?id=88300
I don't think it's the same bug, but it's the only thing I found related to subqueries and incorrect returnsets
- relates to
-
MDEV-18383
Change of behaviour of OR in IF-conditions 10.2 -> 10.3
-
-
Closed
{"report":{"fcp":1003.1999998092651,"ttfb":302.8999996185303,"pageVisibility":"visible","entityId":68708,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"00b43132-4a83-41a0-82ab-7336bc6f860b","navigationType":0,"readyForUser":1191.3000001907349,"redirectCount":0,"resourceLoadedEnd":754.8999996185303,"resourceLoadedStart":309.30000019073486,"resourceTiming":[{"duration":52.30000019073486,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":309.30000019073486,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":309.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":361.6000003814697,"responseStart":0,"secureConnectionStart":0},{"duration":63.19999980926514,"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":309.6000003814697,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":309.6000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":372.80000019073486,"responseStart":0,"secureConnectionStart":0},{"duration":202.5999994277954,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":309.80000019073486,"connectEnd":309.80000019073486,"connectStart":309.80000019073486,"domainLookupEnd":309.80000019073486,"domainLookupStart":309.80000019073486,"fetchStart":309.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":375.80000019073486,"responseEnd":512.3999996185303,"responseStart":393.1000003814697,"secureConnectionStart":309.80000019073486},{"duration":348.6000003814697,"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":310,"connectEnd":310,"connectStart":310,"domainLookupEnd":310,"domainLookupStart":310,"fetchStart":310,"redirectEnd":0,"redirectStart":0,"requestStart":376.3999996185303,"responseEnd":658.6000003814697,"responseStart":394.19999980926514,"secureConnectionStart":310},{"duration":88,"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":310.19999980926514,"connectEnd":310.19999980926514,"connectStart":310.19999980926514,"domainLookupEnd":310.19999980926514,"domainLookupStart":310.19999980926514,"fetchStart":310.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":377.69999980926514,"responseEnd":398.19999980926514,"responseStart":396.6000003814697,"secureConnectionStart":310.19999980926514},{"duration":104.5,"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":310.30000019073486,"connectEnd":310.30000019073486,"connectStart":310.30000019073486,"domainLookupEnd":310.30000019073486,"domainLookupStart":310.30000019073486,"fetchStart":310.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":378.19999980926514,"responseEnd":414.80000019073486,"responseStart":413.6000003814697,"secureConnectionStart":310.30000019073486},{"duration":118.69999980926514,"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":310.5,"connectEnd":310.5,"connectStart":310.5,"domainLookupEnd":310.5,"domainLookupStart":310.5,"fetchStart":310.5,"redirectEnd":0,"redirectStart":0,"requestStart":392.3999996185303,"responseEnd":429.19999980926514,"responseStart":427.3999996185303,"secureConnectionStart":310.5},{"duration":67.30000019073486,"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":310.69999980926514,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":310.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":378,"responseStart":0,"secureConnectionStart":0},{"duration":118.59999942779541,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":310.80000019073486,"connectEnd":310.80000019073486,"connectStart":310.80000019073486,"domainLookupEnd":310.80000019073486,"domainLookupStart":310.80000019073486,"fetchStart":310.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":392.6000003814697,"responseEnd":429.3999996185303,"responseStart":428,"secureConnectionStart":310.80000019073486},{"duration":79.10000038146973,"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":311,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":311,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":390.1000003814697,"responseStart":0,"secureConnectionStart":0},{"duration":106.19999980926514,"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":311.1000003814697,"connectEnd":311.1000003814697,"connectStart":311.1000003814697,"domainLookupEnd":311.1000003814697,"domainLookupStart":311.1000003814697,"fetchStart":311.1000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":392.69999980926514,"responseEnd":417.30000019073486,"responseStart":415.80000019073486,"secureConnectionStart":311.1000003814697},{"duration":381.80000019073486,"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":323.80000019073486,"connectEnd":323.80000019073486,"connectStart":323.80000019073486,"domainLookupEnd":323.80000019073486,"domainLookupStart":323.80000019073486,"fetchStart":323.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":695,"responseEnd":705.6000003814697,"responseStart":704.8999996185303,"secureConnectionStart":323.80000019073486},{"duration":390.5,"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":364.3999996185303,"connectEnd":364.3999996185303,"connectStart":364.3999996185303,"domainLookupEnd":364.3999996185303,"domainLookupStart":364.3999996185303,"fetchStart":364.3999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":719.3999996185303,"responseEnd":754.8999996185303,"responseStart":754.3000001907349,"secureConnectionStart":364.3999996185303},{"duration":140.5,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":647.1000003814697,"connectEnd":647.1000003814697,"connectStart":647.1000003814697,"domainLookupEnd":647.1000003814697,"domainLookupStart":647.1000003814697,"fetchStart":647.1000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":719.5,"responseEnd":787.6000003814697,"responseStart":786.6000003814697,"secureConnectionStart":647.1000003814697},{"duration":284.8999996185303,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":908.3000001907349,"connectEnd":908.3000001907349,"connectStart":908.3000001907349,"domainLookupEnd":908.3000001907349,"domainLookupStart":908.3000001907349,"fetchStart":908.3000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":1160.8999996185303,"responseEnd":1193.1999998092651,"responseStart":1192.5,"secureConnectionStart":908.3000001907349}],"fetchStart":1,"domainLookupStart":1,"domainLookupEnd":1,"connectStart":1,"connectEnd":1,"requestStart":57,"responseStart":303,"responseEnd":365,"domLoading":308,"domInteractive":1273,"domContentLoadedEventStart":1273,"domContentLoadedEventEnd":1336,"domComplete":2166,"loadEventStart":2166,"loadEventEnd":2167,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1222.6999998092651},{"name":"bigPipe.sidebar-id.end","time":1223.3999996185303},{"name":"bigPipe.activity-panel-pipe-id.start","time":1223.6999998092651},{"name":"bigPipe.activity-panel-pipe-id.end","time":1232.3000001907349},{"name":"activityTabFullyLoaded","time":1355.6999998092651}],"measures":[],"correlationId":"6c42cb1d8734a","effectiveType":"4g","downlink":9.3,"rtt":0,"serverDuration":168,"dbReadsTimeInMs":59,"dbConnsTimeInMs":68,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
Thanks for the report!
Reproducible on 10.2, 10.3
MariaDB [test]> SELECT tmp1.ib
-> FROM (SELECT CASE WHEN (tmp2.wf IS NULL OR tmp2.wf NOT LIKE '%test%') THEN 1 ELSE 0 END AS ib
-> FROM (SELECT 'test' AS wf FROM t1 GROUP BY t1.v1) AS tmp2) AS tmp1;
+----+
| ib |
+----+
| 0 |
+----+
1 row in set (0.00 sec)
MariaDB [test]> SELECT tmp1.ib
-> FROM (SELECT CASE WHEN (tmp2.wf IS NULL OR tmp2.wf NOT LIKE '%test%') THEN 1 ELSE 0 END AS ib
-> FROM (SELECT 'test' AS wf FROM t1 GROUP BY t1.v1) AS tmp2) AS tmp1
-> WHERE tmp1.ib=0 ;
Empty set (0.00 sec)
MariaDB [test]> explain extended
-> SELECT tmp1.ib
-> FROM (SELECT CASE WHEN (tmp2.wf IS NULL OR tmp2.wf NOT LIKE '%test%') THEN 1 ELSE 0 END AS ib
-> FROM (SELECT 'test' AS wf FROM t1 GROUP BY t1.v1) AS tmp2) AS tmp1
-> WHERE tmp1.ib=0 ;
+------+-------------+------------+------+---------------+------+---------+------+------+----------+----------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+------+-------------+------------+------+---------------+------+---------+------+------+----------+----------------------------------------------+
| 1 | PRIMARY | <derived3> | ALL | NULL | NULL | NULL | NULL | 2 | 100.00 | Using where |
| 3 | DERIVED | t1 | ALL | NULL | NULL | NULL | NULL | 1 | 100.00 | Using where; Using temporary; Using filesort |
+------+-------------+------------+------+---------------+------+---------+------+------+----------+----------------------------------------------+
2 rows in set, 1 warning (0.00 sec)
Note (Code 1003): select case when (<cache>(`tmp2`.`wf` is null) or `tmp2`.`wf` not like '%test%') then 1 else 0 end AS `ib` from (select 'test' AS `wf` from `test`.`t1` where case when (<cache>(`tmp2`.`wf` is null) or `tmp2`.`wf` not like '%test%') then 1 else 0 end = 0 group by `test`.`t1`.`v1`) `tmp2` where case when (<cache>(`tmp2`.`wf` is null) or `tmp2`.`wf` not like '%test%') then 1 else 0 end = 0
MariaDB [test]> explain extended SELECT tmp1.ib FROM (SELECT CASE WHEN (tmp2.wf IS NULL OR tmp2.wf NOT LIKE '%test%') THEN 1 ELSE 0 END AS ib FROM (SELECT 'test' AS wf FROM t1 GROUP BY t1.v1) AS tmp2) AS tmp1;
+------+-------------+------------+------+---------------+------+---------+------+------+----------+---------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+------+-------------+------------+------+---------------+------+---------+------+------+----------+---------------------------------+
| 1 | PRIMARY | <derived3> | ALL | NULL | NULL | NULL | NULL | 2 | 100.00 | |
| 3 | DERIVED | t1 | ALL | NULL | NULL | NULL | NULL | 1 | 100.00 | Using temporary; Using filesort |
+------+-------------+------------+------+---------------+------+---------+------+------+----------+---------------------------------+
2 rows in set, 1 warning (0.01 sec)
Note (Code 1003): select case when (`tmp2`.`wf` is null or `tmp2`.`wf` not like '%test%') then 1 else 0 end AS `ib` from (select 'test' AS `wf` from `test`.`t1` group by `test`.`t1`.`v1`) `tmp2`