github-actions[bot] commented on code in PR #68282:
URL: https://github.com/apache/doris/pull/68282#discussion_r4080612135


##########
fe/fe-core/src/main/java/org/apache/doris/statistics/analysis/TableStatsMeta.java:
##########
@@ -130,6 +137,59 @@ public TableStatsMeta(long rowCount, AnalysisInfo 
analyzedJob, TableIf table) {
         update(analyzedJob, table);
     }
 
+    /**
+     * Create a record for a table which doesn't have one yet, in the state of 
an empty table. The rows
+     * loaded into the table are accumulated by {@link 
AnalysisManager#replayUpdateRowsRecord}, so a record
+     * has to exist before the first load, otherwise these rows can never be 
turned into a row count.
+     */
+    public TableStatsMeta(OlapTable table) {
+        this.ctlId = table.getDatabase().getCatalog().getId();
+        this.ctlName = table.getDatabase().getCatalog().getName();
+        this.dbId = table.getDatabase().getId();
+        this.dbName = table.getDatabase().getFullName();
+        this.tblId = table.getId();
+        this.tblName = table.getName();
+        this.idxId = -1;
+        this.indexesRowCount = buildEmptyIndexRowCount(table);
+        this.updatedRowsBase.set(0);
+    }
+
+    /**
+     * TRUNCATE TABLE removes all the data of the table. Reset this record 
back to the state of an empty
+     * table instead of dropping it, so that the rows loaded after the 
truncation can still be accumulated
+     * into {@link #updatedRows} and be reported as the row count of the table.
+     */
+    public void reset(OlapTable table) {
+        rowCount = 0;
+        updatedRows.set(0);
+        // Nothing has been collected for the emptied table, so none of the 
rows loaded from now on is
+        // included in the collected row count. They are all delta rows.
+        updatedRowsBase.set(0);
+        partitionUpdateRows.clear();
+        // All the data is removed, so the base index is known to be empty.

Review Comment:
   [P2] Keep the reset coherent for lock-free MTMV cache planning
   
   Normal query planning is protected by the table read lock, but a direct MTMV 
scan can reach `getOrGenerateCache()` with an empty cache; its nested 
`MTMVCache.from(..., needLock=false)` still runs a full cost plan, while the 
outer statement locks the MTMV rather than the base tables in its definition. A 
concurrent base-table truncate can therefore let `StatsCalculator` read the old 
`indexesRowCount` here and the newly zeroed delta, then publish that inflated 
cardinality in the reusable MTMV cache. Please publish the count and baseline 
as one reader-visible snapshot, or ensure this on-demand planner locks the 
definition's base tables; a barrier-based direct-MTMV cache test would cover 
the bypass.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to