[Bug] ORCA: QD segfault in CExtendedStatsProcessor when extended statistics (dependencies) do not cover all filtered columns
Maintainer thường phản hồi trong vòng 3 ngày
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 74/100
Hướng nghiên cứu
Tái hiện ví dụ SQL với ORCA được bật, sau đó đọc libnaucrates/src/statistics/CExtendedStatsProcessor.cpp quanh CExtendedStatsProcessor::ApplyCorrelatedStatsToScaleFactorFilterCalculation, lần theo các hàm gọi qua CFilterStatsProcessor::MakeHistHashMapConjFilter và CLogicalSelect::PstatsDerive. Được xem là hoàn tất khi trường hợp thống kê mở rộng được bao phủ một phần không còn dereference ánh xạ cột bị thiếu, backend không bị segfault và truy vấn trả về 0 hàng.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Apache Cloudberry version
main branch (recent build)
What happened
With ORCA enabled, the backend crashes when a query filters on a set of columns that is only partially covered by an extended statistics object (CREATE STATISTICS ... (dependencies)). In the reproducer below the statistics object covers c0, c1 and the outer WHERE also references c2, which is not covered.
The crash is a null-pointer dereference in the QD backend inside ORCA's statistics derivation:
CExtendedStatsProcessor::ApplyCorrelatedStatsToScaleFactorFilterCalculation
(libnaucrates/src/statistics/CExtendedStatsProcessor.cpp, ~line 366)
<- CFilterStatsProcessor::MakeHistHashMapConjFilter
<- CLogicalSelect::PstatsDerive
colid_to_attno_mapping->Find(&colid) returns nullptr for the column that is not part of the statistics object, and the result is dereferenced without a check.
With optimizer = off the query runs fine and returns 0 rows.
Found by SQLancer.
What you think should happen instead
The query should run and return 0 rows (no row has c1 = ''). Cardinality estimation must not assume every filtered column is present in the extended statistics object.
How to reproduce
CREATE TABLE t3 (c0 boolean, c1 text, c2 int) DISTRIBUTED BY (c0);
INSERT INTO t3 SELECT (g%2=0), 'x'||g, g FROM generate_series(1,100) g;
CREATE STATISTICS s0 (dependencies) ON c0, c1 FROM t3; -- covers c0, c1 only
ANALYZE t3;
SET optimizer = on;
SELECT * FROM (SELECT ALL t3.c0 AS t3c0, t3.c1 AS t3c1, t3.c2 AS t3c2
FROM t3
WHERE (t3.c0) IS TRUE
GROUP BY t3.c0, t3.c1, t3.c2
ORDER BY t3.c1) AS result
WHERE result.t3c0 = TRUE AND result.t3c1 = '' AND result.t3c2 > 0; -- c2 not covered by s0
-- QD backend SIGSEGV
Operating System
Linux
Anything else
Found while running SQLancer against Cloudberry main (3-segment demo cluster, --enable-cassert). See the proposal to run SQLancer continuously: https://github.com/apache/cloudberry/discussions/1952
Are you willing to submit PR?
- Yes, I am willing to submit a PR!
Code of Conduct
- I agree to follow this project's Code of Conduct
- Ngôn ngữ chính
- C
- Star
- 1.4k
- Fork
- 260
- Merge trung bình
- 4 ngày 52 phút
- Pull request đã merge (30 ngày)
- 51
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 apache/cloudberry
-
[Bug] Expand fails to recognize user-defined tablespacesCó thể đã có người làm @nix-oss đã nhận 56 ngày trước. Đang mởtype: Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
apache/cloudberry#1885 · 2 reaction ·
Maintainer thường phản hồi trong vòng 3 ngày
-
gpexpand first stage fails: 'SyncPackages' object has no attribute 'ret' (extension sync never runs; regression)Có thể đã có người làm @talmacschen-arch đã nhận 117 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
apache/cloudberry#1825 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
[Issues] When Initializing a new Cloudberry cluster we are encountering issuesCó thể đã có người làm @yjhjstz đã nhận 1 ngày trước. Đang mởtype: Bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 12/100
apache/cloudberry#2101 · 7 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 12/100
apache/cloudberry#2097 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
-
type: Bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 22/100
apache/cloudberry#2091 ·
Maintainer thường phản hồi trong vòng 3 ngày
Tất cả issue của apache/cloudberry
Issue tương tự
-
chore: update release scheduleĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 4 ngày
-
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
-
enhancement help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
kabirvashisht4-glitch/Vet#22 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100