englefly commented on code in PR #69322:
URL: https://github.com/apache/doris/pull/69322#discussion_r4360784668
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/stats/HboUtils.java:
##########
@@ -368,6 +341,48 @@ private static Optional<List<PlanStatistics>>
getFilterAdjustedInputTableStatist
return Optional.of(outputTableStatisticsBuilder.build());
}
+ /** The table each relation id of the current plan is bound to. */
+ private static Map<RelationId, Long> currentTableIdsByRelation(String
queryId,
+ HboPlanInfoProvider planInfoProvider) {
+ Map<RelationId, Long> tableIds = new HashMap<>();
+ for (PhysicalPlan plan :
planInfoProvider.getIdToPlanMap(queryId).values()) {
+ if (plan instanceof PhysicalOlapScan) {
+ PhysicalOlapScan scan = (PhysicalOlapScan) plan;
+ tableIds.put(scan.getRelationId(), scan.getTable().getId());
+ }
+ }
+ return tableIds;
+ }
+
+ /**
+ * Whether every scan of a recorded entry is bound to the same table in
the current plan.
+ *
+ * <p>A relation id is a position in the plan, and a slot reference is
compared by its expression id
+ * only (see {@code SlotReference#equals}), so a query which writes the
tables of a key in the other
+ * order binds the same positions to opposite tables: its predicates would
be read as the entry's, and
+ * the learned row count of a run with a different filter would be applied
to it. The comparison uses
+ * the id of the table, which no alias, position or name of a query
changes. A scan the collector did
+ * not see (it records the relations while the filters of the query are
collected) cannot be
+ * compared and does not reject the entry on its own.
+ */
+ static boolean sameTablesByRelation(Map<RelationId, Long> currentTableIds,
+ List<PlanStatistics> recordedInputTableStatistics) {
+ for (PlanStatistics recorded : recordedInputTableStatistics) {
+ if (!(recorded instanceof ScanPlanStatistics)) {
+ continue;
+ }
+ PhysicalOlapScan recordedScan = ((ScanPlanStatistics)
recorded).getScan();
+ if (recordedScan == null || recordedScan.getTable() == null) {
+ continue;
+ }
+ Long currentTableId =
currentTableIds.get(recordedScan.getRelationId());
+ if (currentTableId != null && currentTableId !=
recordedScan.getTable().getId()) {
Review Comment:
learned hbo 将重做, 不在这个 pr 范围
--
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]