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

Slow query log has Rows_examined: 0 for UNION ALL queries

Details

    Description

      Put this in my.cnf:

      slow-query-log
      long-query-time=0.00001
      log-slow-verbosity=full
      

      Then run

      create table t21(a int, b int);
      insert into t21 select seq, seq from seq_1_to_10000;
      select sum(a) from t21 
      union all
      select sum(b) from t21;
      

      Look into the slow query log. It shows something like:

      # Time: 241106 16:05:31
      # User@Host: root[root] @ localhost []
      # Thread_id: 3  Schema: j1  QC_hit: No
      # Query_time: 0.140179  Lock_time: 0.000414  Rows_sent: 2  Rows_examined: 0
      # Rows_affected: 0  Bytes_sent: 81
      # Pages_accessed: 48  Pages_read: 0  Pages_prefetched: 0  Pages_updated: 0  Old_rows_read: 0
      # Pages_read_time: 0.0000  Engine_time: 123.8240
      # Full_scan: Yes  Full_join: No  Tmp_table: No  Tmp_table_on_disk: No
      # Filesort: No  Filesort_on_disk: No  Merge_passes: 0  Priority_queue: No
      #
      # explain: id   select_type     table   type    possible_keys   key     key_len ref     rows    r_rows  filtered        r_filtered      Extra
      # explain: 1    PRIMARY t21     ALL     NULL    NULL    NULL    NULL    10157   10000.00        100.00  100.00
      # explain: 2    UNION   t21     ALL     NULL    NULL    NULL    NULL    10157   10000.00        100.00  100.00
      #
      SET timestamp=1730901931;
      select sum(a) from t21
      union all
      select sum(b) from t21;
      

      Note the Rows_examined: 0.

      For comparison, if one uses UNION instead of UNION ALL:

      select sum(a) from t21 
      union
      select sum(b) from t21;
      

      it shows Rows_examined: 20001 which is the real number:

      # Time: 241106 16:04:59
      # User@Host: root[root] @ localhost []
      # Thread_id: 3  Schema: j1  QC_hit: No
      # Query_time: 0.129300  Lock_time: 0.000127  Rows_sent: 1  Rows_examined: 20001
      # Rows_affected: 0  Bytes_sent: 74
      # Pages_accessed: 48  Pages_read: 0  Pages_prefetched: 0  Pages_updated: 0  Old_rows_read: 0
      # Pages_read_time: 0.0000  Engine_time: 114.1540
      # Tmp_tables: 1  Tmp_disk_tables: 0  Tmp_table_sizes: 126984
      # Full_scan: Yes  Full_join: No  Tmp_table: Yes  Tmp_table_on_disk: No
      # Filesort: No  Filesort_on_disk: No  Merge_passes: 0  Priority_queue: No
      #
      # explain: id   select_type     table   type    possible_keys   key     key_len ref     rows    r_rows  filtered        r_filtered      Extra
      # explain: 1    PRIMARY t21     ALL     NULL    NULL    NULL    NULL    10000   10000.00        100.00  100.00
      # explain: 2    UNION   t21     ALL     NULL    NULL    NULL    NULL    10000   10000.00        100.00  100.00
      # explain: NULL UNION RESULT    <union1,2>      ALL     NULL    NULL    NULL    NULL    NULL    1.00    NULL    NULL
      #
      SET timestamp=1730901899;
      select sum(a) from t21
      union
      select sum(b) from t21;
      

      Attachments

        Activity

          There are no comments yet on this issue.

          People

            Johnston Rex Johnston
            psergei Sergei Petrunia
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

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