bug: `PARTITION BY (to_date(ts))` stores partition values in the writer's time zone but prunes with the reader's, so rows written from a UTC session are missing from filtered queries in an Asia/Shanghai session and survive a matching DELETE
Maintainers usually reply within 1 day
@KKould is already working on this.
Since Nov 23, 2026.
Assessment
This issue has not been assessed yet.
Description
Search before asking
- I had searched in the issues and found no similar issues.
Version
main 057efa66e6 (v1.2.961-057efa66e6, nightly image of 2026-11-08); also v1.2.960-nightly-3c9357c866.
What's Wrong?
A fuse table partitioned by a time-zone dependent expression (PARTITION BY (to_date(ts)), (to_yyyymm(ts)),
(date_trunc(day, ts))) computes the partition value of each row with the writing session's time zone and
stores it in the segment's partition statistics. Partition pruning folds the partition expression over the
reading session's filter with the reader's time zone and compares with the stored values. When the two
sessions use different timezone settings, blocks holding matching rows are pruned:
- a filtered
SELECTsilently misses rows (count_if()of the same predicate, which is not pruned, finds them); - a
DELETE(orUPDATE) with the predicate skips them: the rows stay although they match.
Sessions with the same time zone are consistent; CLUSTER BY (to_date(ts)) is not affected (cluster statistics
already fall back for context-dependent keys). #20595 rejects explicit context functions (timezone(),
current_user(), …) in cluster/partition keys and documents that "implicit timezone/other settings dependencies
of ordinary functions and casts remain a separate unresolved issue requiring coordinated definition/runtime
changes"; to_date(ts) is such an implicit dependency, and this is what it does to query and DML results.
Cause: on write, the partition key is evaluated by the cluster-statistics generator built with the writing
session's function context
(append.rs#L469-L478),
and the value is stored as the segment's partition statistics. On read, PartitionPruner::try_create(func_ctx, …)
(fuse_pruner.rs#L158-L162)
folds the partition expressions and projects the filter with the reading session's FunctionContext. Nothing ties
the two contexts together: analyze_table_keys
(ddl/table.rs#L2888)
accepts any deterministic expression, including time-zone dependent ones, and the table does not record the time
zone its partition values were computed in. Possible fixes: evaluate partition keys in a fixed context recorded in
the table (e.g. UTC, or the definer's time zone) on both write and read, or reject time-zone dependent partition
keys, or skip partition pruning when the reader's context differs from the writer's.
How to Reproduce?
-- session A
SET timezone = 'UTC';
CREATE TABLE events (id INT, ts TIMESTAMP) PARTITION BY (to_date(ts));
INSERT INTO events VALUES (1, '2024-01-31 20:00:00'), (2, '2024-01-31 10:00:00'), (3, '2024-02-01 10:00:00');
-- session B (row 1 is 2024-02-01 04:00 in Shanghai)
SET timezone = 'Asia/Shanghai';
SELECT id, ts, to_date(ts) FROM events ORDER BY id;
SELECT id FROM events WHERE to_date(ts) = '2024-02-01' ORDER BY id;
SELECT count_if(to_date(ts) = '2024-02-01') FROM events;
SELECT id FROM events WHERE ts >= '2024-02-01 00:00:00' AND ts < '2024-02-02 00:00:00' ORDER BY id;
SELECT id FROM events WHERE ts = '2024-02-01 04:00:00';
DELETE FROM events WHERE to_date(ts) = '2024-02-01';
SELECT id, ts, to_date(ts) FROM events ORDER BY id;
Result on main 057efa66e6 (session B):
1 | 2024-02-01 04:00:00.000000 | 2024-02-01
2 | 2024-01-31 18:00:00.000000 | 2024-01-31
3 | 2024-02-01 18:00:00.000000 | 2024-02-01
WHERE to_date(ts) = '2024-02-01': 3 <- expected 1, 3
count_if(to_date(ts) = '2024-02-01'): 2
WHERE ts >= '2024-02-01' AND ts < '2024-02-02': 3 <- expected 1, 3
WHERE ts = '2024-02-01 04:00:00': (no rows) <- expected 1
DELETE ... WHERE to_date(ts) = '2024-02-01': 1 row deleted
1 | 2024-02-01 04:00:00.000000 | 2024-02-01 <- matches the DELETE predicate but survives
2 | 2024-01-31 18:00:00.000000 | 2024-01-31
Expected: rows 1 and 3 for both range predicates, row 1 for the equality, and the DELETE removes rows 1 and 3.
With PARTITION BY (to_yyyymm(ts)) and PARTITION BY (date_trunc(day, ts)) the to_date(ts) predicate happens to
return rows 1 and 3, but both ts predicates miss row 1 (with date_trunc(day, ts) the range query returns no rows
at all).
Single node, default settings apart from the session time zones, HTTP handler.
Are you willing to submit PR?
- Yes I am willing to submit a PR!
- Dominant language
- Rust
- Stars
- 9.5k
- Forks
- 903
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 204
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from databendlabs/databend
-
bug: segment pruning skips rows when only some blocks have statistics of an added columnPossibly taken @zhyass claimed this today. OpenC-bug
databendlabs/databend#21244 · 1 assignee ·
Maintainers usually reply within 1 day
-
bug: ORDER BY ... NULLS LAST LIMIT returns wrong rows when an inverted index answers the filter and the sort column has NULLsPossibly taken @b41sh claimed this today. OpenC-bug
databendlabs/databend#21243 · 1 assignee ·
Maintainers usually reply within 1 day
-
Feature: Reduce role-graph work for explicit secondary rolesPossibly taken @TCeason claimed this 1 day ago. OpenC-feature
databendlabs/databend#21226 · 1 assignee ·
Maintainers usually reply within 1 day
-
Feature: Key role-dependent query results by authorization contextPossibly taken @TCeason claimed this 1 day ago. OpenC-feature
databendlabs/databend#21225 · 1 assignee ·
Maintainers usually reply within 1 day
-
bug: filters folded to false on block statistics drop matching rows: cast-eliminated equality under NOT, float arithmetic over NaN and infinities, variant IS DISTINCT FROMPossibly taken @forsaken628 claimed this 1 day ago. OpenC-bug
databendlabs/databend#21216 · 1 assignee ·
Maintainers usually reply within 1 day
All issues in databendlabs/databend
Similar issues
-
marketing
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
eliasstravik/herdr-projects#1605 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
jlcodes99/cockpit-tools#3332 ·
Maintainers usually reply within 3 days
-
Cognito: the email MFA code (EMAIL_OTP challenge after a password flow) has 8 digits; AWS delivers 6Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
aws/aws-emulator#692 ·
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 82/100
pamburus/hl#1779 · 1 comment ·
Maintainers usually reply within 1 day