Repository navigation
Commit 0276aff
committed
[fix](ivm) Estimate a stream read's row count from the table it reads
### What problem does this PR solve?
Issue Number: None
Related PR: None
Problem Summary:
A scan that reads a table stream is planned over a lightweight wrapper of the base table:
OlapTableWrapper for the base-table reads (stream@reset, and the base part of stream@snapshot),
OlapChangelogTableWrapper for the changelog part. The wrapper delegates partition lookups but
holds no partitions of its own, while OlapTable derives a row count by iterating that map. Every
scan over a wrapper was therefore estimated at zero rows, which StatsCalculator.computeOlapScan
raises to one: a read of a four-billion-row table looked like a one-row scan.
In cloud mode NormalizeOlapTableStreamScan wraps the base table for every read once the cloud
read states are installed, so both stream@reset() and stream@snapshot() were estimated at one
row. An incremental view maintenance refresh plans its reads the same way. With the wrong
estimate the optimizer picks the real four-hundred-million-row side as the broadcast build, and
the refresh exhausts the task memory limit.
Reproduction: one duplicate-key table with seven rows and one stream (show_initial_rows=false,
five rows written before the stream and two after). Before this change, the plans estimated the
base table at 7 rows, stream@reset() at 1 row in cloud (7 rows in shared-nothing), and
stream@snapshot() at 1 row in both.
Fix:
- OlapTableWrapper delegates getRowCountForIndex, getRowCountForPartitionIndex,
getPartitionNum and getPartitionItemOrAnalysisException to the table it wraps. A reset read,
and a snapshot read whose offsets already reached the end, see exactly that table's content; a
snapshot read of an older offset is bounded by it. With the partition count in place, a
partition-pruned scan takes the statistics calculator's per-partition path, which looks up the
selected partitions' items to tighten the partition-key min/max.
- OlapChangelogTableWrapper does not guess. A changelog scan reads the change rows of its offset
range, not the table; a read that starts at the beginning of the stream returns about the
table's rows while a delta returns a few, and FE cannot tell the two apart. It keeps the row
count unknown (UNKNOWN_ROW_COUNT) instead of the table's rows or zero. This is unchanged
behaviour from before the delegation.
Results on a local cloud cluster, with the seven-row table and stream, stats= from the query
profile: base table 7 -> 7, stream@reset() 1 -> 7, stream@snapshot() 1 -> 7. The incremental
read keeps its previous estimate.
### Release note
Fix stream reads (including incremental view maintenance refreshes) estimating every scan at one
row, which could make the optimizer broadcast a very large build side and exhaust memory during a
refresh.
### Check List (For Author)
- Test: Unit test / Regression test / Manual test
- Unit test: OlapTableWrapperTest, three new cases (row count delegation; the changelog wrapper
keeps the change-row count unknown instead of inheriting the table's row count; partition
item lookup delegation).
- Regression test: changelog_p0/test_stream_scan_row_count, which runs in both the
shared-nothing and the cloud P0 pipelines and asserts the estimates with
explain physical plan.
- Manual test: the reproduction above, verified through query profiles on a local cloud
cluster before and after the change.
- Behavior changed: Yes. Scans over a reset or snapshot stream read are now estimated from the
table they read instead of one row.
- Does this need documentation: No1 parent 2a4191c commit 0276aff
4 files changed
Lines changed: 198 additions & 0 deletions
File tree
- fe/fe-core/src
- main/java/org/apache/doris/catalog
- test/java/org/apache/doris/catalog
- regression-test/suites/changelog_p0
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
38 | 44 | | |
39 | 45 | | |
40 | 46 | | |
| |||
62 | 68 | | |
63 | 69 | | |
64 | 70 | | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
65 | 85 | | |
66 | 86 | | |
67 | 87 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
149 | 150 | | |
150 | 151 | | |
151 | 152 | | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
152 | 158 | | |
153 | 159 | | |
154 | 160 | | |
| |||
190 | 196 | | |
191 | 197 | | |
192 | 198 | | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
193 | 226 | | |
194 | 227 | | |
195 | 228 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
186 | 186 | | |
187 | 187 | | |
188 | 188 | | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
189 | 244 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
0 commit comments