Skip to content

Query condition cache serves another session's verdict when a conversion captures a session setting (precise_float_parsing) not in the cache key: rows silently vanish #117203

Closed

Description

@zlareb1

Describe what's wrong

The query condition cache (use_query_condition_cache, default on) keys a granule-skip verdict by a hash of the filter DAG (ActionsDAG::Node::updateHash), which includes the function/type names and constant values but not the session settings that a conversion function captured at build time. FunctionConvertSettings (src/Functions/FunctionsConversion.h) captures precise_float_parsing, cast_string_to_date_time_mode, date_time_overflow_behavior, cast_keep_nullable, etc. from the building session's context, while the function reports a fixed getName() (e.g. toFloat64) and a stable result_type. Two sessions that differ only in one of these settings therefore build byte-identical DAG hashes, collide on the same query condition cache key, and one reuses the other's per-granule verdict — even though the conversion evaluates the predicate to a different value in each session.

The result is silent row loss: a session using a non-default value of one of these settings can mark a granule "no matching rows" in the cache, and a second session running at pure defaults then skips that granule and drops rows that actually match its predicate.

This is a distinct mechanism from #117186 (that one is an omitted DateTime timezone hiding inside the type name). Here the divergence lives inside the FunctionBase object and never reaches getName() or the type name, so a fix scoped to the type-name path does not cover it.

Does it reproduce on the most recent release?

Yes, reproduced on 26.9.1.1.

How to reproduce

precise_float_parsing (default true) is the cleanest lever. A Float64 SQL literal parses to the same bits under both values of the setting, but parsing a String column differs by one ULP for a value like 1.1e-300:

-- literal is identical under both settings (comparison constant is stable across sessions)
SELECT reinterpretAsUInt64(CAST(1.1e-300 AS Float64)) SETTINGS precise_float_parsing=1;  -- 119225253609828885
SELECT reinterpretAsUInt64(CAST(1.1e-300 AS Float64)) SETTINGS precise_float_parsing=0;  -- 119225253609828885
-- column parse differs by one ULP
SELECT reinterpretAsUInt64(toFloat64(materialize('1.1e-300'))) SETTINGS precise_float_parsing=1;  -- 119225253609828885
SELECT reinterpretAsUInt64(toFloat64(materialize('1.1e-300'))) SETTINGS precise_float_parsing=0;  -- 119225253609828886

Full poisoning on a real server (the query condition cache is disabled in clickhouse local):

CREATE TABLE t (id UInt64, s String) ENGINE = MergeTree ORDER BY id;
INSERT INTO t SELECT number, '1.1e-300' FROM numbers(200000);

-- data is at stake: at pure defaults every row matches
SELECT count() FROM t WHERE toFloat64(s) = 1.1e-300 SETTINGS use_query_condition_cache = 0;
-- 200000

SYSTEM DROP QUERY CONDITION CACHE;

-- session A: one non-default setting, populates the cache (predicate is false under fast parsing)
SELECT count() FROM t WHERE toFloat64(s) = 1.1e-300
SETTINGS use_query_condition_cache = 1, precise_float_parsing = 0;
-- 0  (and system.query_condition_cache now has one entry)

-- session B: PURE DEFAULTS, same query
SELECT count() FROM t WHERE toFloat64(s) = 1.1e-300
SETTINGS use_query_condition_cache = 1;
-- 0     <-- wrong

Controls, all confirming it is the cache and the rows exist:

-- B alone (no poisoning), defaults, cache on -> correct
SYSTEM DROP QUERY CONDITION CACHE;
SELECT count() FROM t WHERE toFloat64(s) = 1.1e-300 SETTINGS use_query_condition_cache = 1;  -- 200000

-- poison, then read B with the cache off -> rows are still there
SYSTEM DROP QUERY CONDITION CACHE;
SELECT count() FROM t WHERE toFloat64(s) = 1.1e-300 SETTINGS use_query_condition_cache = 1, precise_float_parsing = 0;  -- 0
SELECT count() FROM t WHERE toFloat64(s) = 1.1e-300 SETTINGS use_query_condition_cache = 0;  -- 200000

The victim runs at pure defaults; the only non-default input is on the poisoning session, and precise_float_parsing = 0 was itself the default before 26.7, so it is a realistic value to find in an existing user profile on a shared cluster. Any two sessions that disagree on one of the FunctionConvertSettings-captured settings poison each other; precise_float_parsing is used here only because it is the easiest to demonstrate deterministically.

Expected behavior

Session B, running at pure defaults, returns 200000 — every row whose toFloat64(s) equals the literal 1.1e-300 under its own settings. A cache verdict produced by a session that evaluates the predicate differently must not be served to a session with different settings.

Actual behavior

Session B returns 0. It reuses the granule-skip verdict populated by session A (which evaluated the predicate to false under precise_float_parsing = 0) and silently drops all 200000 matching rows. The rows are present (the same query with use_query_condition_cache = 0 returns 200000).

Additional context

Root cause: the cache key ultimately derives from ActionsDAG::Node::updateHash (src/Interpreters/ActionsDAG.cpp), which hashes function_base->getName() / result_type->getName() / constant values but no session settings, while FunctionConvertSettings (src/Functions/FunctionsConversion.h) captures precise_float_parsing, cast_string_to_date_time_mode, date_time_overflow_behavior, and others from context. Folding a fingerprint of the captured settings into the node hash (or reporting these conversions as non-deterministic-across-settings so the cache-population gate excludes them) would close the whole family; the same reasoning applies to FunctionBinaryArithmetic, which captures check_decimal_overflow without surfacing it in getName().

Version info

Activity

  1. alexey-milovidov commented on Aug 31, 2026

    @alexey-milovidov
    Member

    Include these settings into the key.

  2. added
    bug
    comp-mergetree
    comp-query-execution
    on Aug 31, 2026
  3. clickgapai commented on Aug 31, 2026

    @clickgapai
    Contributor
    Reproducer
    -- on a real server (the query condition cache is inert in clickhouse-local)
    CREATE TABLE t (id UInt64, s String) ENGINE = MergeTree ORDER BY id;
    INSERT INTO t SELECT number, '1.1e-300' FROM numbers(200000);
    
    -- ground truth: every row matches under precise parsing
    SELECT count() FROM t WHERE toFloat64(s) = 1.1e-300
    SETTINGS use_query_condition_cache = 0, precise_float_parsing = 1;   -- 200000
    
    SYSTEM DROP QUERY CONDITION CACHE;
    
    -- session A: predicate is false under fast parsing -> writes "no matching rows" for every granule
    SELECT count() FROM t WHERE toFloat64(s) = 1.1e-300
    SETTINGS use_query_condition_cache = 1, precise_float_parsing = 0;   -- 0
    
    -- session B: same query, precise parsing (the default since 26.7)
    SELECT count() FROM t WHERE toFloat64(s) = 1.1e-300
    SETTINGS use_query_condition_cache = 1, precise_float_parsing = 1;   -- 0   <-- expected 200000
    
    -- control: drop the cache first and B is correct
    SYSTEM DROP QUERY CONDITION CACHE;
    SELECT count() FROM t WHERE toFloat64(s) = 1.1e-300
    SETTINGS use_query_condition_cache = 1, precise_float_parsing = 1;   -- 200000

    Results:

    • Culprit PR: not identified (details in Analysis metadata)
    • Reproduces on: master, 26.7, 26.6, 26.5, 26.3, 25.8
    • Tested versions: master, 26.7, 26.6, 26.5, 26.3, 25.8
    • Also tested (unsupported, context only): 26.2 reproduces
    Analysis metadata

    comp-mergetree · Severity P2 · Finding h_issue_117203

    • Verified against master build bb113c3849bb (aarch64)
    • Secondary components: comp-query-execution
  4. added
    potential bug
    minor
    and removed
    bug
    on Sep 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

clickgap-analyzedcomp-mergetreecomp-query-executionculprit-pr-not-foundminorpotential bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions