Fixed error in system.tables #3982

This commit is contained in:
Alexey Milovidov 2019-02-08 17:10:26 +03:00
parent 2bc0ad3fdb
commit c2b6b15778
3 changed files with 22 additions and 6 deletions

View File

@ -173,8 +173,12 @@ protected:
for (; rows_count < max_block_size && tables_it->isValid(); tables_it->next())
{
++rows_count;
auto table_name = tables_it->name();
const auto table = context.tryGetTable(database_name, table_name);
if (!table)
continue;
++rows_count;
size_t src_index = 0;
size_t res_index = 0;
@ -253,11 +257,10 @@ protected:
else
src_index += 2;
const auto table_it = context.getTable(database_name, table_name);
ASTPtr expression_ptr;
if (columns_mask[src_index++])
{
if ((expression_ptr = table_it->getPartitionKeyAST()))
if ((expression_ptr = table->getPartitionKeyAST()))
res_columns[res_index++]->insert(queryToString(expression_ptr));
else
res_columns[res_index++]->insertDefault();
@ -265,7 +268,7 @@ protected:
if (columns_mask[src_index++])
{
if ((expression_ptr = table_it->getSortingKeyAST()))
if ((expression_ptr = table->getSortingKeyAST()))
res_columns[res_index++]->insert(queryToString(expression_ptr));
else
res_columns[res_index++]->insertDefault();
@ -273,7 +276,7 @@ protected:
if (columns_mask[src_index++])
{
if ((expression_ptr = table_it->getPrimaryKeyAST()))
if ((expression_ptr = table->getPrimaryKeyAST()))
res_columns[res_index++]->insert(queryToString(expression_ptr));
else
res_columns[res_index++]->insertDefault();
@ -281,7 +284,7 @@ protected:
if (columns_mask[src_index++])
{
if ((expression_ptr = table_it->getSamplingKeyAST()))
if ((expression_ptr = table->getSamplingKeyAST()))
res_columns[res_index++]->insert(queryToString(expression_ptr));
else
res_columns[res_index++]->insertDefault();

View File

@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -e
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
. $CURDIR/../shell_config.sh
$CLICKHOUSE_CLIENT -q "DROP TABLE IF EXISTS test.table"
seq 1 100 | sed -r -e "s/.+/CREATE TABLE test.table (x UInt8) ENGINE = MergeTree ORDER BY x; DROP TABLE test.table;/" | $CLICKHOUSE_CLIENT -n &
seq 1 1000 | sed -r -e "s/.+/SELECT * FROM system.tables WHERE database = 'test' LIMIT 1000000, 1;/" | $CLICKHOUSE_CLIENT -n &
wait