Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta
#1,949 0 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
74/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
cpp, sql
Ambito
backend, databases

Direzione di ricerca

Riproduci l’esempio SQL con ORCA abilitato e poi leggi libnaucrates/src/statistics/CExtendedStatsProcessor.cpp intorno a CExtendedStatsProcessor::ApplyCorrelatedStatsToScaleFactorFilterCalculation, seguendo i chiamanti attraverso CFilterStatsProcessor::MakeHistHashMapConjFilter e CLogicalSelect::PstatsDerive. Il lavoro è completato quando il caso di statistiche estese parzialmente coperto non dereferenzia più una mappatura di colonna mancante, il backend non va in segfault e la query restituisce 0 righe.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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
Lingua principale
C
Stelle
1.4k
Fork
248
Merge medio
4g 10h
PR unite (30g)
40

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di apache/cloudberry

Tutte le issue di apache/cloudberry

Issue simili

Altre issue su C

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.