create table ten(a int);
|
insert into ten values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
|
create table t1 (key1 int, col1 int, filler1 varchar(100), filler varchar(100), key(key1));
|
insert into t1
|
select A.a + B.a* 10 + C.a * 100,
|
A.a + B.a* 10 + C.a * 100,
|
'filler1-data', 'filler2-data'
|
from
|
ten A, ten B, ten C;
|
set histogram_size=100;
|
set use_stat_tables='preferably';
|
set optimizer_use_condition_selectivity=4;
|
analyze table t1 persistent for all;
|
Let's check the data distribution. First, we have a non-indexed condition with
50% selectivity.
explain extended select * from t1 where col1 < 500;
|
+------+-------------+-------+------+---------------+------+---------+------+------+----------+-------------+
|
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
|
+------+-------------+-------+------+---------------+------+---------+------+------+----------+-------------+
|
| 1 | SIMPLE | t1 | ALL | NULL | NULL | NULL | NULL | 1000 | 50.50 | Using where |
|
+------+-------------+-------+------+---------------+------+---------+------+------+----------+-------------+
|
Second, "key1<10" produces a range access which selects 10/1000= 1/100th of the
table:
explain extended select * from t1 where key1<10 ;
|
+------+-------------+-------+-------+---------------+------+---------+------+------+----------+-----------------------+
|
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
|
+------+-------------+-------+-------+---------------+------+---------+------+------+----------+-----------------------+
|
| 1 | SIMPLE | t1 | range | key1 | key1 | 5 | NULL | 9 | 100.00 | Using index condition |
|
+------+-------------+-------+-------+---------------+------+---------+------+------+----------+-----------------------+
|
Now, let's use both conditions:
explain extended select * from t1 where key1<10 and col1< 500;
|
+------+-------------+-------+-------+---------------+------+---------+------+------+----------+------------------------------------+
|
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
|
+------+-------------+-------+-------+---------------+------+---------+------+------+----------+------------------------------------+
|
| 1 | SIMPLE | t1 | range | key1 | key1 | 5 | NULL | 9 | 50.50 | Using index condition; Using where |
|
+------+-------------+-------+-------+---------------+------+---------+------+------+----------+------------------------------------+
|
EXPLAIN looks ok. However, in debugger, one can see:
Breakpoint 31, matching_candidates_in_table (...
|
(gdb) fini
|
Run till exit from #0 matching_candidates_in_table (...
|
Value returned is $279 = 4.5445544554455441
|
4.5 records is 9 records * 0.5 selectivity. Ok so far.
Breakpoint 32, table_cond_selectivity (...
|
(gdb) fini
|
0x000000000069e43e in best_extension_by_limited_search (...
|
Value returned is $281 = 0.50495049504950495
|
(gdb) list
|
7597 double partial_join_cardinality= current_record_count *
|
7598 pushdown_cond_selectivity;
|
(gdb) print partial_join_cardinality
|
$283 = 2.294775022056661
|
Ooops. Selectivity=0.5 has been applied for the second time, and now we've got
9 * 0.5 * 0.5 = 2.25 for estimate.
Let's check if it matters..
create table t2 as select * from t1;
|
explain extended select * from t1,t2 where t1.key1<10 and t1.col1< 500;
|
For the last query, put a breakpoint in best_access_path().
Breakpoint 33, best_access_path (join=0x7fffca5a4088, s=0x7fffca5a5038, remaining_tables=3, idx=0, disable_jbuf=false, record_count=1, pos=0x7fffca5a58b0, loose_scan_pos=0x7ffff7e9fac0) at /home/psergey/dev2/10.0/sql/sql_select.cc:5642
|
(gdb) p s->table->alias.Ptr
|
$288 = 0x7fffca4215f0 "t1"
|
(gdb) c
|
Continuing.
|
|
Breakpoint 33, best_access_path (join=0x7fffca5a4088, s=0x7fffca5a5360, remaining_tables=2, idx=1, disable_jbuf=false, record_count=2.294775022056661, pos=0x7fffca5a59b8, loose_scan_pos=0x7ffff7e9f8b0) at /home/psergey/dev2/10.0/sql/sql_select.cc:5642
|
(gdb) p s->table->alias.Ptr
|
$289 = 0x7fffca5a7270 "t2"
|
See: table t2 has got record_count=2.29. Half of what should be.
Sergei Petrunia
made changes -
Field |
Original Value |
New Value |
Assignee
|
|
Igor Babaev
[ igor
]
|
Sergei Petrunia
made changes -
Assignee
|
Igor Babaev
[ igor
]
|
Sergei Petrunia
[ psergey
]
|
Sergei Petrunia
made changes -
Status
|
Open
[ 1
]
|
In Progress
[ 3
]
|
Sergei Petrunia
made changes -
Fix Version/s
|
|
10.0.11
[ 15200
]
|
Sergei Petrunia
made changes -
Resolution
|
|
Fixed
[ 1
]
|
Status
|
In Progress
[ 3
]
|
Closed
[ 6
]
|
Sergei Golubchik
made changes -
Workflow
|
defaullt
[ 37909
]
|
MariaDB v2
[ 43608
]
|
Sergei Golubchik
made changes -
Workflow
|
MariaDB v3
[ 62749
]
|
MariaDB v4
[ 147729
]
|
{"report":{"fcp":883.2000000476837,"ttfb":292.7000000476837,"pageVisibility":"visible","entityId":34109,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":1,"journeyId":"9748c700-d918-49c2-bb72-4279ea433a62","navigationType":0,"readyForUser":963.3000000715256,"redirectCount":0,"resourceLoadedEnd":1418.8000000715256,"resourceLoadedStart":297.89999997615814,"resourceTiming":[{"duration":82.40000009536743,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":297.89999997615814,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":297.89999997615814,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":380.3000000715256,"responseStart":0,"secureConnectionStart":0},{"duration":82.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2bu7/820016/12ta74/8679b4946efa1a0bb029a3a22206fb5d/_/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","startTime":298.2000000476837,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":298.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":380.7000000476837,"responseStart":0,"secureConnectionStart":0},{"duration":137.70000004768372,"initiatorType":"script","name":"https://jira.mariadb.org/s/fbf975c0cce4b1abf04784eeae9ba1f4-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":298.39999997615814,"connectEnd":298.39999997615814,"connectStart":298.39999997615814,"domainLookupEnd":298.39999997615814,"domainLookupStart":298.39999997615814,"fetchStart":298.39999997615814,"redirectEnd":0,"redirectStart":0,"requestStart":298.39999997615814,"responseEnd":436.10000002384186,"responseStart":436.10000002384186,"secureConnectionStart":298.39999997615814},{"duration":193,"initiatorType":"script","name":"https://jira.mariadb.org/s/099b33461394b8015fc36c0a4b96e19f-CDN/lu2bu7/820016/12ta74/8679b4946efa1a0bb029a3a22206fb5d/_/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","startTime":298.5,"connectEnd":298.5,"connectStart":298.5,"domainLookupEnd":298.5,"domainLookupStart":298.5,"fetchStart":298.5,"redirectEnd":0,"redirectStart":0,"requestStart":298.5,"responseEnd":491.5,"responseStart":491.5,"secureConnectionStart":298.5},{"duration":196.19999992847443,"initiatorType":"script","name":"https://jira.mariadb.org/s/94c15bff32baef80f4096a08aceae8bc-CDN/lu2bu7/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":298.7000000476837,"connectEnd":298.7000000476837,"connectStart":298.7000000476837,"domainLookupEnd":298.7000000476837,"domainLookupStart":298.7000000476837,"fetchStart":298.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":298.7000000476837,"responseEnd":494.89999997615814,"responseStart":494.89999997615814,"secureConnectionStart":298.7000000476837},{"duration":196.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":299,"connectEnd":299,"connectStart":299,"domainLookupEnd":299,"domainLookupStart":299,"fetchStart":299,"redirectEnd":0,"redirectStart":0,"requestStart":299,"responseEnd":495.5,"responseStart":495.39999997615814,"secureConnectionStart":299},{"duration":196.70000004768372,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":299.10000002384186,"connectEnd":299.10000002384186,"connectStart":299.10000002384186,"domainLookupEnd":299.10000002384186,"domainLookupStart":299.10000002384186,"fetchStart":299.10000002384186,"redirectEnd":0,"redirectStart":0,"requestStart":299.10000002384186,"responseEnd":495.8000000715256,"responseStart":495.8000000715256,"secureConnectionStart":299.10000002384186},{"duration":277.10000002384186,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2bu7/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":299.39999997615814,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":299.39999997615814,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":576.5,"responseStart":0,"secureConnectionStart":0},{"duration":196.80000007152557,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":299.5,"connectEnd":299.5,"connectStart":299.5,"domainLookupEnd":299.5,"domainLookupStart":299.5,"fetchStart":299.5,"redirectEnd":0,"redirectStart":0,"requestStart":299.5,"responseEnd":496.3000000715256,"responseStart":496.3000000715256,"secureConnectionStart":299.5},{"duration":276.89999997615814,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2bu7/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":299.7000000476837,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":299.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":576.6000000238419,"responseStart":0,"secureConnectionStart":0},{"duration":197.09999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/3339d87fa2538a859872f2df449bf8d0-CDN/lu2bu7/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":299.8000000715256,"connectEnd":299.8000000715256,"connectStart":299.8000000715256,"domainLookupEnd":299.8000000715256,"domainLookupStart":299.8000000715256,"fetchStart":299.8000000715256,"redirectEnd":0,"redirectStart":0,"requestStart":299.8000000715256,"responseEnd":496.89999997615814,"responseStart":496.8000000715256,"secureConnectionStart":299.8000000715256},{"duration":500.8000000715256,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":305,"connectEnd":305,"connectStart":305,"domainLookupEnd":305,"domainLookupStart":305,"fetchStart":305,"redirectEnd":0,"redirectStart":0,"requestStart":305,"responseEnd":805.8000000715256,"responseStart":805.7000000476837,"secureConnectionStart":305},{"duration":1092.8999999761581,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":305.10000002384186,"connectEnd":305.10000002384186,"connectStart":305.10000002384186,"domainLookupEnd":305.10000002384186,"domainLookupStart":305.10000002384186,"fetchStart":305.10000002384186,"redirectEnd":0,"redirectStart":0,"requestStart":305.10000002384186,"responseEnd":1398,"responseStart":1398,"secureConnectionStart":305.10000002384186},{"duration":219.29999995231628,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":587.7000000476837,"connectEnd":587.7000000476837,"connectStart":587.7000000476837,"domainLookupEnd":587.7000000476837,"domainLookupStart":587.7000000476837,"fetchStart":587.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":587.7000000476837,"responseEnd":807,"responseStart":806.8999999761581,"secureConnectionStart":587.7000000476837},{"duration":577.8000000715256,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/e65b778d185daf5aee24936755b43da6/_/download/contextbatch/js/browser-metrics-plugin.contrib,-_super,-project.issue.navigator,-jira.view.issue,-atl.general/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true","startTime":841,"connectEnd":841,"connectStart":841,"domainLookupEnd":841,"domainLookupStart":841,"fetchStart":841,"redirectEnd":0,"redirectStart":0,"requestStart":841,"responseEnd":1418.8000000715256,"responseStart":1418.8000000715256,"secureConnectionStart":841},{"duration":622.6000000238419,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":877.7000000476837,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":877.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1500.3000000715256,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":105,"responseStart":292,"responseEnd":299,"domLoading":296,"domInteractive":1420,"domContentLoadedEventStart":1420,"domContentLoadedEventEnd":1464,"domComplete":1748,"loadEventStart":1748,"loadEventEnd":1748,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1399.7000000476837},{"name":"bigPipe.sidebar-id.end","time":1400.6000000238419},{"name":"bigPipe.activity-panel-pipe-id.start","time":1400.8000000715256},{"name":"bigPipe.activity-panel-pipe-id.end","time":1402.8999999761581},{"name":"activityTabFullyLoaded","time":1515.2000000476837}],"measures":[],"correlationId":"b1359a7a9a78df","effectiveType":"4g","downlink":9.6,"rtt":0,"serverDuration":116,"dbReadsTimeInMs":16,"dbConnsTimeInMs":25,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}