If ICP is turned off the result returned by the query is correct:
MariaDB [test]> set optimizer_switch='index_condition_pushdown=off';
Query OK, 0 rows affected (0.00 sec)
MariaDB [test]> SELECT * FROM t3
-> WHERE a = (SELECTCOUNT(DISTINCT t2.b) FROM t1, t2
-> WHERE t1.a = t2.a AND t2.a BETWEEN 7 AND 9
-> AND t3.b = t1.b
-> GROUPBY t1.b);
+------+------+
| a | b |
+------+------+
| 1 | 0 |
| 1 | 1 |
| 1 | 3 |
+------+------+
3 rowsinset (0.00 sec)
The above test case is a simplified version of the test case for Oracle's bug#12667154 that can be found in http://lists.mysql.com/commits/143149
The fix itself (without any test case) was pulled into MariaDB 5.5.
The validity of the fix should be re-checked.
Note that lp:~maria-captains/maria/5.5-show-explain, which is based on 5.5.27 and has alternative fix developed for use with SHOW EXPLAIN, doesn't produce a wrong result.
Sergei Petrunia
added a comment - Sorry, somehow missed comment by Patryk.
Note that lp:~maria-captains/maria/5.5-show-explain, which is based on 5.5.27 and has alternative fix developed for use with SHOW EXPLAIN, doesn't produce a wrong result.
have made a patch that takes out Olav's fix
(revid: olav.sandstaa@oracle.com-20120516074923-vd0dhp183vqcp2ql )
and instead adds my fix ( revid:
psergey@askmonty.org-20120719115219-212cxmm6qvf0wlrb, branch: 5.5-show-explain,
then 10.0)
As a result of that, I've got a patch that can handle subqueries with pushed
index conditions. Testcase for MDEV-567 passes with it. However, it doesn't
work with MRR+ICP. I don't have a ready testcase for this, but looking at the
code I see that it won't work. These lines in create_sort_index():
<quote>
if (table->file->inited == handler::INDEX)
{
// Save index #, save index condition
join->pre_sort_index= table->file->active_index;
join->pre_sort_idx_pushed_cond= table->file->pushed_idx_cond;
// no need to save key_read?
err= table->file->ha_index_end();
}
</quote>
will not function correctly when using DS-MRR. With DS-MRR,
table->file->inited==handler::RND (DS-MRR uses secondary handler object for
index scans and primary handler object for fetching fows).
Sergei Petrunia
added a comment - have made a patch that takes out Olav's fix
(revid: olav.sandstaa@oracle.com-20120516074923-vd0dhp183vqcp2ql )
and instead adds my fix ( revid:
psergey@askmonty.org-20120719115219-212cxmm6qvf0wlrb, branch: 5.5-show-explain,
then 10.0)
As a result of that, I've got a patch that can handle subqueries with pushed
index conditions. Testcase for MDEV-567 passes with it. However, it doesn't
work with MRR+ICP. I don't have a ready testcase for this, but looking at the
code I see that it won't work. These lines in create_sort_index():
<quote>
if (table->file->inited == handler::INDEX)
{
// Save index #, save index condition
join->pre_sort_index= table->file->active_index;
join->pre_sort_idx_pushed_cond= table->file->pushed_idx_cond;
// no need to save key_read?
err= table->file->ha_index_end();
}
</quote>
will not function correctly when using DS-MRR. With DS-MRR,
table->file->inited==handler::RND (DS-MRR uses secondary handler object for
index scans and primary handler object for fetching fows).
Fix for Bug#12667154 SAME QUERY EXEC AS WHERE SUBQ GIVES DIFFERENT
...
So, the test case from the description does not fail anymore.
The fix introduced the bug MDEV-614/MDEV-536. This other bug was only fixed in 5.5 and up, and is still reproducible on 5.3. If it's necessary to fix it in 5.3, MDEV-614 can be re-opened, but I suppose it makes no sense to keep this one open any longer, so I close it as fixed.
Elena Stepanova
added a comment - The initial reported problem was fixed in 5.3.10 by the backport of the Oracle fix:
revno: 3586
revision-id: psergey@askmonty.org-20121010052122-1uua5ogs8pyoanbf
parent: sanja@montyprogram.com-20121005092655-1xfcw36gsdyhawu5
committer: Sergey Petrunya <psergey@askmonty.org>
branch nick: 5.3
timestamp: Wed 2012-10-10 09:21:22 +0400
message:
Backport of: olav.sandstaa@oracle.com-20120516074923-vd0dhp183vqcp2ql
.. into MariaDB 5.3
Fix for Bug#12667154 SAME QUERY EXEC AS WHERE SUBQ GIVES DIFFERENT
...
So, the test case from the description does not fail anymore.
The fix introduced the bug MDEV-614 / MDEV-536 . This other bug was only fixed in 5.5 and up, and is still reproducible on 5.3. If it's necessary to fix it in 5.3, MDEV-614 can be re-opened, but I suppose it makes no sense to keep this one open any longer, so I close it as fixed.
People
Sergei Petrunia
Igor Babaev (Inactive)
Votes:
0Vote for this issue
Watchers:
4Start watching this issue
Dates
Created:
Updated:
Resolved:
Git Integration
Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.
{"report":{"fcp":979.5,"ttfb":268.60000014305115,"pageVisibility":"visible","entityId":19643,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"bd0670c6-a887-42f7-bd78-f5da66bab7eb","navigationType":0,"readyForUser":1077.6000001430511,"redirectCount":0,"resourceLoadedEnd":1208.9000000953674,"resourceLoadedStart":273.90000009536743,"resourceTiming":[{"duration":135.79999995231628,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":273.90000009536743,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":273.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":409.7000000476837,"responseStart":0,"secureConnectionStart":0},{"duration":135.90000009536743,"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":274.2000000476837,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":274.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":410.10000014305115,"responseStart":0,"secureConnectionStart":0},{"duration":198.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":274.40000009536743,"connectEnd":274.40000009536743,"connectStart":274.40000009536743,"domainLookupEnd":274.40000009536743,"domainLookupStart":274.40000009536743,"fetchStart":274.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":274.40000009536743,"responseEnd":472.90000009536743,"responseStart":472.90000009536743,"secureConnectionStart":274.40000009536743},{"duration":273.5,"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":274.60000014305115,"connectEnd":274.60000014305115,"connectStart":274.60000014305115,"domainLookupEnd":274.60000014305115,"domainLookupStart":274.60000014305115,"fetchStart":274.60000014305115,"redirectEnd":0,"redirectStart":0,"requestStart":274.60000014305115,"responseEnd":548.1000001430511,"responseStart":548.1000001430511,"secureConnectionStart":274.60000014305115},{"duration":277.7000000476837,"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":274.7000000476837,"connectEnd":274.7000000476837,"connectStart":274.7000000476837,"domainLookupEnd":274.7000000476837,"domainLookupStart":274.7000000476837,"fetchStart":274.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":274.7000000476837,"responseEnd":552.4000000953674,"responseStart":552.3000001907349,"secureConnectionStart":274.7000000476837},{"duration":277.90000009536743,"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":274.90000009536743,"connectEnd":274.90000009536743,"connectStart":274.90000009536743,"domainLookupEnd":274.90000009536743,"domainLookupStart":274.90000009536743,"fetchStart":274.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":274.90000009536743,"responseEnd":552.8000001907349,"responseStart":552.8000001907349,"secureConnectionStart":274.90000009536743},{"duration":278.2000000476837,"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":275,"connectEnd":275,"connectStart":275,"domainLookupEnd":275,"domainLookupStart":275,"fetchStart":275,"redirectEnd":0,"redirectStart":0,"requestStart":275,"responseEnd":553.2000000476837,"responseStart":553.2000000476837,"secureConnectionStart":275},{"duration":347.60000014305115,"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":275.2000000476837,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":275.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":622.8000001907349,"responseStart":0,"secureConnectionStart":0},{"duration":278.2999999523163,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":275.40000009536743,"connectEnd":275.40000009536743,"connectStart":275.40000009536743,"domainLookupEnd":275.40000009536743,"domainLookupStart":275.40000009536743,"fetchStart":275.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":275.40000009536743,"responseEnd":553.7000000476837,"responseStart":553.6000001430511,"secureConnectionStart":275.40000009536743},{"duration":347.5,"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":275.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":275.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":623,"responseStart":0,"secureConnectionStart":0},{"duration":278.39999985694885,"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":275.80000019073486,"connectEnd":275.80000019073486,"connectStart":275.80000019073486,"domainLookupEnd":275.80000019073486,"domainLookupStart":275.80000019073486,"fetchStart":275.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":275.80000019073486,"responseEnd":554.2000000476837,"responseStart":554.2000000476837,"secureConnectionStart":275.80000019073486},{"duration":569.9000000953674,"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":291,"connectEnd":291,"connectStart":291,"domainLookupEnd":291,"domainLookupStart":291,"fetchStart":291,"redirectEnd":0,"redirectStart":0,"requestStart":291,"responseEnd":860.9000000953674,"responseStart":860.9000000953674,"secureConnectionStart":291},{"duration":902.9000000953674,"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":306,"connectEnd":306,"connectStart":306,"domainLookupEnd":306,"domainLookupStart":306,"fetchStart":306,"redirectEnd":0,"redirectStart":0,"requestStart":306,"responseEnd":1208.9000000953674,"responseStart":1208.9000000953674,"secureConnectionStart":306},{"duration":220.39999985694885,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":641.1000001430511,"connectEnd":641.1000001430511,"connectStart":641.1000001430511,"domainLookupEnd":641.1000001430511,"domainLookupStart":641.1000001430511,"fetchStart":641.1000001430511,"redirectEnd":0,"redirectStart":0,"requestStart":641.1000001430511,"responseEnd":861.5,"responseStart":861.4000000953674,"secureConnectionStart":641.1000001430511}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":93,"responseStart":268,"responseEnd":306,"domLoading":272,"domInteractive":1290,"domContentLoadedEventStart":1290,"domContentLoadedEventEnd":1347,"domComplete":1930,"loadEventStart":1930,"loadEventEnd":1931,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1266.6000001430511},{"name":"bigPipe.sidebar-id.end","time":1267.5},{"name":"bigPipe.activity-panel-pipe-id.start","time":1267.7000000476837},{"name":"bigPipe.activity-panel-pipe-id.end","time":1269.8000001907349},{"name":"activityTabFullyLoaded","time":1365}],"measures":[],"correlationId":"4c65ba1eec3896","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":107,"dbReadsTimeInMs":11,"dbConnsTimeInMs":19,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
The fix introduced other bug:
MDEV-536