**Subject: [Fix] Prevent aligned LAST queries from hanging with time
filters**

Hi all,

I’d like to share a bug fix introduced by the following PRs:

- Master: https://github.com/apache/iotdb/pull/18213
- Dev/1.3: https://github.com/apache/iotdb/pull/18214

This issue may cause an aligned multi-measurement `LAST` query with a time
filter to keep running until it times out.

An example query is:

```sql
SELECT LAST s1, s2
FROM root.sg.d1
WHERE time >= 100 AND time <= 101;
```

The issue occurs under a specific aligned-series data layout:

- The queried measurements only contain data outside the specified time
range.
- Other measurements in the same aligned device extend the overall
time-series statistics into the specified time range.
- After pruning chunks that contain no values for the queried measurements,
only one chunk remains.

The chunk metadata loader previously skipped time filtering when the
aligned chunk metadata list contained only one chunk. This was based on the
assumption that the singleton chunk statistics were identical to the
time-series metadata statistics.

However, this assumption is not valid after selected-column pruning. The
remaining chunk may be completely outside the query time range. If such a
chunk enters the scan state machine, it may be repeatedly checked without
being unpacked or skipped, causing the query to remain running until
timeout.

The fix applies the global time filter to every non-empty aligned chunk
metadata list, including singleton lists.

A regression integration test has also been added to cover this scenario.

Main changes include:

- Filter singleton aligned chunks using the global time filter.
- Remove the invalid singleton-statistics assumption.
- Add an integration test for aligned multi-measurement `LAST` queries with
time filters.

Feedback and suggestions are welcome.


大家好,

我想分享以下 PR 中修复的一个查询问题:

- Master:https://github.com/apache/iotdb/pull/18213
- Dev/1.3:https://github.com/apache/iotdb/pull/18214

该问题可能导致带时间过滤条件的对齐多测点 `LAST` 查询持续运行,直到查询超时。

示例查询如下:

```sql
SELECT LAST s1, s2
FROM root.sg.d1
WHERE time >= 100 AND time <= 101;
```

该问题会在一种特定的对齐序列数据分布下出现:

- 被查询的测点仅在时间过滤范围之外存在数据。
- 同一对齐设备中的其他测点将整体时间序列统计范围扩展到了查询时间范围内。
- 根据查询测点裁剪不包含有效值的 Chunk 后,最终只剩下一个 Chunk。

此前,ChunkMetadata 加载逻辑在对齐 ChunkMetadata 列表中只有一个 Chunk 时,会跳过时间过滤。其依据是单个 Chunk
的统计范围与 TimeSeriesMetadata 的统计范围相同。

但经过查询列裁剪后,这个假设并不成立。剩余的单个 Chunk 可能完全位于查询时间范围之外。如果该 Chunk
进入扫描状态机,它可能既不会被展开,也不会被跳过,而是在后续调度中被重复检查,最终导致查询持续运行直到超时。

本次修复确保所有非空的对齐 ChunkMetadata 列表都会执行全局时间过滤,包括只包含一个 Chunk 的情况。

同时补充了对应的集成测试,用于覆盖带时间过滤条件的对齐多测点 `LAST` 查询场景。

主要修改包括:

- 对 singleton aligned Chunk 执行全局时间过滤。
- 移除 singleton Chunk 统计范围必然等于 TimeSeriesMetadata 的错误假设。
- 增加对应的回归集成测试。

欢迎大家提出反馈和建议。

Best regards,
Wenwei Shu

Reply via email to