Skip to content

Commit

Permalink
test: separate testcase for join_scan from sql_join_find_test
Browse files Browse the repository at this point in the history
  • Loading branch information
kuron99 committed Nov 14, 2024
1 parent aa0f5bf commit 943bd7a
Show file tree
Hide file tree
Showing 2 changed files with 363 additions and 60 deletions.
79 changes: 19 additions & 60 deletions test/jogasaki/api/sql_join_find_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ class sql_join_find_test :
db_teardown();
}
bool has_join_find(std::string_view query);
bool has_join_scan(std::string_view query);
bool uses_secondary(std::string_view query);
};

Expand All @@ -100,12 +99,6 @@ bool sql_join_find_test::has_join_find(std::string_view query) {
return contains(plan, "join_find");
}

bool sql_join_find_test::has_join_scan(std::string_view query) {
std::string plan{};
explain_statement(query, plan);
return contains(plan, "join_scan");
}

bool sql_join_find_test::uses_secondary(std::string_view query) {
std::string plan{};
explain_statement(query, plan);
Expand Down Expand Up @@ -263,71 +256,37 @@ TEST_F(sql_join_find_test, use_secondary_index_with_null) {
EXPECT_EQ((mock::create_nullable_record<kind::int4, kind::int4, kind::int4>(1, 11, 1)), result[0]);
}

TEST_F(sql_join_find_test, join_scan_simple) {
global::config_pool()->enable_join_scan(true);
execute_statement("CREATE TABLE t0 (c0 int)");
execute_statement("INSERT INTO t0 VALUES (1),(2)");
execute_statement("CREATE TABLE t1 (c0 int, c1 int, primary key(c0, c1))");
execute_statement("INSERT INTO t1 VALUES (1,10)");
TEST_F(sql_join_find_test, multiple_columns) {
execute_statement("CREATE TABLE t0 (c0 int, c1 bigint)");
execute_statement("INSERT INTO t0 VALUES (1,11),(2,12)");
execute_statement("CREATE TABLE t1 (c0 int, c1 bigint, c2 int, primary key(c0, c1))");
execute_statement("INSERT INTO t1 VALUES (1,10,100),(1,11,100),(2,20,200)");

auto query = "SELECT t0.c0, t1.c0, t1.c1 FROM t0 join t1 on t0.c0=t1.c0";
EXPECT_TRUE(has_join_scan(query));
auto query = "SELECT t0.c0, t0.c1, t1.c0, t1.c1, t1.c2 FROM t0 join t1 on t0.c0=t1.c0 and t0.c1=t1.c1";
EXPECT_TRUE(has_join_find(query));
std::vector<mock::basic_record> result{};
execute_query(query, result);
ASSERT_EQ(1, result.size());
EXPECT_EQ((mock::create_nullable_record<kind::int4, kind::int4, kind::int4>(1, 1, 10)), result[0]);
EXPECT_EQ((mock::create_nullable_record<kind::int4, kind::int8, kind::int4, kind::int8, kind::int4>(1,11,1,11,100)), result[0]);
}

TEST_F(sql_join_find_test, join_scan_secondary) {
global::config_pool()->enable_join_scan(true);
execute_statement("CREATE TABLE t0 (c0 int)");
execute_statement("INSERT INTO t0 VALUES (1),(2)");
execute_statement("CREATE TABLE t1 (c0 int, c1 int)");
TEST_F(sql_join_find_test, secondary_multiple_columns) {
// similar as multiple_columns but using secondary index (note we have more records in t1 since secondary index is not necessarily unique)
execute_statement("CREATE TABLE t0 (c0 int, c1 bigint)");
execute_statement("INSERT INTO t0 VALUES (1,11),(2,12)");
execute_statement("CREATE TABLE t1 (c0 int, c1 bigint, c2 int)");
execute_statement("CREATE INDEX i1 on t1 (c0, c1)");
execute_statement("INSERT INTO t1 VALUES (1,10)");
execute_statement("INSERT INTO t1 VALUES (1,10,100),(1,11,100),(1,11,101),(2,20,200)");

auto query = "SELECT t0.c0, t1.c0, t1.c1 FROM t0 join t1 on t0.c0=t1.c0";
EXPECT_TRUE(has_join_scan(query));
auto query = "SELECT t0.c0, t0.c1, t1.c0, t1.c1, t1.c2 FROM t0 join t1 on t0.c0=t1.c0 and t0.c1=t1.c1";
EXPECT_TRUE(has_join_find(query));
EXPECT_TRUE(uses_secondary(query));
std::vector<mock::basic_record> result{};
execute_query(query, result);
ASSERT_EQ(1, result.size());
EXPECT_EQ((mock::create_nullable_record<kind::int4, kind::int4, kind::int4>(1, 1, 10)), result[0]);
}

TEST_F(sql_join_find_test, join_scan_disabled) {
// verify fallback to shuffle join when join scan is disabled
global::config_pool()->enable_join_scan(false);
execute_statement("CREATE TABLE t0 (c0 int)");
execute_statement("INSERT INTO t0 VALUES (1),(2)");
execute_statement("CREATE TABLE t1 (c0 int, c1 int, primary key(c0, c1))");
execute_statement("INSERT INTO t1 VALUES (1,10)");

auto query = "SELECT t0.c0, t1.c0, t1.c1 FROM t0 join t1 on t0.c0=t1.c0";
EXPECT_TRUE(! has_join_scan(query));
std::vector<mock::basic_record> result{};
execute_query(query, result);
ASSERT_EQ(1, result.size());
EXPECT_EQ((mock::create_nullable_record<kind::int4, kind::int4, kind::int4>(1, 1, 10)), result[0]);
}

TEST_F(sql_join_find_test, join_scan_multiple_records) {
global::config_pool()->enable_join_scan(true);
execute_statement("CREATE TABLE t0 (c0 int)");
execute_statement("INSERT INTO t0 VALUES (1),(2)");
execute_statement("CREATE TABLE t1 (c0 int, c1 int, primary key(c0, c1))");
execute_statement("INSERT INTO t1 VALUES (1,10),(1,11),(2,20)");

auto query = "SELECT t0.c0, t1.c0, t1.c1 FROM t0 join t1 on t0.c0=t1.c0";
EXPECT_TRUE(has_join_scan(query));
std::vector<mock::basic_record> result{};
execute_query(query, result);
ASSERT_EQ(3, result.size());
ASSERT_EQ(2, result.size());
std::sort(result.begin(), result.end());
EXPECT_EQ((mock::create_nullable_record<kind::int4, kind::int4, kind::int4>(1, 1, 10)), result[0]);
EXPECT_EQ((mock::create_nullable_record<kind::int4, kind::int4, kind::int4>(1, 1, 11)), result[1]);
EXPECT_EQ((mock::create_nullable_record<kind::int4, kind::int4, kind::int4>(2, 2, 20)), result[2]);
EXPECT_EQ((mock::create_nullable_record<kind::int4, kind::int8, kind::int4, kind::int8, kind::int4>(1,11,1,11,100)), result[0]);
EXPECT_EQ((mock::create_nullable_record<kind::int4, kind::int8, kind::int4, kind::int8, kind::int4>(1,11,1,11,101)), result[1]);
}


}
Loading

0 comments on commit 943bd7a

Please sign in to comment.