[MDEV-25231] A subquery stoped returning correct data after mariadb upgrade from 10.4.10 onwards Created: 2021-03-23  Updated: 2021-03-28

Status: Open
Project: MariaDB Server
Component/s: Optimizer, Server
Affects Version/s: 10.4.11, 10.4.12, 10.4.13, 10.4.14, 10.4.15, 10.4.16, 10.4.17, 10.4.18
Fix Version/s: 10.4

Type: Bug Priority: Major
Reporter: Anton Avramov Assignee: Sergei Petrunia
Resolution: Unresolved Votes: 0
Labels: optimizer, regression, server
Environment:

Ubuntu focal, Debian buster


Attachments: Text File msql-10.4.10.txt     Text File msql-10.4.11.txt     Text File msql-10.4.18.txt    

 Description   

We have a complex query that used to work fine and return correct data, but after upgrade from 10.4.10 onwards it NULL for column 2 and 3.

The query is:

SELECT SQL_CALC_FOUND_ROWS BA.ARTICLE_ID,AMOUNT_LAST_UPDATE,STORE_AMOUNT_ALL
  FROM b_articles BA
LEFT JOIN ( SELECT ARTICLE_ID,MAX(AMOUNT_LAST_UPDATE) AMOUNT_LAST_UPDATE,SUM(TBAV.AMOUNT) STORE_AMOUNT_ALL
                FROM b_availability TBAV
                WHERE TBAV.BARSY_ID IN (1,194,314,134,376,164,346,284,361,344,224,254,391)
               GROUP BY TBAV.ARTICLE_ID
            ) BAV USING (ARTICLE_ID)
WHERE
BA.PARENT_ID IS NULL 
AND BA.PICTURE IS NOT NULL 
AND BA.ARTICLE_ID IN ( SELECT DISTINCT ARTICLE_ID FROM b_article_cats ) 
AND BA.ARTICLE_ID IN ( SELECT DISTINCT IBA.ARTICLE_ID
                         FROM b_articles IBA
                        INNER JOIN b_availability IBAV USING (ARTICLE_ID)
                         LEFT JOIN (b_article_details IBAD  
                                   INNER JOIN b_article_detail_key_values IBADKV USING (DETAIL_ID) ) ON IBA.ARTICLE_ID = IBAD.ARTICLE_ID AND IBAD.KEY_ID = -1                                   
                         WHERE (IBADKV.DETAIL_VALUE IS NULL 
                               OR IBADKV.DETAIL_VALUE = "" 
                               OR IBA.LAST_UPDATE > IBADKV.DETAIL_VALUE 
                               OR IBAV.AMOUNT_LAST_UPDATE > IBADKV.DETAIL_VALUE
                              ) 
                          AND IBAV.BARSY_ID IN (1,194,314,134,376,164,346,284,361,344,224,254,391)
                      )

Using mariadb 10.4.10 binary the query would return something like:
173984 2018-11-01 13:10:25 0.000000000
174044 2018-11-01 13:10:25 0.000000000
.....
But if I upgrade the package it start returning:
173984 NULL NULL
174044 NULL NULL
....

I cannot provide recreation steps since the data is private, but I'm attaching the result from running ANALYZE on the query.
the result from 10.4.11 and 10.4.18 are identical, but I'm attaching both of them for completenes



 Comments   
Comment by Anton Avramov [ 2021-03-23 ]

Another interesing obervation.
If I comment/remove this row: AND BA.ARTICLE_ID IN ( SELECT DISTINCT ARTICLE_ID FROM b_article_cats )
the query starts working again.
It is interesing because those are filters on the result set and should only effect the number of rows returned. But it seams they influence on the subquery that is geting the max date and sum.

Generated at Thu Feb 08 09:36:08 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.