Bug Report
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 30/100
Hướng nghiên cứu
Bắt đầu bằng cách tải tập dữ liệu tidb/tpcd.sql đính kèm và tái hiện cả hai truy vấn trên TiDB 8.3.0, đồng thời so sánh kết quả và hành vi thực thi của chúng. Kiểm tra thứ tự GROUP BY, các phép ép kiểu và l_receiptdate bị bỏ qua được mô tả trong báo cáo. Công việc được xem là hoàn tất khi có lời giải thích đã được xác nhận về sự khác biệt và một hướng giải quyết được ghi chép.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
BUG Report
TiDB 8.3.0
Original Query
SELECT ALL l_extendedprice, l_orderkey, l_discount
FROM lineitem
WHERE (coalesce(l_quantity, l_suppkey, 0.21501538554113775, l_receiptdate)) <= l_returnflag
GROUP BY l_extendedprice, l_orderkey, l_discount;
Return: 6005 rows
Rewritten Query
SELECT l_extendedprice, l_orderkey, l_discount
FROM lineitem
WHERE CASE
WHEN l_quantity IS NOT NULL THEN CAST(l_quantity AS decimal(15,2))
WHEN l_suppkey IS NOT NULL THEN CAST(l_suppkey AS unsigned)
ELSE 0.21501538554113775
END <= l_returnflag
GROUP BY l_orderkey, l_extendedprice, l_discount
Return: 0 rows
Analysis
1. Logical Equivalence of the Queries
The original and rewritten queries are intended to be semantically equivalent:
- Both select
l_extendedprice,l_orderkey, andl_discountfrom thelineitemtable. - Both filter rows by comparing the first non-NULL value among
l_quantity,l_suppkey,0.21501538554113775, andl_receiptdatetol_returnflag.
- Original Query (using COALESCE):
SELECT ALL l_extendedprice, l_orderkey, l_discount
FROM lineitem
WHERE (coalesce(l_quantity, l_suppkey, 0.21501538554113775, l_receiptdate)) <= l_returnflag
GROUP BY l_extendedprice, l_orderkey, l_discount;
- Rewritten Query (using CASE):
SELECT l_extendedprice, l_orderkey, l_discount
FROM lineitem
WHERE CASE
WHEN l_quantity IS NOT NULL THEN CAST(l_quantity AS decimal(15,2))
WHEN l_suppkey IS NOT NULL THEN CAST(l_suppkey AS unsigned)
ELSE 0.21501538554113775
END <= l_returnflag
GROUP BY l_orderkey, l_extendedprice, l_discount
Expected Behavior
Logically, these two queries should produce the same result set for all rows, as the rewritten query mimics the logic of COALESCE with CASE WHEN.
2. Bug Manifestation
- Original Query result:
6005 rows - Rewritten Query result:
0 rows
This large discrepancy indicates that the semantic equivalence between the queries does not hold in TiDB 8.3.0 for this case.
3. Potential Cause
-
Column Order in GROUP BY:
The original query usesGROUP BY l_extendedprice, l_orderkey, l_discount, whereas the rewritten query usesGROUP BY l_orderkey, l_extendedprice, l_discount.
While standard SQL considers group column order insignificant, some engines may produce different plans if the order is changed. -
Type Casting Differences:
COALESCEreturns the first non-NULL value as is, maintaining its type.- The rewritten
CASEcastsl_quantitytodecimal(15,2)andl_suppkeytounsigned.
If the types differ from those in the original, it may change comparison logic or evaluation, causing filter mismatches.
-
Implicit vs Explicit Null Handling:
COALESCEandCASEshould be functionally similar, but differences in how TiDB handles type conversions and nullability can result in different evaluation orders or filter results.
-
Edge Case: l_receiptdate Ignored in Rewritten Query:
- In the rewritten query,
l_receiptdateis omitted, whereas it is the last fallback in theCOALESCE. This means when all other columns are NULL, the rewritten query will not usel_receiptdate, while the original will.
- In the rewritten query,
How to repeat ?
The exported file for the database is in the attachment. : (https://github.com/LLuopeiqi/newtpcd/blob/main/tidb/tpcd.sql) .
- Ngôn ngữ chính
- Python
- Star
- 616
- Fork
- 724
- Merge trung bình
- 2 ngày 5 giờ
- Pull request đã merge (30 ngày)
- 168
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của pingcap/docs
-
Weekly keywords check: mismatches foundCó thể đã có người làm @saryn17 đã nhận 57 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Broken Link DetectedĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Weekly keywords check: mismatches foundCó thể đã có người làm @saryn17 đã nhận 57 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Broken Link DetectedĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
Maintainer thường phản hồi trong vòng 1 ngày
-
tidb-cloud: Terraform import procedures need Terraform v1.5.0 or later, but the prerequisite says >=1.0Có thể đã có người làm @yahonda đã nhận 5 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
Maintainer thường phản hồi trong vòng 1 ngày
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Install the skills as a Claude Code pluginCó thể đã có người làm @ruban-24 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 6 ngày
-
Make the usage of time-zone aware UTC timestamps the norm across the pynxtools NOMAD ecosystemĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
FAIRmat-NFDI/pynxtools#874 ·
-
Eval: PublicationĐang mởdata
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100