Skip to content
This repository was archived by the owner on Mar 1, 2026. It is now read-only.

Commit 9cc489f

Browse files
sunshine-Chunfacebook-github-bot
authored andcommitted
fix the issue of 0 io_write issue when operating on partition table
Summary: For partition tables, there are missing some info in the performance schema table. They are io_write_bytes, io_write_requests, io_read_bytes and io_read_requests.The current return value of these field are 0, which is not the correct value. In this diff, the issue of 0 return value is fixed. Reviewed By: luqun Differential Revision: D38227596 fbshipit-source-id: c561b33
1 parent 2bcb464 commit 9cc489f

7 files changed

Lines changed: 106 additions & 4 deletions

File tree

‎mysql-test/suite/rocksdb/r/bytes_written.result‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,16 @@ io_write > 0 io_write_requests
1111
1 2
1212
DROP TABLE stats_test_table;
1313
SET GLOBAL rocksdb_perf_context_level=DEFAULT;
14+
DROP TABLE IF EXISTS partition_table;
15+
SET GLOBAL rocksdb_perf_context_level=3;
16+
CREATE TABLE partition_table(a int, b int , c int) PARTITION BY RANGE (b) (PARTITION p0 VALUES LESS THAN (10), PARTITION p1 VALUES LESS THAN (20), PARTITION p2 VALUES LESS THAN (50));
17+
INSERT INTO partition_table VALUES (12,12,12);
18+
SELECT table_schema AS db, sum(io_write) AS bytes_written FROM sys.fb_ps_schema_table_statistics_io WHERE table_schema = "test" AND table_name = "partition_table" GROUP BY 1;
19+
db bytes_written
20+
test 25
21+
INSERT INTO partition_table VALUES (25,25,25);
22+
SELECT table_schema AS db, sum(io_write) AS bytes_written FROM sys.fb_ps_schema_table_statistics_io WHERE table_schema = "test" AND table_name = "partition_table" GROUP BY 1;
23+
db bytes_written
24+
test 50
25+
DROP TABLE partition_table;
26+
SET GLOBAL rocksdb_perf_context_level=DEFAULT;

‎mysql-test/suite/rocksdb/t/bytes_written.test‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,34 @@ SELECT io_write > 0, io_write_requests FROM sys.fb_ps_schema_table_statistics_io
2222
# Cleanup
2323
DROP TABLE stats_test_table;
2424
SET GLOBAL rocksdb_perf_context_level=DEFAULT;
25+
26+
27+
#########################################
28+
## Test io_write of partition table
29+
#########################################
30+
31+
--disable_warnings
32+
DROP TABLE IF EXISTS partition_table;
33+
--enable_warnings
34+
35+
# Ensure appropriate perf_context_level is set
36+
SET GLOBAL rocksdb_perf_context_level=3;
37+
38+
# Create a partition table
39+
CREATE TABLE partition_table(a int, b int , c int) PARTITION BY RANGE (b) (PARTITION p0 VALUES LESS THAN (10), PARTITION p1 VALUES LESS THAN (20), PARTITION p2 VALUES LESS THAN (50));
40+
41+
# Insert a row into table
42+
INSERT INTO partition_table VALUES (12,12,12);
43+
44+
# Check the io_write
45+
SELECT table_schema AS db, sum(io_write) AS bytes_written FROM sys.fb_ps_schema_table_statistics_io WHERE table_schema = "test" AND table_name = "partition_table" GROUP BY 1;
46+
47+
# Insert more values
48+
INSERT INTO partition_table VALUES (25,25,25);
49+
50+
# Check the io_write
51+
SELECT table_schema AS db, sum(io_write) AS bytes_written FROM sys.fb_ps_schema_table_statistics_io WHERE table_schema = "test" AND table_name = "partition_table" GROUP BY 1;
52+
53+
# Cleanup
54+
DROP TABLE partition_table;
55+
SET GLOBAL rocksdb_perf_context_level=DEFAULT;

‎sql/partitioning/partition_base.cc‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3082,6 +3082,15 @@ int Partition_base::info(uint flag) {
30823082
DBUG_RETURN(error);
30833083
}
30843084

3085+
void Partition_base::reset_partition_io_counters() {
3086+
for (uint i = m_part_info->get_first_used_partition(); i < m_tot_parts;
3087+
i = m_part_info->get_next_used_partition(i)) {
3088+
handler *file = m_file[i];
3089+
assert(bitmap_is_set(&(m_part_info->read_partitions), i));
3090+
file->stats.reset_io_counters();
3091+
}
3092+
}
3093+
30853094
void Partition_base::get_dynamic_partition_info(ha_statistics *stat_info,
30863095
ha_checksum *check_sum,
30873096
uint part_id) {
@@ -3099,11 +3108,28 @@ void Partition_base::get_dynamic_partition_info(ha_statistics *stat_info,
30993108
stat_info->create_time = static_cast<ulong>(file->stats.create_time);
31003109
stat_info->update_time = file->stats.update_time;
31013110
stat_info->check_time = file->stats.check_time;
3111+
stat_info->io_write_bytes = file->stats.io_write_bytes;
3112+
stat_info->io_write_requests = file->stats.io_write_requests;
3113+
stat_info->io_read_bytes = file->stats.io_read_bytes;
3114+
stat_info->io_read_requests = file->stats.io_read_requests;
31023115
*check_sum = 0;
31033116
if (file->ha_table_flags() & HA_HAS_CHECKSUM) *check_sum = file->checksum();
31043117
return;
31053118
}
31063119

3120+
void Partition_base::get_partitions_io_write_stats(ha_statistics *ha_stat) {
3121+
ha_statistics ha_part_stat;
3122+
ha_checksum check_sum = 0;
3123+
for (uint i = m_part_info->get_first_used_partition(); i < m_tot_parts;
3124+
i = m_part_info->get_next_used_partition(i)) {
3125+
get_dynamic_partition_info(&ha_part_stat, &check_sum, i);
3126+
ha_stat->io_write_bytes += ha_part_stat.io_write_bytes;
3127+
ha_stat->io_write_requests += ha_part_stat.io_write_requests;
3128+
ha_stat->io_read_bytes += ha_part_stat.io_read_bytes;
3129+
ha_stat->io_read_requests += ha_part_stat.io_read_requests;
3130+
}
3131+
}
3132+
31073133
/**
31083134
General function to prepare handler for certain behavior.
31093135

‎sql/partitioning/partition_base.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,8 @@ class Partition_base : public handler,
456456
void get_dynamic_partition_info(ha_statistics *stat_info,
457457
ha_checksum *check_sum,
458458
uint part_id) override;
459+
void get_partitions_io_write_stats(ha_statistics *ha_stat) override;
460+
void reset_partition_io_counters() override;
459461
int extra(enum ha_extra_function operation) override;
460462
int reset(void) override;
461463

‎sql/partitioning/partition_handler.h‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,20 @@ class Partition_handler {
208208
virtual void get_dynamic_partition_info(ha_statistics *stat_info,
209209
ha_checksum *check_sum,
210210
uint part_id) = 0;
211+
212+
/**
213+
Get the statistics of partition tables
214+
*/
215+
virtual void get_partitions_io_write_stats(
216+
ha_statistics *ha_stat MY_ATTRIBUTE((unused))) {
217+
return;
218+
}
219+
220+
/**
221+
Set the io counters of partition tables
222+
*/
223+
virtual void reset_partition_io_counters() { return; }
224+
211225
/**
212226
Get default number of partitions.
213227

‎sql/sql_base.cc‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
#include "sql/mysqld_thd_manager.h" // Global_THD_manage
110110
#include "sql/nested_join.h"
111111
#include "sql/partition_info.h" // partition_info
112+
#include "sql/partitioning/partition_handler.h"
112113
#include "sql/psi_memory_key.h" // key_memory_TABLE
113114
#include "sql/query_options.h"
114115
#include "sql/rpl_gtid.h"
@@ -3380,6 +3381,13 @@ retry_share : {
33803381
/* Call rebind_psi outside of the critical section. */
33813382
assert(table->file != nullptr);
33823383
table->file->stats.reset_io_counters();
3384+
assert(table->file != nullptr);
3385+
Partition_handler *part_handler = table->file->get_partition_handler();
3386+
if (part_handler) {
3387+
part_handler->reset_partition_io_counters();
3388+
} else {
3389+
table->file->stats.reset_io_counters();
3390+
}
33833391
table->file->rebind_psi();
33843392
table->file->ha_extra(HA_EXTRA_RESET_STATE);
33853393

‎storage/perfschema/pfs.cc‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
#include "pfs_thread_provider.h"
9898
#include "pfs_transaction_provider.h"
9999
#include "sql/mdl.h" /* mdl_key_init */
100+
#include "sql/partitioning/partition_base.h"
100101
#include "sql/sp_head.h"
101102
#include "sql/sql_class.h" // THD
102103
#include "sql/sql_const.h"
@@ -2743,13 +2744,20 @@ void pfs_unbind_table_v1(PSI_table *table) {
27432744
assert(pfs->m_identity);
27442745
const handler *h = reinterpret_cast<const handler *>(pfs->m_identity);
27452746
if (h != nullptr) {
2747+
Partition_handler *part_handler =
2748+
const_cast<handler *>(h)->get_partition_handler();
2749+
2750+
ha_statistics ha_stat = h->stats;
2751+
if (part_handler) {
2752+
part_handler->get_partitions_io_write_stats(&ha_stat);
2753+
}
27462754
query_stat->m_io_write_bytes.aggregate_counted(
2747-
h->stats.io_write_bytes);
2755+
ha_stat.io_write_bytes);
27482756
query_stat->m_io_write_requests.aggregate_counted(
2749-
h->stats.io_write_requests);
2750-
query_stat->m_io_read_bytes.aggregate_counted(h->stats.io_read_bytes);
2757+
ha_stat.io_write_requests);
2758+
query_stat->m_io_read_bytes.aggregate_counted(ha_stat.io_read_bytes);
27512759
query_stat->m_io_read_requests.aggregate_counted(
2752-
h->stats.io_read_requests);
2760+
ha_stat.io_read_requests);
27532761
}
27542762
}
27552763
}

0 commit comments

Comments
 (0)