kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject incubator-kudu git commit: KUDU-1446 Consider data types in predicate evaluation order
Date Fri, 03 Jun 2016 22:17:40 GMT
Repository: incubator-kudu
Updated Branches:
  refs/heads/master c24478b83 -> a2e24ba5c


KUDU-1446 Consider data types in predicate evaluation order

This patch enhances SelectivityRank() in column_predicate.cc to account for
column type. Predicate type dominates column type for the sort, and a predicate
on a column of a small type will sort before a predicate on a column of larger
(or variable-size) type.

It also adds a small test for selectivity comparison.

Change-Id: I9c3388876035cb494fdb2c0e1f17698f089fdf72
Reviewed-on: http://gerrit.cloudera.org:8080/3298
Tested-by: Kudu Jenkins
Reviewed-by: Todd Lipcon <todd@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/incubator-kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-kudu/commit/a2e24ba5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-kudu/tree/a2e24ba5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-kudu/diff/a2e24ba5

Branch: refs/heads/master
Commit: a2e24ba5c8c4f2432fa95ee1529f5b82cb523057
Parents: c24478b
Author: Will Berkeley <wdberkeley@gmail.com>
Authored: Mon May 23 12:01:53 2016 -0400
Committer: Todd Lipcon <todd@apache.org>
Committed: Fri Jun 3 22:17:20 2016 +0000

----------------------------------------------------------------------
 src/kudu/common/column_predicate-test.cc | 42 +++++++++++++++++++++++++++
 src/kudu/common/column_predicate.cc      | 12 ++++----
 2 files changed, 49 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/a2e24ba5/src/kudu/common/column_predicate-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/common/column_predicate-test.cc b/src/kudu/common/column_predicate-test.cc
index 1e0cb06..12461ab 100644
--- a/src/kudu/common/column_predicate-test.cc
+++ b/src/kudu/common/column_predicate-test.cc
@@ -328,4 +328,46 @@ TEST_F(TestColumnPredicate, TestInclusiveRange) {
   }
 }
 
+// Test that column predicate comparison works correctly: ordered by predicate
+// type first, then size of the column type.
+TEST_F(TestColumnPredicate, TestSelectivity) {
+  int32_t one_32 = 1;
+  int64_t one_64 = 1;
+  double_t one_d = 1.0;
+  Slice one_s("one", 3);
+
+  ColumnSchema column_i32("a", INT32, true);
+  ColumnSchema column_i64("b", INT64, true);
+  ColumnSchema column_d("c", DOUBLE, true);
+  ColumnSchema column_s("d", STRING, true);
+
+  // Predicate type
+  ASSERT_LT(SelectivityComparator(ColumnPredicate::Equality(column_i32, &one_32),
+                                  ColumnPredicate::Range(column_d, &one_d, nullptr)),
+            0);
+  ASSERT_LT(SelectivityComparator(ColumnPredicate::Equality(column_i32, &one_32),
+                                  ColumnPredicate::IsNotNull(column_s)),
+            0);
+  ASSERT_LT(SelectivityComparator(ColumnPredicate::Range(column_i64, &one_64, nullptr),
+                                  ColumnPredicate::IsNotNull(column_i32)),
+            0);
+
+  // Size of column type
+  ASSERT_LT(SelectivityComparator(ColumnPredicate::Equality(column_i32, &one_32),
+                                  ColumnPredicate::Equality(column_i64, &one_64)),
+            0);
+  ASSERT_LT(SelectivityComparator(ColumnPredicate::Equality(column_i32, &one_32),
+                                  ColumnPredicate::Equality(column_d, &one_d)),
+            0);
+  ASSERT_LT(SelectivityComparator(ColumnPredicate::Equality(column_i32, &one_32),
+                                  ColumnPredicate::Equality(column_s, &one_s)),
+            0);
+  ASSERT_LT(SelectivityComparator(ColumnPredicate::Equality(column_i64, &one_64),
+                                  ColumnPredicate::Equality(column_s, &one_s)),
+            0);
+  ASSERT_LT(SelectivityComparator(ColumnPredicate::Equality(column_d, &one_d),
+                                  ColumnPredicate::Equality(column_s, &one_s)),
+            0);
+}
+
 } // namespace kudu

http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/a2e24ba5/src/kudu/common/column_predicate.cc
----------------------------------------------------------------------
diff --git a/src/kudu/common/column_predicate.cc b/src/kudu/common/column_predicate.cc
index e7aef58..9dc54b7 100644
--- a/src/kudu/common/column_predicate.cc
+++ b/src/kudu/common/column_predicate.cc
@@ -347,13 +347,15 @@ bool ColumnPredicate::operator==(const ColumnPredicate& other) const
{
 
 namespace {
 int SelectivityRank(const ColumnPredicate& predicate) {
+  int rank;
   switch (predicate.predicate_type()) {
-    case PredicateType::None: return 0;
-    case PredicateType::Equality: return 1;
-    case PredicateType::Range: return 2;
-    case PredicateType::IsNotNull: return 3;
+    case PredicateType::None: rank = 0; break;
+    case PredicateType::Equality: rank = 1; break;
+    case PredicateType::Range: rank = 2; break;
+    case PredicateType::IsNotNull: rank = 3; break;
+    default: LOG(FATAL) << "unknown predicate type";
   }
-  LOG(FATAL) << "unknown predicate type";
+  return rank * (kLargestTypeSize + 1) + predicate.column().type_info()->size();
 }
 } // anonymous namespace
 


Mime
View raw message