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

Wrong result (missing row) with LIMIT 1 on INFORMATION_SCHEMA.TABLES

    XMLWordPrintable

Details

    • Not for Release Notes

    Description

      LIMIT 1 incorrectly stops the scan after examining the first table (tb3), regardless of whether a matching row is found based on the WHERE condition, thus returning an empty result for tb1/tb2.

      CREATE DATABASE db1;
      CREATE TABLE db1.tb1(a INT);
      CREATE TABLE db1.tb2(a INT);
      CREATE TABLE db1.tb3(a INT);
       
      SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='db1';
      +------------+
      | tb3        |     <- scan order, not sorted
      | tb2        |
      | tb1        |
      +------------+
       
      SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='db1' AND (TABLE_NAME='tb1' OR TABLE_CATALOG='nope');
      +------------+
      | tb1        |
      +------------+
       
      SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='db1' AND (TABLE_NAME='tb1' OR TABLE_CATALOG='nope') LIMIT 1;
      Empty set
      

      CLI Output

      13.1.0-opt>CREATE DATABASE db1;
      Query OK, 1 row affected (0.000 sec)
       
      13.1.0-opt>CREATE TABLE db1.tb1(a INT);
      Query OK, 0 rows affected (0.008 sec)
       
      13.1.0-opt>CREATE TABLE db1.tb2(a INT);
      Query OK, 0 rows affected (0.006 sec)
       
      13.1.0-opt>CREATE TABLE db1.tb3(a INT);
      Query OK, 0 rows affected (0.007 sec)
       
      13.1.0-opt>SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='db1' AND (TABLE_NAME='tb1' OR TABLE_CATALOG='nope') LIMIT 1;
      Empty set (0.000 sec)
       
      13.1.0-opt>SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='db1' AND (TABLE_NAME='tb2' OR TABLE_CATALOG='nope') LIMIT 1;
      Empty set (0.000 sec)
       
      13.1.0-opt>SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='db1' AND (TABLE_NAME='tb3' OR TABLE_CATALOG='nope') LIMIT 1;
      +------------+
      | TABLE_NAME |
      +------------+
      | tb3        |
      +------------+
      1 row in set (0.000 sec)
       
      13.1.0-opt>
      

      Attachments

        Issue Links

          Activity

            People

              janlindstrom Jan Lindström
              ramesh Ramesh Sivaraman
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:

                Time Tracking

                  Estimated:
                  Original Estimate - 0d
                  0d
                  Remaining:
                  Remaining Estimate - 0d
                  0d
                  Logged:
                  Time Spent - 50m
                  50m

                  Git Integration

                    Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.