Type:
Bug
Priority:
Minor
Resolution:
Not a Bug
Affects Version/s:
N/A
In the test case below, the filtered value with JSON histogram is far away from r_filtered , while with DOUBLE_PREC it's pretty close.
However, I'm not sure that r_filtered = 33% is even correct.
The table contains 500 rows, and the only condition in the query returns 18 rows, so I don't see where 33% comes from. So, maybe the JSON estimation is actually good here, while both r_filtered and DOUBLE_PREC estimation are off. In this case please re-categorize as needed.
DROP TABLE IF EXISTS t;
CREATE TABLE t (a int ) ENGINE=MyISAM;
INSERT INTO t VALUES
( NULL ),(335086),(7),(1208746),( NULL ),(596640),( NULL ),(6),(63898),(5),
(632029),(6),(995492),( NULL ),(2),( NULL ),( NULL ),(433258),(3),( NULL ),(6),
( NULL ),(6),(3),( NULL ),( NULL ),(8),(5),(0),(2030240),(534970),(1775698),
(1564541),(9),(337969),(79757),( NULL ),(6),(8),(9),(1887175),(7),(81723),
( NULL ),( NULL ),(1409876),(777585),(1194263),( NULL ),(6),(0),(7),(710345),
( NULL ),( NULL ),(3),(1127285),( NULL ),( NULL ),(7),(912065),(0),( NULL ),
(1377174),( NULL ),( NULL ),(7),(1689387),(6),( NULL ),( NULL ),( NULL ),( NULL ),
(8),(1087570),(6),(327746),(4),( NULL ),(1163002),( NULL ),(4),(0),(1359282),
(2),(1497104),( NULL ),(1838481),(3),(4),( NULL ),(6),(8),(8),(1630339),
( NULL ),( NULL ),( NULL ),(4),(4),(6),(3),(1551892),(1174209),(3),(6),( NULL ),
(2),( NULL ),(1058603),(0),( NULL ),(2),( NULL ),(0),( NULL ),(1968636),( NULL ),
( NULL ),( NULL ),( NULL ),(2),(532677),(3),(904069),( NULL ),(2),( NULL ),
(1511260),( NULL ),( NULL ),(2139488),(3),(2),(1),( NULL ),( NULL ),( NULL ),
(2118975),(2),(1),(1),(6),(4915),(1),(1168900),(217252),(1178665),(4),
( NULL ),(5),(8),(1430716),(1198326),(545325),(6),(7),(952238),(4),( NULL ),
(413073),(158925),(2100036),( NULL ),( NULL ),( NULL ),(3),(1220084),(8),
( NULL ),(1508442),(1639973),( NULL ),(8),(1690108),(1135084),( NULL ),(6),
( NULL ),( NULL ),(1),(4),(1965883),( NULL ),(4),(5),(107545),( NULL ),( NULL ),
(9),(1667564),(7),(1),(8),(667222),( NULL ),( NULL ),(1598554),(1),(8),(6),
(6),( NULL ),(0),(2),( NULL ),(2),(1710817),( NULL ),(411435),(1),( NULL ),( NULL ),
( NULL ),(408158),(5),( NULL ),(3),( NULL ),(8),(5),(471728),( NULL ),( NULL ),
(802292),( NULL ),( NULL ),(7),(1561264),(7),( NULL ),(4),( NULL ),( NULL ),
(241762),( NULL ),(816972),(4),( NULL ),( NULL ),(1751908),(295502),( NULL ),
( NULL ),( NULL ),( NULL ),(1090191),( NULL ),(2),(838205),( NULL ),(9),( NULL ),
(1857946),( NULL ),(1776746),(291701),(311886),(205783),(1337655),(560529),
(83427),(953942),(0),(1951138),(1474822),(1637220),(3),(9),(0),(323748),
(4),(6),(10355),(3),(735904),(6),(3),(799343),( NULL ),( NULL ),(7),(1),
(475464),(1094517),(8),( NULL ),( NULL ),(5),(1479999),( NULL ),( NULL ),(42533),
(3),(2022048),(3),( NULL ),(7),( NULL ),( NULL ),(2030764),(2),(1335886),(8),
(2),(8),(1584726),(0),(1467154),(5),(5),(8),( NULL ),(3),(9),(1179517),
( NULL ),( NULL ),(866779),( NULL ),( NULL ),(2),(6),( NULL ),( NULL ),( NULL ),
(571277),( NULL ),( NULL ),(582025),(1679163),(6),(9),(3),(728826),(695927),
(1321533),(4),(4),( NULL ),(3),(3),(1265631),(1077477),(8),(1013187),
( NULL ),(0),(569377),(1410990),(996999),(240583),(474808),(0),( NULL ),
( NULL ),( NULL ),(2),(6),(686817),(844104),(67109),( NULL ),(9),( NULL ),( NULL ),
( NULL ),(9),( NULL ),( NULL ),(3),(144835),( NULL ),(6),( NULL ),( NULL ),(0),
( NULL ),( NULL ),(330695),(1056571),(3),( NULL ),(884539),( NULL ),(5),( NULL ),
(7),(6),( NULL ),(3),( NULL ),( NULL ),(5),(324731),( NULL ),(1852834),( NULL ),
(1159922),(9),( NULL ),(1),(132907),(558105),(7),(1793262),( NULL ),( NULL ),
(6),(509542),(3),(6),(7),(7),(4),(6),(1),( NULL ),(5),(1402733),(109052),
(8),( NULL ),(695992),(1210909),(570294),(6),(8),( NULL ),(2),(0),(7),
(724042),(818151),( NULL ),( NULL ),(1571750),(3),(350355),( NULL ),(764215),
(2114257),(9),( NULL ),(1256194),( NULL ),( NULL ),(363987),(9),(2),(7),( NULL ),
(1826095),(5),(1600127),(1829437),( NULL ),(2),(1417085),(6),(1468858),(3),
(8),(108724),(6),(8),(1801454),(2093482),(902234),(104530),(2145714),
( NULL ),(8),(9),(8),(7),( NULL ),(6),( NULL ),(1277100),(1),(4),( NULL ),( NULL ),
(4),(5),( NULL ),( NULL ),( NULL ),(96272),( NULL ),( NULL ),(4),( NULL ),(810025),
( NULL ),(1056244),(8),(982319),(3);
set histogram_type= DOUBLE_PREC_HB; analyze table t persistent for all ;
ANALYZE FORMAT=JSON SELECT a FROM t WHERE a = 7 ORDER BY a LIMIT 1;
set histogram_type= JSON_HB; analyze table t persistent for all ;
ANALYZE FORMAT=JSON SELECT a FROM t WHERE a = 7 ORDER BY a LIMIT 1;
# Cleanup
DROP TABLE t;
DOUBLE_PREC_HB preview-10.8-MDEV-26519-json-histograms 9a86900b
"table" : {
"table_name" : "t" ,
"access_type" : "ALL" ,
"r_loops" : 1,
"rows" : 500,
"r_rows" : 3,
"r_table_time_ms" : 0.004537902,
"r_other_time_ms" : 0.004708198,
"filtered" : 36.87187576,
"r_filtered" : 33.33333333,
"attached_condition" : "t.a = 7"
}
JSON_HB
"table" : {
"table_name" : "t" ,
"access_type" : "ALL" ,
"r_loops" : 1,
"rows" : 500,
"r_rows" : 3,
"r_table_time_ms" : 0.002915076,
"r_other_time_ms" : 0.003756541,
"filtered" : 3.599999905,
"r_filtered" : 33.33333333,
"attached_condition" : "t.a = 7"
}
Also reproducible with InnoDB and Aria.
relates to
MDEV-26519
JSON Histograms: improve histogram collection
Closed
{"report":{"fcp":1232,"ttfb":280.60000002384186,"pageVisibility":"visible","entityId":106745,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"3ee9e80a-580a-49c2-8a14-96c8b7043c89","navigationType":0,"readyForUser":1366.2000000476837,"redirectCount":0,"resourceLoadedEnd":1497.6000000238419,"resourceLoadedStart":285.89999997615814,"resourceTiming":[{"duration":279.10000002384186,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":285.89999997615814,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":285.89999997615814,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":565,"responseStart":0,"secureConnectionStart":0},{"duration":279.1999999284744,"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":286.2000000476837,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":286.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":565.3999999761581,"responseStart":0,"secureConnectionStart":0},{"duration":476.89999997615814,"initiatorType":"script","name":"https://jira.mariadb.org/s/fbf975c0cce4b1abf04784eeae9ba1f4-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":286.39999997615814,"connectEnd":286.39999997615814,"connectStart":286.39999997615814,"domainLookupEnd":286.39999997615814,"domainLookupStart":286.39999997615814,"fetchStart":286.39999997615814,"redirectEnd":0,"redirectStart":0,"requestStart":286.39999997615814,"responseEnd":763.2999999523163,"responseStart":763.2999999523163,"secureConnectionStart":286.39999997615814},{"duration":531.5,"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":286.5,"connectEnd":286.5,"connectStart":286.5,"domainLookupEnd":286.5,"domainLookupStart":286.5,"fetchStart":286.5,"redirectEnd":0,"redirectStart":0,"requestStart":286.5,"responseEnd":818,"responseStart":818,"secureConnectionStart":286.5},{"duration":535.1999999284744,"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":286.7000000476837,"connectEnd":286.7000000476837,"connectStart":286.7000000476837,"domainLookupEnd":286.7000000476837,"domainLookupStart":286.7000000476837,"fetchStart":286.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":286.7000000476837,"responseEnd":821.8999999761581,"responseStart":821.8999999761581,"secureConnectionStart":286.7000000476837},{"duration":535.3999999761581,"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":286.89999997615814,"connectEnd":286.89999997615814,"connectStart":286.89999997615814,"domainLookupEnd":286.89999997615814,"domainLookupStart":286.89999997615814,"fetchStart":286.89999997615814,"redirectEnd":0,"redirectStart":0,"requestStart":286.89999997615814,"responseEnd":822.2999999523163,"responseStart":822.2999999523163,"secureConnectionStart":286.89999997615814},{"duration":535.6000000238419,"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":287.10000002384186,"connectEnd":287.10000002384186,"connectStart":287.10000002384186,"domainLookupEnd":287.10000002384186,"domainLookupStart":287.10000002384186,"fetchStart":287.10000002384186,"redirectEnd":0,"redirectStart":0,"requestStart":287.10000002384186,"responseEnd":822.7000000476837,"responseStart":822.7000000476837,"secureConnectionStart":287.10000002384186},{"duration":620.8000000715256,"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":287.2999999523163,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":287.2999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":908.1000000238419,"responseStart":0,"secureConnectionStart":0},{"duration":535.8000000715256,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":287.39999997615814,"connectEnd":287.39999997615814,"connectStart":287.39999997615814,"domainLookupEnd":287.39999997615814,"domainLookupStart":287.39999997615814,"fetchStart":287.39999997615814,"redirectEnd":0,"redirectStart":0,"requestStart":287.39999997615814,"responseEnd":823.2000000476837,"responseStart":823.2000000476837,"secureConnectionStart":287.39999997615814},{"duration":620.7000000476837,"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":287.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":287.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":908.2000000476837,"responseStart":0,"secureConnectionStart":0},{"duration":536.0999999046326,"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":287.7000000476837,"connectEnd":287.7000000476837,"connectStart":287.7000000476837,"domainLookupEnd":287.7000000476837,"domainLookupStart":287.7000000476837,"fetchStart":287.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":287.7000000476837,"responseEnd":823.7999999523163,"responseStart":823.7999999523163,"secureConnectionStart":287.7000000476837},{"duration":859,"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":293.89999997615814,"connectEnd":293.89999997615814,"connectStart":293.89999997615814,"domainLookupEnd":293.89999997615814,"domainLookupStart":293.89999997615814,"fetchStart":293.89999997615814,"redirectEnd":0,"redirectStart":0,"requestStart":293.89999997615814,"responseEnd":1152.8999999761581,"responseStart":1152.8999999761581,"secureConnectionStart":293.89999997615814},{"duration":1170.1000000238419,"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":300.10000002384186,"connectEnd":300.10000002384186,"connectStart":300.10000002384186,"domainLookupEnd":300.10000002384186,"domainLookupStart":300.10000002384186,"fetchStart":300.10000002384186,"redirectEnd":0,"redirectStart":0,"requestStart":300.10000002384186,"responseEnd":1470.2000000476837,"responseStart":1470.2000000476837,"secureConnectionStart":300.10000002384186},{"duration":233.60000002384186,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":919.8999999761581,"connectEnd":919.8999999761581,"connectStart":919.8999999761581,"domainLookupEnd":919.8999999761581,"domainLookupStart":919.8999999761581,"fetchStart":919.8999999761581,"redirectEnd":0,"redirectStart":0,"requestStart":919.8999999761581,"responseEnd":1153.5,"responseStart":1153.5,"secureConnectionStart":919.8999999761581},{"duration":309.7000000476837,"initiatorType":"link","name":"https://jira.mariadb.org/s/d5715adaadd168a9002b108b2b039b50-CDN/lu2bu7/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","startTime":1183.7999999523163,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1183.7999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1493.5,"responseStart":0,"secureConnectionStart":0},{"duration":305.60000002384186,"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":1184.7999999523163,"connectEnd":1184.7999999523163,"connectStart":1184.7999999523163,"domainLookupEnd":1184.7999999523163,"domainLookupStart":1184.7999999523163,"fetchStart":1184.7999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":1184.7999999523163,"responseEnd":1490.3999999761581,"responseStart":1490.3999999761581,"secureConnectionStart":1184.7999999523163},{"duration":312.39999997615814,"initiatorType":"script","name":"https://jira.mariadb.org/s/f51ef5507eea4c158f257c66c93b2a3f-CDN/lu2bu7/820016/12ta74/be4b45e9cec53099498fa61c8b7acba4/_/download/contextbatch/js/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.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true","startTime":1185.2000000476837,"connectEnd":1185.2000000476837,"connectStart":1185.2000000476837,"domainLookupEnd":1185.2000000476837,"domainLookupStart":1185.2000000476837,"fetchStart":1185.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":1185.2000000476837,"responseEnd":1497.6000000238419,"responseStart":1497.6000000238419,"secureConnectionStart":1185.2000000476837},{"duration":398.60000002384186,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":1224.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1224.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1623.1000000238419,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":56,"responseStart":281,"responseEnd":300,"domLoading":284,"domInteractive":1551,"domContentLoadedEventStart":1551,"domContentLoadedEventEnd":1616,"domComplete":2296,"loadEventStart":2296,"loadEventEnd":2296,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1473.7000000476837},{"name":"bigPipe.sidebar-id.end","time":1474.6000000238419},{"name":"bigPipe.activity-panel-pipe-id.start","time":1474.7000000476837},{"name":"bigPipe.activity-panel-pipe-id.end","time":1477.6000000238419},{"name":"activityTabFullyLoaded","time":1637.2000000476837}],"measures":[],"correlationId":"d2b6764f99326e","effectiveType":"4g","downlink":9.4,"rtt":0,"serverDuration":104,"dbReadsTimeInMs":10,"dbConnsTimeInMs":17,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
The table contains 500 rows, BUT the query has
"WHERE a=7 ORDER BY a LIMIT 1"
The "WHERE a=7" part makes "ORDER BY a" no-op, so it becomes
"WHERE a=7 LIMIT 1"
That is, the execution will stop as soon as one matching row is found.
In this case, r_rows=3 so it has found a match after reading 3 rows.
This is confirmed by r_filtered=33.33333333 - one row out of 3 has matched the condition.