aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com>2024-05-21 13:59:26 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2024-05-21 13:59:26 +0000
commit8a43beade3a44fbd0276d9033f317fb4ab2ea8df (patch)
treeb9e00d3c7b49ee42a206f9205a300ae39dfe226f
parentefd8ac8e389ec2bac433edb72a61cd054d586994 (diff)
parent400b2e5ce121e67c6bbc2ebbfc233fc67abaca87 (diff)
downloadperfetto-main.tar.gz
Merge "tp: update sqlite3_vtab_distinct handling based on latest documentation" into mainHEADmastermain
-rw-r--r--src/trace_processor/sqlite/db_sqlite_table.cc5
-rw-r--r--test/trace_processor/diff_tests/syntax/table_tests.py31
2 files changed, 32 insertions, 4 deletions
diff --git a/src/trace_processor/sqlite/db_sqlite_table.cc b/src/trace_processor/sqlite/db_sqlite_table.cc
index 736af92d1..cc4f545da 100644
--- a/src/trace_processor/sqlite/db_sqlite_table.cc
+++ b/src/trace_processor/sqlite/db_sqlite_table.cc
@@ -54,9 +54,6 @@
namespace perfetto::trace_processor {
namespace {
-// TODO(b/341230981): Enable after it's fixed.
-static constexpr bool kEnableDistinct = false;
-
std::optional<FilterOp> SqliteOpToFilterOp(int sqlite_op) {
switch (sqlite_op) {
case SQLITE_INDEX_CONSTRAINT_EQ:
@@ -574,7 +571,7 @@ int DbSqliteModule::BestIndex(sqlite3_vtab* vtab, sqlite3_index_info* info) {
// Distinct:
idx_str += "D";
- if (ob_idxes.size() == 1 && kEnableDistinct) {
+ if (ob_idxes.size() == 1 && PERFETTO_POPCOUNT(info->colUsed) == 1) {
switch (sqlite3_vtab_distinct(info)) {
case 0:
case 1:
diff --git a/test/trace_processor/diff_tests/syntax/table_tests.py b/test/trace_processor/diff_tests/syntax/table_tests.py
index 7de63e9d4..5785b6f8a 100644
--- a/test/trace_processor/diff_tests/syntax/table_tests.py
+++ b/test/trace_processor/diff_tests/syntax/table_tests.py
@@ -178,6 +178,37 @@ class PerfettoTable(TestSuite):
3073,8,4529,8
"""))
+ def test_distinct_multi_column(self):
+ return DiffTestBlueprint(
+ trace=TextProto(''),
+ query="""
+ CREATE PERFETTO TABLE foo AS
+ WITH data(a, b) AS (
+ VALUES
+ -- Needed to defeat any id/sorted detection.
+ (2, 3),
+ (0, 2),
+ (0, 1)
+ )
+ SELECT * FROM data;
+
+ CREATE TABLE bar AS
+ SELECT 1 AS b;
+
+ WITH multi_col_distinct AS (
+ SELECT DISTINCT a FROM foo CROSS JOIN bar USING (b)
+ ), multi_col_group_by AS (
+ SELECT a FROM foo CROSS JOIN bar USING (b) GROUP BY a
+ )
+ SELECT
+ (SELECT COUNT(*) FROM multi_col_distinct) AS cnt_distinct,
+ (SELECT COUNT(*) FROM multi_col_group_by) AS cnt_group_by
+ """,
+ out=Csv("""
+ "cnt_distinct","cnt_group_by"
+ 1,1
+ """))
+
def test_limit(self):
return DiffTestBlueprint(
trace=TextProto(''),