Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

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

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

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
74/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
cpp, sql
領域
backend, databases

調査の方向性

ORCA を有効にして SQL の例を再現し、その後 libnaucrates/src/statistics/CExtendedStatsProcessor.cpp の CExtendedStatsProcessor::ApplyCorrelatedStatsToScaleFactorFilterCalculation 付近を読み、CFilterStatsProcessor::MakeHistHashMapConjFilter と CLogicalSelect::PstatsDerive を経由して呼び出し元をたどる。部分的にしかカバーされていない拡張統計のケースで存在しない列マッピングをデリファレンスしなくなり、バックエンドが segfault せず、クエリが 0 行を返せば完了とする。

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

説明

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
主要言語
C
スター
1.4k
フォーク
248
平均マージ
4日 10時間
マージ済み PR(30日)
40

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

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

apache/cloudberry のほかの issue

apache/cloudberry の issue をすべて見る

似ている issue

C の issue をもっと見る

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

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