From 3a1a9162c0949d9d8526b4b8e041db7d9bd20835 Mon Sep 17 00:00:00 2001 From: Siddharth D Jaiswal Date: Tue, 15 Dec 2020 15:49:03 +0530 Subject: [PATCH] Added changes to address incorrect approx stats for getDistinctValuesCount() for columns. --- .../planner/iterative/rule/TablePushdown.java | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/presto-main/src/main/java/io/prestosql/sql/planner/iterative/rule/TablePushdown.java b/presto-main/src/main/java/io/prestosql/sql/planner/iterative/rule/TablePushdown.java index 8282ee2bc..52b72caed 100644 --- a/presto-main/src/main/java/io/prestosql/sql/planner/iterative/rule/TablePushdown.java +++ b/presto-main/src/main/java/io/prestosql/sql/planner/iterative/rule/TablePushdown.java @@ -226,21 +226,22 @@ public class TablePushdown TableHandle tableHandle = tableNode.getTable(); TableStatistics tableStatistics = metadata.getTableStatistics(ruleContext.getSession(), tableHandle, Constraint.alwaysTrue()); - if (tableStatistics != null) { - /* - * We check here if tablestats is null or not. - * If not null then proceed as follows. - * */ - return isTableWithUniqueColumnTableStatistics(tableStatistics, tableHandle); + /* + * We check here if tablestats is null or not. + * If not null then check if the stats match as per requirement. + * */ + if (tableStatistics != null && isTableWithUniqueColumnTableStatistics(tableStatistics, tableHandle)) { + return true; } else { /* - * if table statistics are not available, check if user hint is available. If not, return false as nothing can be tested at this point. - * If user hint is available, check- - * If table name of the current table doesn't match with user hint, then return false; - * If it matches, then check if the user supplied column name is present in the join criteria. If it does, return true; - * Else, return false. - * */ + * if table statistics are not available or due to approx stats doesn't match, check if user hint is available. + * If not, return false as nothing can be tested at this point. + * If user hint is available, check- + * If table name of the current table doesn't match with user hint, then return false; + * If it matches, then check if the user supplied column name is present in the join criteria. If it does, return true; + * Else, return false. + * */ if (uniqueColumnsPerTable.isEmpty()) { return false; }