Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

[Bug] ORCA: QD segfault in CExtendedStatsProcessor when extended statistics (dependencies) do not cover all filtered columns

Đang mở
#1,949 0 bình luận 1 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 3 ngày

@yjhjstz đang làm issue này rồi.

Từ ngày 7/9/2026.

  • #1966 của @yjhjstz — đang mở

Đá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
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
cpp, sql
Lĩnh vực
backend, databases

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ả

type: Bug type: Orca
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
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

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của apache/cloudberry

Tất cả issue của apache/cloudberry

Issue tương tự

Thêm issue về C

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.