Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

infoschema: fix regression on select table_rows from information_schema.tables for partition table #51980

Merged
merged 3 commits into from Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 13 additions & 3 deletions pkg/executor/infoschema_reader.go
Expand Up @@ -638,9 +638,19 @@ func (e *memtableRetriever) setDataFromTables(sctx sessionctx.Context, schemas [

var rowCount, avgRowLength, dataLength, indexLength uint64
if useStatsCache {
err := cache.TableRowStatsCache.UpdateByID(sctx, table.ID)
if err != nil {
return err
if table.GetPartitionInfo() == nil {
err := cache.TableRowStatsCache.UpdateByID(sctx, table.ID)
if err != nil {
return err
}
} else {
// needs to update all partitions for partition table.
for _, pi := range table.GetPartitionInfo().Definitions {
err := cache.TableRowStatsCache.UpdateByID(sctx, pi.ID)
if err != nil {
return err
}
}
}
rowCount, avgRowLength, dataLength, indexLength = fetchColumnsFromStatsCache(table)
}
Expand Down
10 changes: 10 additions & 0 deletions tests/integrationtest/r/executor/infoschema_reader.result
Expand Up @@ -318,3 +318,13 @@ tidb_mem_oom_action
tidb_pessimistic_txn_fair_locking
tidb_row_format_version
tidb_txn_assertion_level
drop table if exists t;
CREATE TABLE t (a int, b int, c varchar(5), primary key(a), index idx(c)) PARTITION BY RANGE (a) (PARTITION p0 VALUES LESS THAN (6), PARTITION p1 VALUES LESS THAN (11), PARTITION p2 VALUES LESS THAN (16));
insert into t(a, b, c) values(1, 2, 'c'), (7, 3, 'd'), (12, 4, 'e');
analyze table t;
select sleep(1);
sleep(1)
0
select table_rows, avg_row_length, data_length, index_length from information_schema.tables where table_name='t' AND TABLE_SCHEMA='executor__infoschema_reader';
table_rows avg_row_length data_length index_length
3 18 54 6
9 changes: 9 additions & 0 deletions tests/integrationtest/t/executor/infoschema_reader.test
Expand Up @@ -253,3 +253,12 @@ set global tidb_txn_assertion_level = default;
set global tidb_enable_mutation_checker = default;
set global tidb_pessimistic_txn_fair_locking = default;
select a.VARIABLE_NAME from information_schema.VARIABLES_INFO as a, mysql.GLOBAL_VARIABLES as b where a.VARIABLE_NAME = b.VARIABLE_NAME and a.DEFAULT_VALUE = b.VARIABLE_VALUE and a.CURRENT_VALUE = b.VARIABLE_VALUE and a.variable_name in ('tidb_enable_async_commit','tidb_enable_1pc', 'tidb_mem_oom_action', 'tidb_enable_auto_analyze', 'tidb_row_format_version', 'tidb_txn_assertion_level', 'tidb_enable_mutation_checker', 'tidb_pessimistic_txn_fair_locking') order by VARIABLE_NAME;


# test issue51942
drop table if exists t;
CREATE TABLE t (a int, b int, c varchar(5), primary key(a), index idx(c)) PARTITION BY RANGE (a) (PARTITION p0 VALUES LESS THAN (6), PARTITION p1 VALUES LESS THAN (11), PARTITION p2 VALUES LESS THAN (16));
insert into t(a, b, c) values(1, 2, 'c'), (7, 3, 'd'), (12, 4, 'e');
analyze table t;
select sleep(1);
select table_rows, avg_row_length, data_length, index_length from information_schema.tables where table_name='t' AND TABLE_SCHEMA='executor__infoschema_reader';