Skip to content

Commit fb22c7e

Browse files
committed
filter table deletions
1 parent f05ad36 commit fb22c7e

3 files changed

Lines changed: 40 additions & 1 deletion

File tree

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/fragment/FragmentInstanceContext.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,9 @@ protected PatternTreeMap<ModEntry, PatternTreeMapFactory.ModsSerializer> getAllM
364364
}
365365
return null;
366366
});
367+
if (cachedResult == null) {
368+
LOGGER.error("cached num: {}, mem cost: {}", fileModCache.size(), cachedModEntriesSize.get());
369+
}
367370
return cachedResult == null ? atomicReference.get() : cachedResult;
368371
}
369372

@@ -526,6 +529,16 @@ public void setTimeFilterForTableModel(Filter timeFilter) {
526529
}
527530
}
528531

532+
@Override
533+
public boolean collectTable(String table) {
534+
boolean added = super.collectTable(table);
535+
if (added && memoryReservationManager != null) {
536+
memoryReservationManager.reserveMemoryCumulatively(
537+
RamUsageEstimator.sizeOf(table) + RamUsageEstimator.SHALLOW_SIZE_OF_HASHMAP_ENTRY);
538+
}
539+
return added;
540+
}
541+
529542
public IDataRegionForQuery getDataRegion() {
530543
return dataRegion;
531544
}
@@ -842,6 +855,7 @@ public synchronized void releaseResource() {
842855
releaseTVListOwnedByQuery();
843856

844857
fileModCache = null;
858+
tables = null;
845859
dataRegion = null;
846860
globalTimeFilter = null;
847861
sharedQueryDataSource = null;

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/fragment/QueryContext.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.iotdb.commons.path.PartialPath;
2424
import org.apache.iotdb.commons.path.PatternTreeMap;
2525
import org.apache.iotdb.db.storageengine.dataregion.modification.ModEntry;
26+
import org.apache.iotdb.db.storageengine.dataregion.modification.TableDeletionEntry;
2627
import org.apache.iotdb.db.storageengine.dataregion.tsfile.TsFileID;
2728
import org.apache.iotdb.db.storageengine.dataregion.tsfile.TsFileResource;
2829
import org.apache.iotdb.db.utils.ModificationUtils;
@@ -76,6 +77,8 @@ public class QueryContext {
7677
// referenced TVLists for the query
7778
protected final Set<TVList> tvListSet = new HashSet<>();
7879

80+
protected Set<String> tables;
81+
7982
public QueryContext() {}
8083

8184
public QueryContext(long queryId) {
@@ -90,6 +93,18 @@ public QueryContext(long queryId, boolean debug, long startTime, long timeout) {
9093
this.timeout = timeout;
9194
}
9295

96+
// Only used for query with table data(Tree view is not included)
97+
public boolean collectTable(String table) {
98+
if (tables == null) {
99+
tables = Collections.singleton(table);
100+
return true;
101+
}
102+
if (!(tables instanceof HashSet)) {
103+
tables = new HashSet<>(tables);
104+
}
105+
return tables.add(table);
106+
}
107+
93108
// if the mods file does not exist, do not add it to the cache
94109
protected boolean checkIfModificationExists(TsFileResource tsFileResource) {
95110
// The exists state of ModificationFile is maintained in memory, and ModificationFile instance
@@ -106,7 +121,15 @@ public PatternTreeMap<ModEntry, ModsSerializer> loadAllModificationsFromDisk(
106121
TsFileResource resource) {
107122
PatternTreeMap<ModEntry, ModsSerializer> modifications =
108123
PatternTreeMapFactory.getModsPatternTreeMap();
109-
for (ModEntry modification : resource.getAllModEntries()) {
124+
TsFileResource.ModIterator modEntryIterator = resource.getModEntryIterator();
125+
while (modEntryIterator.hasNext()) {
126+
ModEntry modification = modEntryIterator.next();
127+
if (tables != null && modification instanceof TableDeletionEntry) {
128+
String tableName = ((TableDeletionEntry) modification).getTableName();
129+
if (!tables.contains(tableName)) {
130+
continue;
131+
}
132+
}
110133
modifications.append(modification.keyOfPatternTree(), modification);
111134
}
112135
return modifications;

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/TableOperatorGenerator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,6 +1207,7 @@ public Operator visitDeviceTableScan(
12071207

12081208
TableScanOperator tableScanOperator = new TableScanOperator(parameter);
12091209

1210+
context.getInstanceContext().collectTable(node.getQualifiedObjectName().getObjectName());
12101211
addSource(
12111212
tableScanOperator,
12121213
context,
@@ -3021,6 +3022,7 @@ public Operator visitAggregationTableScan(
30213022
} else {
30223023
DefaultAggTableScanOperator aggTableScanOperator = new DefaultAggTableScanOperator(parameter);
30233024

3025+
context.getInstanceContext().collectTable(node.getQualifiedObjectName().getObjectName());
30243026
addSource(
30253027
aggTableScanOperator,
30263028
context,

0 commit comments

Comments
 (0)