From 3d9a37f28fe413bb310059eb4d8d401e032d24b1 Mon Sep 17 00:00:00 2001 From: Piotr Sarna Date: Mon, 17 Jun 2019 11:51:37 +0200 Subject: [PATCH] tests: add indexing + paging + aggregation test case Indexed queries used to erroneously return partial per-page results for aggregation queries. This test case used to reproduce the problem and now ensures that there would be no regressions. Refs #4540 --- tests/secondary_index_test.cc | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/secondary_index_test.cc b/tests/secondary_index_test.cc index f1437d7a43..10e856c140 100644 --- a/tests/secondary_index_test.cc +++ b/tests/secondary_index_test.cc @@ -28,6 +28,7 @@ #include "types/list.hh" #include "types/set.hh" #include "exception_utils.hh" +#include "cql3/statements/select_statement.hh" SEASTAR_TEST_CASE(test_secondary_index_regular_column_query) { @@ -1132,3 +1133,37 @@ SEASTAR_TEST_CASE(test_secondary_index_on_partition_key_with_filtering) { }); }); } + +SEASTAR_TEST_CASE(test_indexing_paging_and_aggregation) { + static constexpr int row_count = 2 * cql3::statements::select_statement::DEFAULT_COUNT_PAGE_SIZE + 120; + + return do_with_cql_env_thread([] (cql_test_env& e) { + cquery_nofail(e, "CREATE TABLE fpa (id int primary key, v int)"); + cquery_nofail(e, "CREATE INDEX ON fpa(v)"); + for (int i = 0; i < row_count; ++i) { + cquery_nofail(e, format("INSERT INTO fpa (id, v) VALUES ({}, {})", i + 1, i % 2).c_str()); + } + + auto qo = std::make_unique(db::consistency_level::LOCAL_ONE, infinite_timeout_config, std::vector{}, + cql3::query_options::specific_options{2, nullptr, {}, api::new_timestamp()}); + auto msg = cquery_nofail(e, "SELECT sum(id) FROM fpa WHERE v = 0;", std::move(qo)); + // Even though we set up paging, we still expect a single result from an aggregation function. + // Also, instead of the user-provided page size, internal DEFAULT_COUNT_PAGE_SIZE is expected to be used. + assert_that(msg).is_rows().with_rows({ + { int32_type->decompose(row_count * row_count / 4)}, + }); + + // Even if paging is not explicitly used, the query will be internally paged to avoid OOM. + msg = cquery_nofail(e, "SELECT sum(id) FROM fpa WHERE v = 1;"); + assert_that(msg).is_rows().with_rows({ + { int32_type->decompose(row_count * row_count / 4 + row_count / 2)}, + }); + + qo = std::make_unique(db::consistency_level::LOCAL_ONE, infinite_timeout_config, std::vector{}, + cql3::query_options::specific_options{3, nullptr, {}, api::new_timestamp()}); + msg = cquery_nofail(e, "SELECT avg(id) FROM fpa WHERE v = 1;", std::move(qo)); + assert_that(msg).is_rows().with_rows({ + { int32_type->decompose(row_count / 2 + 1)}, + }); + }); +}