Repository navigation
Conversation
ColinLeeo
left a comment
There was a problem hiding this comment.
The fix looks correct to me. I compared 26 result queries on the base and PR versions, including partial deletions, out-of-order writes, and ascending and descending group-by windows. Both comments below are non-blocking.
| + "(time, x, y, z) ALIGNED VALUES " | ||
| + "(10, 100, 1, NULL), (20, NULL, 1, NULL), (30, NULL, 1, 300)", | ||
| "FLUSH " + database, | ||
| "DELETE FROM " + device + ".y WHERE time >= 10" |
There was a problem hiding this comment.
Could we add a regression that reaches the file-level statistics check? This deletion marks the file metadata as modified, so the scan already descends to chunk statistics. I disabled only the new file-level coverage check locally, and all three assertions below still passed.
One case that distinguishes the two versions is to load an aligned TsFile with 9 physical timestamps, 4 of which have a value in at least one measurement. With no deletions, SELECT * returns 4 rows. On the PR, COUNT_TIME(*) also returns 4. Disabling just the file-level check makes it return 9. An assertion on that count would catch a regression in this branch.
| // A measurement covering every timestamp proves that COUNT_TIME can use the physical count. | ||
| if (usesTimeStatistics | ||
| && Arrays.stream(valueStatistics) | ||
| .noneMatch(s -> s != null && s.getCount() == timeStatistics.getCount())) { |
There was a problem hiding this comment.
One possible follow-up for COUNT_TIME(*): when statistics are usable and exactly one selected measurement has a positive count, that measurement's count is the exact number of visible timestamps, even if it is sparse.
I checked this with 4,096 physical timestamps. After deleting the dense measurement, only x had values, at the 2,048 even timestamps. Both COUNT_TIME(*) and COUNT(x) returned 2,048. EXPLAIN ANALYZE VERBOSE showed that the former decoded 32 aligned pages and the latter decoded zero. Using the surviving measurement's count would avoid decoding those pages.
Reproducer
An aligned device has three timestamps. After a flush, deleting the only non-null value at time 20 leaves two visible timestamps.
root.count_demo.d1SELECT *SELECT COUNT_TIME(*)SELECT COUNT_TIME(*) … GROUP BY ([10, 40), 30ms)SELECT COUNT_TIME(*) … GROUP BY ([10, 40), 10ms)Fix
The aligned time column can retain physical timestamps after their values have been deleted. A tree aggregation that consumes time-column statistics now uses a file, chunk, or page count only when a selected measurement has a value at every timestamp. If the statistics cannot establish that, the scan descends to finer-grained statistics or reads the rows. The regression test leaves the two surviving values in different columns so it also checks that both timestamps contribute to the result.
Verification
IoTDBCountTimeAlignedDeviceIT, including the new regression, with no failures, errors, or skips.IoTDBCountTimeAlignedDeviceITandIoTDBCountTimeIT. All passed, with no skips.FragmentInstanceContextTestunit tests passed. Spotless and integration test selection checks passed.