Skip to content

Commit

Permalink
Bug#32169848 THD_NDB TRANSACTION FUNCTIONALITY [#16]
Browse files Browse the repository at this point in the history
Add counter for number of times table stats has been fetched from NDB.
Remove usage of execute, scan and purge counter from the function that
fetches table stats.
Keep counting one execute when fetching table stats.

Change-Id: I489babe9631e3c385ac8b49dfadc440cfe22fbaf
  • Loading branch information
blaudden committed May 19, 2021
1 parent aa81047 commit 6992585
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 11 deletions.
1 change: 1 addition & 0 deletions mysql-test/suite/ndb/r/ndb_basic.result
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ Ndb_conflict_trans_row_conflict_count #
Ndb_conflict_trans_row_reject_count #
Ndb_connect_count #
Ndb_execute_count #
Ndb_fetch_table_stats #
Ndb_index_stat_cache_clean #
Ndb_index_stat_cache_query #
Ndb_index_stat_event_count #
Expand Down
1 change: 1 addition & 0 deletions mysql-test/suite/ndb/r/ndb_basic_3rpl.result
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ Ndb_conflict_trans_row_conflict_count #
Ndb_conflict_trans_row_reject_count #
Ndb_connect_count #
Ndb_execute_count #
Ndb_fetch_table_stats #
Ndb_index_stat_cache_clean #
Ndb_index_stat_cache_query #
Ndb_index_stat_event_count #
Expand Down
1 change: 1 addition & 0 deletions mysql-test/suite/ndb/r/ndb_basic_4rpl.result
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ Ndb_conflict_trans_row_conflict_count #
Ndb_conflict_trans_row_reject_count #
Ndb_connect_count #
Ndb_execute_count #
Ndb_fetch_table_stats #
Ndb_index_stat_cache_clean #
Ndb_index_stat_cache_query #
Ndb_index_stat_event_count #
Expand Down
1 change: 1 addition & 0 deletions mysql-test/suite/ndb/r/ndb_basic_ndbd.result
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ Ndb_conflict_trans_row_conflict_count #
Ndb_conflict_trans_row_reject_count #
Ndb_connect_count #
Ndb_execute_count #
Ndb_fetch_table_stats #
Ndb_index_stat_cache_clean #
Ndb_index_stat_cache_query #
Ndb_index_stat_event_count #
Expand Down
29 changes: 29 additions & 0 deletions mysql-test/suite/ndbcluster/fetch_table_stats_count.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#
# Showing the "ndb_fetch_table_stats" counter
#
# Since fetching table stats incurs one roundtrip to NDB it should not
# be done more than strictly required, the "ndb_fetch_table_stats"
# counter provides a means to check when table stats are fetched.
CREATE TABLE t1 (a int primary key) ENGINE = NDB;
INSERT INTO t1 VALUES (1);
SELECT * FROM t1;
a
1
Table stats was fetched 1 time (expected 1)
# Another query using an open handler instance should not cause
# table stats to be fetched again
SELECT * FROM t1;
a
1
Table stats was fetched 0 times (expected 0)
# Closing handler, should really not need to fetch
# table stats again, but they seem to be
FLUSH TABLES t1;
Table stats was fetched 1 times (oops! expected 0)
# Running query again, should cause
# table stats to be fetched once again
SELECT * FROM t1;
a
1
Table stats was fetched 1 times (expected 1)
DROP TABLE t1;
56 changes: 56 additions & 0 deletions mysql-test/suite/ndbcluster/fetch_table_stats_count.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
--source include/have_ndb.inc

--echo #
--echo # Showing the "ndb_fetch_table_stats" counter
--echo #
--echo # Since fetching table stats incurs one roundtrip to NDB it should not
--echo # be done more than strictly required, the "ndb_fetch_table_stats"
--echo # counter provides a means to check when table stats are fetched.

CREATE TABLE t1 (a int primary key) ENGINE = NDB;

let $count =
`SELECT VARIABLE_VALUE
FROM performance_schema.session_status
WHERE variable_name = 'NDB_FETCH_TABLE_STATS'`;

INSERT INTO t1 VALUES (1);
SELECT * FROM t1;

let $count =
`SELECT VARIABLE_VALUE-$count
FROM performance_schema.session_status
WHERE variable_name = 'NDB_FETCH_TABLE_STATS'`;
echo Table stats was fetched $count time (expected 1);

--echo # Another query using an open handler instance should not cause
--echo # table stats to be fetched again
SELECT * FROM t1;

let $count =
`SELECT VARIABLE_VALUE-$count
FROM performance_schema.session_status
WHERE variable_name = 'NDB_FETCH_TABLE_STATS'`;
echo Table stats was fetched $count times (expected 0);

--echo # Closing handler, should really not need to fetch
--echo # table stats again, but they seem to be
FLUSH TABLES t1;

let $count =
`SELECT VARIABLE_VALUE-$count
FROM performance_schema.session_status
WHERE variable_name = 'NDB_FETCH_TABLE_STATS'`;
echo Table stats was fetched $count times (oops! expected 0);

--echo # Running query again, should cause
--echo # table stats to be fetched once again
SELECT * FROM t1;

let $count =
`SELECT VARIABLE_VALUE-$count
FROM performance_schema.session_status
WHERE variable_name = 'NDB_FETCH_TABLE_STATS'`;
echo Table stats was fetched $count times (expected 1);

DROP TABLE t1;
8 changes: 8 additions & 0 deletions storage/ndb/plugin/ha_ndbcluster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@ static int update_status_variables(Thd_ndb *thd_ndb, st_ndb_status *ns,
ns->api_client_stats[i] = thd_ndb->ndb->getClientStat(i);
}
ns->schema_locks_count = thd_ndb->schema_locks_count;
ns->fetch_table_stats = thd_ndb->m_fetch_table_stats;
}
return 0;
}
Expand Down Expand Up @@ -746,6 +747,8 @@ static SHOW_VAR ndb_status_vars_dynamic[] = {
SHOW_SCOPE_GLOBAL},
{"system_name", (char *)&g_ndb_status.system_name, SHOW_CHAR_PTR,
SHOW_SCOPE_GLOBAL},
{"fetch_table_stats", (char *)&g_ndb_status.fetch_table_stats, SHOW_LONG,
SHOW_SCOPE_GLOBAL},
{NullS, NullS, SHOW_LONG, SHOW_SCOPE_GLOBAL}};

static SHOW_VAR ndb_status_vars_slave[] = {
Expand Down Expand Up @@ -12881,6 +12884,11 @@ int ha_ndbcluster::update_stats(THD *thd, bool do_read_stat, uint part_id) {
table_stats = m_share->cached_table_stats;
mysql_mutex_unlock(&m_share->mutex);
} else {
// Count number of table stat fetches
thd_ndb->m_fetch_table_stats++;
// Count one execute for fetch of stats
thd_ndb->m_execute_count++;

// Request stats from NDB
NdbError ndb_error;
if (ndb_get_table_statistics(thd, thd_ndb->ndb, m_table, &table_stats,
Expand Down
1 change: 1 addition & 0 deletions storage/ndb/plugin/ha_ndbcluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ struct st_ndb_status {
long long last_commit_epoch_session;
long long api_client_stats[Ndb::NumClientStatistics];
const char *system_name;
long fetch_table_stats;
};

int ndbcluster_commit(handlerton *, THD *thd, bool all);
Expand Down
11 changes: 0 additions & 11 deletions storage/ndb/plugin/ndb_stats.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include "storage/ndb/include/ndbapi/NdbTransaction.hpp"
#include "storage/ndb/plugin/ndb_sleep.h"
#include "storage/ndb/plugin/ndb_thd.h"
#include "storage/ndb/plugin/ndb_thd_ndb.h"

// Empty mask for reading no attributes using NdbRecord, will be initialized
// to all zeros by linker.
Expand All @@ -41,8 +40,6 @@ bool ndb_get_table_statistics(THD *thd, Ndb *ndb,
const NdbDictionary::Table *ndbtab,
Ndb_table_stats *stats, NdbError &ndb_error,
Uint32 part_id) {
Thd_ndb *thd_ndb = get_thd_ndb(thd);

DBUG_TRACE;

Uint64 rows, fixed_mem, var_mem, ext_space, free_ext_space;
Expand Down Expand Up @@ -108,14 +105,6 @@ bool ndb_get_table_statistics(THD *thd, Ndb *ndb,
goto retry;
}

// NOTE! Updating scan and execute counters here when reading statistics is
// a little bit unusual, probably better not to count here or use separate
// "fetch stats" counter.
thd_ndb->m_scan_count++;
thd_ndb->m_pruned_scan_count += (pOp->getPruned() ? 1 : 0);

thd_ndb->m_execute_count++;
DBUG_PRINT("info", ("execute_count: %u", thd_ndb->m_execute_count));
if (trans->execute(NdbTransaction::NoCommit, NdbOperation::AbortOnError,
1 /* force send */) == -1) {
ndb_error = trans->getNdbError();
Expand Down
3 changes: 3 additions & 0 deletions storage/ndb/plugin/ndb_thd_ndb.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ class Thd_ndb {
void increment_hinted_trans_count() { m_hinted_trans_count++; }
uint hinted_trans_count() const { return m_hinted_trans_count; }

// Number of times that table stats has been fetched from NDB
uint m_fetch_table_stats{0};

NdbTransaction *global_schema_lock_trans;
uint global_schema_lock_count;
uint global_schema_lock_error;
Expand Down

0 comments on commit 6992585

Please sign in to comment.