[fix](statistics) Quote identifiers in statistics queries - #67703
Open
morrySnow wants to merge 2 commits into
Open
[fix](statistics) Quote identifiers in statistics queries#67703morrySnow wants to merge 2 commits into
morrySnow wants to merge 2 commits into
Conversation
Contributor
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
Contributor
Author
|
run buildall |
Contributor
FE Regression Coverage ReportIncrement line coverage |
Contributor
TPC-H: Total hot run time: 17144 ms |
Contributor
TPC-DS: Total hot run time: 82534 ms |
Contributor
ClickBench: Total hot run time: 14.72 s |
Contributor
Author
|
run buildall |
Problem Summary: Statistics collection SQL placed object names inside template-owned backticks without escaping embedded backticks. Because these statements run with an elevated internal identity, a crafted object name could alter the generated query and expose data outside the caller's privileges. Solution: Generate complete quoted identifier fragments with SqlUtils.getIdentSql for catalogs, databases, tables, columns, indexes, and partitions across OLAP, external, plugin-sample, and histogram analysis paths. Escape identifier-derived values separately when stored as string literals, and add coverage for embedded backticks and apostrophes. Issue Number: None
Issue Number: None Keep the statistics task test fixtures and template expectations consistent with pre-quoted identifier substitutions.
morrySnow
force-pushed
the
fix/quote-statistics-identifiers
branch
from
September 10, 2026 06:42
2ebe95d to
7376cde
Compare
Contributor
Author
|
run buildall |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Statistics collection builds internal SQL from catalog, database, table, index, partition, and column names. Names containing an embedded backtick could terminate a template-owned quoted identifier. Since statistics statements execute through an internal privileged context, the remaining name text could be interpreted as SQL and access objects unavailable to the initiating user.
Root cause
The SQL templates owned the surrounding backticks while callers substituted raw names, or only partially escaped selected column names. This split ownership was inconsistent across full, sampled, partition, external-table, plugin-driven, and histogram collection paths. It also made it easy for a newly added template expression to consume an unescaped name.
How to reproduce
UNIONquery against the inaccessible table.Fix
SqlUtils.getIdentSql, so embedded backticks are doubled and the complete value remains one identifier.Tests
OlapAnalysisTaskTest: 25 tests passed.HistogramTaskTest: 2 tests passed.AnalyzeTest: 2 tests passed.BaseAnalysisTaskTest: 3 tests passed.