Bug Report: Issues with IF function

オープン
#19,475 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
25/100
issue の種類
バグ
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
sql
領域
databases

調査の方向性

まず、添付された tidb/tpcd.sql のデータを読み込み、TiDB 8.3.0 に対して両方の SQL クエリを実行し、結果セットと IF/IN 式の動作を比較します。論理的に同値なクエリで結果が異なる理由を特定し、修正後に同じケースで一貫した結果が得られることを確認できれば完了です。

索引モデルが issue の本文から書いたものです。

説明

BugReport: Issues with IF function

version

8.3.0

Original sql

SELECT 
    O_CUSTKEY 
FROM 
    orders
WHERE 
    (
        O_COMMENT   IN (
            IF(
                -1801656545 IS NOT NULL, 
                -1801656545, 

            )
        )
    ) = 0.24036834733741486
GROUP BY 
    O_CUSTKEY ;

return 0 row

Rewritten sql

SELECT  O_CUSTKEY 
FROM orders
WHERE NOT EXISTS (
    SELECT 1
    WHERE O_COMMENT <> -1801656545 OR O_COMMENT IS NULL
) = 0.24036834733741486
GROUP BY  O_CUSTKEY ;

return 101 row

Analysis

These two queries are logically equivalent, although they are written differently.

Original Query: The original query uses the IF function to check if -1801656545 is not NULL. If it is not NULL, it returns -1801656545; otherwise, it would return NULL (though in this specific query, -1801656545 is never NULL). It then uses IN to check if O_COMMENT matches the returned value and compares the result with 0.24036834733741486 to filter rows.

Rewritten Query: In the rewritten query, the NOT EXISTS subquery is used to check if O_COMMENT is not equal to -1801656545 or is NULL, which is logically equivalent to the IN check in the original query. The final result of the NOT EXISTS subquery is then compared with 0.24036834733741486 to filter the rows.

The two SQL queries are logically equivalent, but they return different results, indicating the presence of a bug.

How to repeat

The exported file for the database is in the attachment. : (https://github.com/LLuopeiqi/newtpcd/blob/main/tidb/tpcd.sql) .

主要言語
Python
スター
616
フォーク
724
平均マージ
2日 5時間
マージ済み PR(30日)
168

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

pingcap/docs のほかの issue

pingcap/docs の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。