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

LP:905353 - Wrong non-empty result with a constant table, aggregate function in subquery, MyISAM or Aria

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Not a Bug
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:

      Description

      The following query

      SELECT a FROM t1 WHERE ( SELECT MIN(a) = 100 );

      if executed on a table with a single row, returns the row regardless the condition in WHERE – it can be = <any number>, or IS NULL, or IS NOT NULL, – and with any of MIN/MAX/COUNT/SUM/AVG.

      bzr version-info
      revision-id: <email address hidden>
      date: 2011-12-16 10:21:46 +0400
      build-date: 2011-12-16 16:38:19 +0200
      revno: 3356
      branch-nick: maria-5.3

      Also reproducible on revno 3250.

      Not reproducible on 5.3.2, 5.2.10, MySQL 5.1.60.

      Reproducible on MyISAM and Aria tables, but not on InnoDB.

      Either in_to_exists or materialization is required, otherwise the query fails with ER_ILLEGAL_SUBQUERY_OPTIMIZER_SWITCHES. Reproducible with either of these, also if everything else is OFF.

      EXPLAIN:

      1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00
      2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used

      1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
      1003 select 1 AS `a` from `test`.`t1` where (select (min(1) = 100))

      Minimal optimizer_switch: in_to_exists=on or materialization=on (otherwise the query refuses to execute)

      Full optimizer_switch: index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on

      Test case:

      1. The table needs to be MyISAM or Aria
        CREATE TABLE t1 ( a INT ) ENGINE=MyISAM;
        INSERT INTO t1 VALUES (1);

      SELECT a FROM t1 WHERE ( SELECT MIN(a) = 100 );

      1. Expected result:
      2. a
        #
      3. Actual result:
      4. a
      5. 1

        Gliffy Diagrams

          Attachments

            Activity

            Hide
            timour Timour Katchaounov added a comment -

            Re: Wrong non-empty result with a constant table, aggregate function in subquery, MyISAM or Aria
            Fixed by the following commit:

            revno: 3380
            committer: sanja@montyprogram.com
            branch nick: work-maria-5.3-lpb908269
            timestamp: Tue 2012-01-10 23:26:00 +0200
            message:
            Fix for LP BUG#908269 Wrong result with subquery in select list, EXISTS, constant MyISAM/Aria table.

            Problem: When building the condition for JOIN::outer_ref_cond the optimizer forgot to take into account
            that this condition could depend on constant tables as well.

            Show
            timour Timour Katchaounov added a comment - Re: Wrong non-empty result with a constant table, aggregate function in subquery, MyISAM or Aria Fixed by the following commit: revno: 3380 committer: sanja@montyprogram.com branch nick: work-maria-5.3-lpb908269 timestamp: Tue 2012-01-10 23:26:00 +0200 message: Fix for LP BUG#908269 Wrong result with subquery in select list, EXISTS, constant MyISAM/Aria table. Problem: When building the condition for JOIN::outer_ref_cond the optimizer forgot to take into account that this condition could depend on constant tables as well.
            Hide
            ratzpo Rasmus Johansson added a comment -

            Launchpad bug id: 905353

            Show
            ratzpo Rasmus Johansson added a comment - Launchpad bug id: 905353

              People

              • Assignee:
                timour Timour Katchaounov
                Reporter:
                elenst Elena Stepanova
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: