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

Wrong result returned when using NOT LIKE combined with IS NOT TRUE in HAVING clause

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Minor
    • Resolution: Unresolved
    • 12.1.2
    • 10.11, 11.4, 11.8, 12.3
    • Optimizer
    • None
    • Server version: 12.1.2-MariaDB-ubu2404 mariadb.org binary distribution

    Description

      I have encountered a logic error where the HAVING clause fails to filter rows correctly. A query involving COUNT(), NOT LIKE, and IS NOT TRUE returns 3 rows, whereas it is expected to return an empty set.

      Evaluating the exact same expression in the SELECT list shows that the condition evaluates to 0 (FALSE) for all groups, yet the HAVING clause allows these groups to pass through.

      How to repeat:

      -- 1. Create table and insert data
      CREATE TABLE t1(c1 NUMERIC);
      INSERT INTO t1(c1) VALUES (54559273),(-70416),(-9762545),(1),(1);
       
      -- 2. Execute the problematic query
      SELECT MAX(ca2) 
      FROM (SELECT c1 AS ca1, c1 AS ca2 FROM t1) AS ta1 
      GROUP BY ca1 
      HAVING (COUNT(ca2) NOT LIKE (ca1)) IS NOT TRUE;
      +----------+
      | MAX(ca2) |
      +----------+
      | -9762545 |
      |   -70416 |
      | 54559273 |
      +----------+
      3 rows in set
      

      Analysis & Evidence: The HAVING condition is (COUNT(ca2) NOT LIKE (ca1)) IS NOT TRUE

      SELECT 
        ca1, 
        COUNT(ca2), 
        ((COUNT(ca2) NOT LIKE (ca1)) IS NOT TRUE) AS condition_result
      FROM (SELECT c1 AS ca1, c1 AS ca2 FROM t1) AS ta1 
      GROUP BY ca1;
      +----------+------------+------------------+
      | ca1      | COUNT(ca2) | condition_result |
      +----------+------------+------------------+
      | -9762545 |          1 |                0 |
      |   -70416 |          1 |                0 |
      |        1 |          2 |                0 |
      | 54559273 |          1 |                0 |
      +----------+------------+------------------+
      

      Attachments

        Activity

          People

            psergei Sergei Petrunia
            March SerenMarch
            Votes:
            0 Vote for this issue
            Watchers:
            2 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.