Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-36348

Query Optimization for Counting Foreign Key Records Not Found in Parent Key even after adding indexes

Details

    • Task
    • Status: Closed (View Workflow)
    • Minor
    • Resolution: Not a Bug
    • N/A
    • Optimizer
    • None

    Description

      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

      Attachments

        Issue Links

          Activity

            marko Marko Mäkelä added a comment -

            This could be easier to implement, once MDEV-22361 has been implemented.

            marko Marko Mäkelä added a comment - This could be easier to implement, once MDEV-22361 has been implemented.
            serg 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

            serg 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 Unassigned
              baludbr Balaji Reddy Dwarampudi
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start 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.