We are facing performance issues when trying to count the number of records in the foreign key column that don’t have a corresponding value in the parent table’s primary key. While we already have the total row count, the query still takes too long to run, especially with large datasets.
What We’ve Tried:
NOT EXISTS Query: We tried using a NOT EXISTS query, but it still took too long to execute.
LEFT JOIN Query: We also tried using a LEFT JOIN with a NULL check on the parent table, but the performance was still suboptimal.
What We Need:
We need a more efficient approach to count the records where the foreign key exists in the child table but doesn’t have a corresponding primary key in the parent table. The current methods are still taking longer than expected with larger datasets(Indexes already implemented).
We would appreciate suggestions on how to optimize this query further. Whether it’s through other query techniques, we are open to solutions that can improve speed
Sergei Golubchik
added a comment - Sorry, but this is not a support forum. See https://mariadb.org/contribute/ for a various ways of asking MariaDB related questions. For example, you can use Zulip or our mailing list
People
Unassigned
Balaji Reddy Dwarampudi
Votes:
0Vote for this issue
Watchers:
3Start 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":883.5,"ttfb":240.40000009536743,"pageVisibility":"visible","entityId":133424,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":1,"journeyId":"01c033ef-3796-48db-b5bd-7b563d1581d0","navigationType":0,"readyForUser":955.6999998092651,"redirectCount":0,"resourceLoadedEnd":674.2999997138977,"resourceLoadedStart":248.90000009536743,"resourceTiming":[{"duration":32.69999980926514,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":248.90000009536743,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":248.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":281.59999990463257,"responseStart":0,"secureConnectionStart":0},{"duration":32.299999713897705,"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":249.90000009536743,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":249.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":282.19999980926514,"responseStart":0,"secureConnectionStart":0},{"duration":136.59999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":250.09999990463257,"connectEnd":250.09999990463257,"connectStart":250.09999990463257,"domainLookupEnd":250.09999990463257,"domainLookupStart":250.09999990463257,"fetchStart":250.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":287.59999990463257,"responseEnd":386.69999980926514,"responseStart":312,"secureConnectionStart":250.09999990463257},{"duration":193.39999961853027,"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":250.40000009536743,"connectEnd":250.40000009536743,"connectStart":250.40000009536743,"domainLookupEnd":250.40000009536743,"domainLookupStart":250.40000009536743,"fetchStart":250.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":287.90000009536743,"responseEnd":443.7999997138977,"responseStart":309.7999997138977,"secureConnectionStart":250.40000009536743},{"duration":66.19999980926514,"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":250.90000009536743,"connectEnd":250.90000009536743,"connectStart":250.90000009536743,"domainLookupEnd":250.90000009536743,"domainLookupStart":250.90000009536743,"fetchStart":250.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":288.59999990463257,"responseEnd":317.09999990463257,"responseStart":314.40000009536743,"secureConnectionStart":250.90000009536743},{"duration":67.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":251,"connectEnd":251,"connectStart":251,"domainLookupEnd":251,"domainLookupStart":251,"fetchStart":251,"redirectEnd":0,"redirectStart":0,"requestStart":290.19999980926514,"responseEnd":318.90000009536743,"responseStart":317.5,"secureConnectionStart":251},{"duration":70.40000009536743,"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":251.2999997138977,"connectEnd":251.2999997138977,"connectStart":251.2999997138977,"domainLookupEnd":251.2999997138977,"domainLookupStart":251.2999997138977,"fetchStart":251.2999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":290.2999997138977,"responseEnd":321.69999980926514,"responseStart":320.5,"secureConnectionStart":251.2999997138977},{"duration":37.80000019073486,"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":251.7999997138977,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":251.7999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":289.59999990463257,"responseStart":0,"secureConnectionStart":0},{"duration":68.40000009536743,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":252,"connectEnd":252,"connectStart":252,"domainLookupEnd":252,"domainLookupStart":252,"fetchStart":252,"redirectEnd":0,"redirectStart":0,"requestStart":292,"responseEnd":320.40000009536743,"responseStart":318.90000009536743,"secureConnectionStart":252},{"duration":39.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":252.2999997138977,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":252.2999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":291.7999997138977,"responseStart":0,"secureConnectionStart":0},{"duration":78.09999990463257,"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":252.69999980926514,"connectEnd":303.5,"connectStart":303.5,"domainLookupEnd":303.5,"domainLookupStart":303.5,"fetchStart":252.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":306.19999980926514,"responseEnd":330.7999997138977,"responseStart":325.5,"secureConnectionStart":303.5},{"duration":403.69999980926514,"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":265.5,"connectEnd":265.5,"connectStart":265.5,"domainLookupEnd":265.5,"domainLookupStart":265.5,"fetchStart":265.5,"redirectEnd":0,"redirectStart":0,"requestStart":462.09999990463257,"responseEnd":669.1999998092651,"responseStart":664.0999999046326,"secureConnectionStart":265.5},{"duration":408.7999997138977,"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":265.5,"connectEnd":265.5,"connectStart":265.5,"domainLookupEnd":265.5,"domainLookupStart":265.5,"fetchStart":265.5,"redirectEnd":0,"redirectStart":0,"requestStart":462.2999997138977,"responseEnd":674.2999997138977,"responseStart":665.5,"secureConnectionStart":265.5},{"duration":222.59999990463257,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":605.0999999046326,"connectEnd":605.0999999046326,"connectStart":605.0999999046326,"domainLookupEnd":605.0999999046326,"domainLookupStart":605.0999999046326,"fetchStart":605.0999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":789.6999998092651,"responseEnd":827.6999998092651,"responseStart":826.6999998092651,"secureConnectionStart":605.0999999046326}],"fetchStart":0,"domainLookupStart":39,"domainLookupEnd":60,"connectStart":60,"connectEnd":83,"secureConnectionStart":70,"requestStart":83,"responseStart":241,"responseEnd":263,"domLoading":245,"domInteractive":1019,"domContentLoadedEventStart":1019,"domContentLoadedEventEnd":1056,"domComplete":1737,"loadEventStart":1737,"loadEventEnd":1738,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":998.7999997138977},{"name":"bigPipe.sidebar-id.end","time":999.7999997138977},{"name":"bigPipe.activity-panel-pipe-id.start","time":999.9000000953674},{"name":"bigPipe.activity-panel-pipe-id.end","time":1001},{"name":"activityTabFullyLoaded","time":1081.2999997138977}],"measures":[],"correlationId":"aa93997e76e739","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":100,"dbReadsTimeInMs":14,"dbConnsTimeInMs":23,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
This could be easier to implement, once MDEV-22361 has been implemented.