[information_schema](tables)modify information_schema.tables rows column use cache rows. (#27028)

Use the cached information and estimated information of the table in the rows column under 
information_schema.tables. Avoid querying information_schema.tables that will cause rpc timeout when there are a 
large number of tables in the catalog.
This commit is contained in:
daidai
2023-11-27 17:48:06 +08:00
committed by GitHub
parent 66eeafcd48
commit d5a56dc7f4
7 changed files with 40 additions and 1 deletions

View File

@ -1208,6 +1208,11 @@ public class OlapTable extends Table {
return rowCount;
}
@Override
public long getCacheRowCount() {
return getRowCount();
}
@Override
public long getAvgRowLength() {
long rowCount = 0;

View File

@ -344,6 +344,10 @@ public abstract class Table extends MetaObject implements Writable, TableIf {
return 0;
}
public long getCacheRowCount() {
return getRowCount();
}
public long getAvgRowLength() {
return 0;
}

View File

@ -121,6 +121,10 @@ public interface TableIf {
long getRowCount();
// Get the exact number of rows in the internal table;
// Get the number of cached rows or estimated rows in the external table, if not, return -1.
long getCacheRowCount();
long getDataLength();
long getAvgRowLength();

View File

@ -282,6 +282,10 @@ public class ExternalTable implements TableIf, Writable, GsonPostProcessable {
return 0;
}
public long getCacheRowCount() {
return 0;
}
@Override
public long getAvgRowLength() {
return 0;

View File

@ -452,6 +452,23 @@ public class HMSExternalTable extends ExternalTable {
return tmpSchema;
}
@Override
public long getCacheRowCount() {
//Cached accurate information
TableStatsMeta tableStats = Env.getCurrentEnv().getAnalysisManager().findTableStatsStatus(id);
if (tableStats != null) {
long rowCount = tableStats.rowCount;
LOG.debug("Estimated row count for db {} table {} is {}.", dbName, name, rowCount);
return rowCount;
}
//estimated information
if (estimatedRowCount != -1) {
return estimatedRowCount;
}
return -1;
}
@Override
public long estimatedRowCount() {
try {

View File

@ -122,6 +122,11 @@ public class JdbcExternalTable extends ExternalTable {
return 1;
}
@Override
public long getCacheRowCount() {
return getRowCount();
}
@Override
public long estimatedRowCount() {
return getRowCount();

View File

@ -747,7 +747,7 @@ public class FrontendServiceImpl implements FrontendService.Iface {
status.setUpdateTime(table.getUpdateTime() / 1000);
status.setCheckTime(lastCheckTime / 1000);
status.setCollation("utf-8");
status.setRows(table.getRowCount());
status.setRows(table.getCacheRowCount());
status.setDataLength(table.getDataLength());
status.setAvgRowLength(table.getAvgRowLength());
tablesResult.add(status);