Repository navigation
Fix tree COUNT_TIME overcount on sparse aligned timestamps #19446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,7 @@ | |
| import java.util.List; | ||
| import java.util.Optional; | ||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.function.IntFunction; | ||
|
|
||
| import static org.apache.iotdb.db.queryengine.execution.operator.AggregationUtil.appendAggregationResult; | ||
| import static org.apache.iotdb.db.queryengine.execution.operator.AggregationUtil.calculateAggregationFromRawData; | ||
|
|
@@ -72,6 +73,8 @@ public abstract class AbstractSeriesAggregationScanOperator extends AbstractData | |
| /** Some special data types(like BLOB) cannot use statistics. */ | ||
| protected final boolean canUseStatistics; | ||
|
|
||
| private final boolean usesTimeStatistics; | ||
|
|
||
| @SuppressWarnings("squid:S107") | ||
| protected AbstractSeriesAggregationScanOperator( | ||
| PlanNodeId sourceId, | ||
|
|
@@ -99,6 +102,7 @@ protected AbstractSeriesAggregationScanOperator( | |
| this.maxReturnSize = maxReturnSize; | ||
| this.outputEndTime = outputEndTime; | ||
| this.canUseStatistics = canUseStatistics; | ||
| this.usesTimeStatistics = aggregators.stream().anyMatch(TreeAggregator::usesTimeStatistics); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -256,6 +260,27 @@ private boolean calcFromRawData(TsBlock tsBlock) { | |
| } | ||
| } | ||
|
|
||
| private boolean tryCalcFromStatistics( | ||
| Statistics timeStatistics, IntFunction<Statistics> getValueStatistics) { | ||
| if (!curTimeRange.contains(timeStatistics.getStartTime(), timeStatistics.getEndTime())) { | ||
| return false; | ||
| } | ||
|
|
||
| Statistics[] valueStatistics = new Statistics[subSensorSize]; | ||
| for (int i = 0; i < subSensorSize; i++) { | ||
| valueStatistics[i] = getValueStatistics.apply(i); | ||
| } | ||
| // An aligned time column can retain a timestamp after its last non-null value is deleted. | ||
| // 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())) { | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One possible follow-up for I checked this with 4,096 physical timestamps. After deleting the dense measurement, only |
||
| return false; | ||
| } | ||
| calcFromStatistics(timeStatistics, valueStatistics); | ||
| return true; | ||
| } | ||
|
|
||
| protected void calcFromStatistics(Statistics timeStatistics, Statistics[] valueStatistics) { | ||
| long startTime = System.nanoTime(); | ||
| try { | ||
|
|
@@ -293,13 +318,7 @@ protected boolean readAndCalcFromFile() throws IOException { | |
| } | ||
| } | ||
| // calc from fileMetaData | ||
| if (curTimeRange.contains( | ||
| fileTimeStatistics.getStartTime(), fileTimeStatistics.getEndTime())) { | ||
| Statistics[] statisticsList = new Statistics[subSensorSize]; | ||
| for (int i = 0; i < subSensorSize; i++) { | ||
| statisticsList[i] = seriesScanUtil.currentFileStatistics(i); | ||
| } | ||
| calcFromStatistics(fileTimeStatistics, statisticsList); | ||
| if (tryCalcFromStatistics(fileTimeStatistics, seriesScanUtil::currentFileStatistics)) { | ||
| seriesScanUtil.skipCurrentFile(); | ||
| if (isAllAggregatorsHasFinalResult(aggregators) && !isGroupByQuery) { | ||
| return true; | ||
|
|
@@ -341,14 +360,7 @@ protected boolean readAndCalcFromChunk() throws IOException { | |
| } | ||
| } | ||
| // calc from chunkMetaData | ||
| if (curTimeRange.contains( | ||
| chunkTimeStatistics.getStartTime(), chunkTimeStatistics.getEndTime())) { | ||
| // calc from chunkMetaData | ||
| Statistics[] statisticsList = new Statistics[subSensorSize]; | ||
| for (int i = 0; i < subSensorSize; i++) { | ||
| statisticsList[i] = seriesScanUtil.currentChunkStatistics(i); | ||
| } | ||
| calcFromStatistics(chunkTimeStatistics, statisticsList); | ||
| if (tryCalcFromStatistics(chunkTimeStatistics, seriesScanUtil::currentChunkStatistics)) { | ||
| seriesScanUtil.skipCurrentChunk(); | ||
| if (isAllAggregatorsHasFinalResult(aggregators) && !isGroupByQuery) { | ||
| return true; | ||
|
|
@@ -384,13 +396,7 @@ protected boolean readAndCalcFromPage() throws IOException { | |
| } | ||
| } | ||
| // can use pageHeader | ||
| if (curTimeRange.contains( | ||
| pageTimeStatistics.getStartTime(), pageTimeStatistics.getEndTime())) { | ||
| Statistics[] statisticsList = new Statistics[subSensorSize]; | ||
| for (int i = 0; i < subSensorSize; i++) { | ||
| statisticsList[i] = seriesScanUtil.currentPageStatistics(i); | ||
| } | ||
| calcFromStatistics(pageTimeStatistics, statisticsList); | ||
| if (tryCalcFromStatistics(pageTimeStatistics, seriesScanUtil::currentPageStatistics)) { | ||
| seriesScanUtil.skipCurrentPage(); | ||
| if (isAllAggregatorsHasFinalResult(aggregators) && !isGroupByQuery) { | ||
| return true; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.