cql3: single metric for range scan and full scan

Combining both range and full table scans in a single metric as
"partition range scans are used to implement full scans in scylla deployments."
Requested by @bdenes and @avi

Refs: #5209

Signed-off-by: Alejo Sanchez <alejo.sanchez@scylladb.com>
Message-Id: <20200211101221.690031-2-alejo.sanchez@scylladb.com>
This commit is contained in:
Alejo Sanchez
2020-02-11 11:12:21 +01:00
committed by Avi Kivity
parent c8348bccc9
commit 45a6cc5d53
5 changed files with 33 additions and 43 deletions

View File

@@ -413,21 +413,16 @@ query_processor::query_processor(service::storage_proxy& proxy, database& db, se
_cql_stats.select_allow_filtering,
sm::description("Counts the number of SELECT query executions with ALLOW FILTERING option.")),
sm::make_derive(
"select_full_scan",
_cql_stats.select_full_scan,
sm::description("Counts the number of SELECT query executions requiring full scan.")),
sm::make_derive(
"select_full_scan_no_bypass_cache",
_cql_stats.select_full_scan_no_bypass_cache,
sm::description("Counts the number of SELECT query executions requiring full scan without BYPASS CACHE option.")),
sm::make_derive(
"select_partition_range_scan",
_cql_stats.select_partition_range_scan,
sm::description("Counts the number of SELECT query executions requiring partition range scan.")),
sm::make_derive(
"select_partition_range_scan_no_bypass_cache",
_cql_stats.select_partition_range_scan_no_bypass_cache,
sm::description("Counts the number of SELECT query executions requiring partition range scan without BYPASS CACHE option.")),
sm::make_derive(
"authorized_prepared_statements_cache_evictions",
[] { return authorized_prepared_statements_cache::shard_stats().authorized_prepared_statements_cache_evictions; },

View File

@@ -316,9 +316,8 @@ select_statement::do_execute(service::storage_proxy& proxy,
_stats.select_bypass_caches += _parameters->bypass_cache();
_stats.select_allow_filtering += _parameters->allow_filtering();
_stats.select_full_scan += _full_scan;
_stats.select_full_scan_no_bypass_cache += _full_scan_no_bypass_cache;
_stats.select_partition_range_scan += _range_scan;
_stats.select_partition_range_scan_no_bypass_cache += _range_scan_no_bypass_cache;
auto command = ::make_lw_shared<query::read_command>(_schema->id(), _schema->version(),
make_partition_slice(options), limit, now, tracing::make_trace_info(state.get_trace_state()), query::max_partitions, utils::UUID(), options.get_timestamp(state));
@@ -734,14 +733,12 @@ primary_key_select_statement::primary_key_select_statement(schema_ptr schema, ui
{
if (_ks_sel == ks_selector::NONSYSTEM) {
if (_restrictions->need_filtering() ||
_restrictions->get_partition_key_restrictions()->empty()) {
_full_scan = true; // Filtered (unindexed) or unrestricted PK
_restrictions->get_partition_key_restrictions()->empty() ||
(_restrictions->get_partition_key_restrictions()->is_on_token() &&
!_restrictions->get_partition_key_restrictions()->is_EQ())) {
_range_scan = true;
if (!_parameters->bypass_cache())
_full_scan_no_bypass_cache = true;
} else {
if (_restrictions->get_partition_key_restrictions()->is_on_token() &&
!_restrictions->get_partition_key_restrictions()->is_EQ())
_range_scan = true; // Token range
_range_scan_no_bypass_cache = true;
}
}
}

View File

@@ -94,9 +94,8 @@ protected:
query::partition_slice::option_set _opts;
cql_stats& _stats;
const ks_selector _ks_sel;
bool _full_scan = false;
bool _full_scan_no_bypass_cache = false;
bool _range_scan = false;
bool _range_scan_no_bypass_cache = false;
protected :
virtual future<::shared_ptr<cql_transport::messages::result_message>> do_execute(service::storage_proxy& proxy,
service::query_state& state, const query_options& options) const;

View File

@@ -87,9 +87,8 @@ struct cql_stats {
int64_t select_bypass_caches = 0;
int64_t select_allow_filtering = 0;
int64_t select_full_scan = 0;
int64_t select_full_scan_no_bypass_cache = 0;
int64_t select_partition_range_scan = 0;
int64_t select_partition_range_scan_no_bypass_cache = 0;
private:
uint64_t _unpaged_select_queries[(size_t)ks_selector::SIZE] = {0ul};

View File

@@ -319,50 +319,50 @@ SEASTAR_TEST_CASE(test_select_full_scan_metrics) {
BOOST_CHECK_EQUAL(stat_ac1 + 1, qp.get_cql_stats().select_allow_filtering);
// Unrestricted PK, full scan without BYPASS CACHE
auto stat_fs1 = qp.get_cql_stats().select_full_scan;
auto stat_fsnb1 = qp.get_cql_stats().select_full_scan_no_bypass_cache;
auto stat_ps1 = qp.get_cql_stats().select_partition_range_scan;
auto stat_psnb1 = qp.get_cql_stats().select_partition_range_scan_no_bypass_cache;
qp.execute_internal("select * from ks.fsm;").get();
BOOST_CHECK_EQUAL(stat_fs1 + 1, qp.get_cql_stats().select_full_scan);
BOOST_CHECK_EQUAL(stat_fsnb1 + 1, qp.get_cql_stats().select_full_scan_no_bypass_cache);
BOOST_CHECK_EQUAL(stat_ps1 + 1, qp.get_cql_stats().select_partition_range_scan);
BOOST_CHECK_EQUAL(stat_psnb1 + 1, qp.get_cql_stats().select_partition_range_scan_no_bypass_cache);
// Unrestricted PK, full scan with BYPASS CACHE
auto stat_fsnb2 = qp.get_cql_stats().select_full_scan_no_bypass_cache;
auto stat_psnb2 = qp.get_cql_stats().select_partition_range_scan_no_bypass_cache;
qp.execute_internal("select * from ks.fsm BYPASS CACHE;").get();
BOOST_CHECK_EQUAL(stat_fsnb2, qp.get_cql_stats().select_full_scan_no_bypass_cache);
BOOST_CHECK_EQUAL(stat_psnb2, qp.get_cql_stats().select_partition_range_scan_no_bypass_cache);
// Restricted PK, no full scan
auto stat_fs2 = qp.get_cql_stats().select_full_scan;
auto stat_ps2 = qp.get_cql_stats().select_partition_range_scan;
qp.execute_internal("select * from ks.fsm where pk = 1;").get();
BOOST_CHECK_EQUAL(stat_fs2, qp.get_cql_stats().select_full_scan);
BOOST_CHECK_EQUAL(stat_ps2, qp.get_cql_stats().select_partition_range_scan);
// Indexed on c1, no full scan
auto stat_fs3 = qp.get_cql_stats().select_full_scan;
auto stat_ps3 = qp.get_cql_stats().select_partition_range_scan;
qp.execute_internal("select * from ks.fsm where c1 = 1;").get();
BOOST_CHECK_EQUAL(stat_fs3, qp.get_cql_stats().select_full_scan);
BOOST_CHECK_EQUAL(stat_ps3, qp.get_cql_stats().select_partition_range_scan);
// Filtered by ck but not filtered by pk
auto stat_fs4 = qp.get_cql_stats().select_full_scan;
auto stat_ps4 = qp.get_cql_stats().select_partition_range_scan;
qp.execute_internal("select * from ks.fsm where ck = 1 allow filtering;").get();
BOOST_CHECK_EQUAL(stat_fs4 + 1, qp.get_cql_stats().select_full_scan);
BOOST_CHECK_EQUAL(stat_ps4 + 1, qp.get_cql_stats().select_partition_range_scan);
// Filtered by unindexed non-cluster column
auto stat_fs5 = qp.get_cql_stats().select_full_scan;
auto stat_ps5 = qp.get_cql_stats().select_partition_range_scan;
qp.execute_internal("select * from ks.fsm where c2 = 1 allow filtering;").get();
BOOST_CHECK_EQUAL(stat_fs5 + 1, qp.get_cql_stats().select_full_scan);
BOOST_CHECK_EQUAL(stat_ps5 + 1, qp.get_cql_stats().select_partition_range_scan);
// System table full scan, not measured
auto stat_fs6 = qp.get_cql_stats().select_full_scan;
auto stat_ps6 = qp.get_cql_stats().select_partition_range_scan;
qp.execute_internal("select * from system.views_builds_in_progress;").get();
BOOST_CHECK_EQUAL(stat_fs6, qp.get_cql_stats().select_full_scan);
BOOST_CHECK_EQUAL(stat_ps6, qp.get_cql_stats().select_partition_range_scan);
// Range token on PK, full scan
auto stat_rs1 = qp.get_cql_stats().select_partition_range_scan;
auto stat_ps7 = qp.get_cql_stats().select_partition_range_scan;
qp.execute_internal("select * from ks.fsm where token(pk) > 100;").get();
BOOST_CHECK_EQUAL(stat_rs1 + 1, qp.get_cql_stats().select_partition_range_scan);
BOOST_CHECK_EQUAL(stat_ps7 + 1, qp.get_cql_stats().select_partition_range_scan);
// Token on PK equals, no full scan
auto stat_rs2 = qp.get_cql_stats().select_partition_range_scan;
auto stat_ps8 = qp.get_cql_stats().select_partition_range_scan;
qp.execute_internal("select * from ks.fsm where token(pk) = 1;").get();
BOOST_CHECK_EQUAL(stat_rs2, qp.get_cql_stats().select_partition_range_scan);
BOOST_CHECK_EQUAL(stat_ps8, qp.get_cql_stats().select_partition_range_scan);
});
}