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

Data Skipping Indices #4143

Merged
merged 155 commits into from
Feb 5, 2019
Merged
Show file tree
Hide file tree
Changes from 153 commits
Commits
Show all changes
155 commits
Select commit Hold shift + click to select a range
6f98649
made index parser
nikvas0 Dec 25, 2018
fcd49af
added index parsing
nikvas0 Dec 25, 2018
36083e1
some fixes
nikvas0 Dec 25, 2018
04a8ea8
added index interface and factory
nikvas0 Dec 26, 2018
b62197b
fixed compilation
nikvas0 Dec 26, 2018
c89df91
ptrs
nikvas0 Dec 26, 2018
9818d27
Merge pull request #1 from nikvas0/nikvas0/index_creation
nikvas0 Dec 26, 2018
9bf5b6b
added indexParts
nikvas0 Dec 28, 2018
06d8416
indextypes
nikvas0 Dec 28, 2018
68c3879
index condition
nikvas0 Dec 29, 2018
5079330
IndexCondition
nikvas0 Dec 29, 2018
f90cdca
added indexes in selectexecutor
nikvas0 Dec 29, 2018
33cf4c9
fix
nikvas0 Dec 29, 2018
ad2a453
changed comment
nikvas0 Dec 29, 2018
1b7c0ae
fix
nikvas0 Jan 2, 2019
f704a32
added granularity
nikvas0 Jan 2, 2019
b2da3a3
comments
nikvas0 Jan 2, 2019
69052b3
fix
nikvas0 Jan 3, 2019
35dbb94
fix
nikvas0 Jan 3, 2019
92a850c
added writing indexes
nikvas0 Jan 4, 2019
f927502
removed indexpart class
nikvas0 Jan 4, 2019
1c80628
fix
nikvas0 Jan 5, 2019
82cc39d
added setSkipIndexes
nikvas0 Jan 5, 2019
61b9c77
add rw for MergeTreeIndexes
nikvas0 Jan 5, 2019
c3f1784
fixes
nikvas0 Jan 5, 2019
83368a4
upd error
nikvas0 Jan 6, 2019
7e0e301
fix
nikvas0 Jan 6, 2019
f345941
Merge pull request #2 from nikvas0/nikvas0/index_stream
nikvas0 Jan 6, 2019
e95376e
Merge branch 'master' into nikvas0/index
nikvas0 Jan 6, 2019
17f6618
fix
nikvas0 Jan 6, 2019
11d37ef
reading
nikvas0 Jan 7, 2019
6871665
test index
nikvas0 Jan 7, 2019
69c6e77
fixed nullptr error
nikvas0 Jan 7, 2019
76c25c2
fixed
nikvas0 Jan 7, 2019
3cad26d
Merge pull request #3 from nikvas0/nikvas0/index_read
nikvas0 Jan 7, 2019
541c641
fix
nikvas0 Jan 7, 2019
48e136f
unique names
nikvas0 Jan 8, 2019
d1e2ab8
asts -> exprlist
nikvas0 Jan 8, 2019
15ee9e1
Merge pull request #4 from nikvas0/nikvas0/fix-double-index
nikvas0 Jan 8, 2019
49148ac
minmax index
nikvas0 Jan 8, 2019
ad4df16
fix
nikvas0 Jan 8, 2019
6eeed48
fixed select
nikvas0 Jan 8, 2019
e580180
fixed merging
nikvas0 Jan 9, 2019
91fb17f
fixed mutation
nikvas0 Jan 9, 2019
1e8fa5d
working minmax
nikvas0 Jan 9, 2019
d8f8b63
removed test index
nikvas0 Jan 9, 2019
0536711
Merge pull request #5 from nikvas0/nikvas0/minmax
nikvas0 Jan 9, 2019
10355ae
Merge remote-tracking branch 'upstream/master' into nikvas0/index
nikvas0 Jan 9, 2019
0ba6f14
fixed style
nikvas0 Jan 9, 2019
d9b7f30
added indexes to checkDataPart
nikvas0 Jan 9, 2019
6490c23
added tests for minmax index
nikvas0 Jan 10, 2019
3f8c2ad
fixed constructor
nikvas0 Jan 10, 2019
634d5eb
fix style
nikvas0 Jan 10, 2019
701627e
fixed includes
nikvas0 Jan 10, 2019
0c18e73
Merge remote-tracking branch 'upstream/master' into nikvas0/index
nikvas0 Jan 10, 2019
d310d1a
fixed setSkipIndexes
nikvas0 Jan 10, 2019
89b831e
added indexes meta to zookeeper
nikvas0 Jan 10, 2019
4d4af73
Merge pull request #6 from nikvas0/nikvas0/index_replication
nikvas0 Jan 10, 2019
e288022
Merge remote-tracking branch 'upstream/master' into nikvas0/index
nikvas0 Jan 13, 2019
183ddea
added parsing
nikvas0 Jan 13, 2019
4f48ebd
removed throw
nikvas0 Jan 13, 2019
d0db87b
alter cmds parse
nikvas0 Jan 13, 2019
e197697
fix
nikvas0 Jan 13, 2019
026a300
added alter
nikvas0 Jan 15, 2019
2f07e31
fix
nikvas0 Jan 15, 2019
b110738
alters fix
nikvas0 Jan 15, 2019
8c35ccd
fix alters
nikvas0 Jan 16, 2019
65539bf
fix "after"
nikvas0 Jan 16, 2019
f937048
Merge pull request #7 from nikvas0/nikvas0/index_alter
nikvas0 Jan 16, 2019
2de2b6f
fixed alter
nikvas0 Jan 16, 2019
b4ce03e
alter fix + test
nikvas0 Jan 16, 2019
08d23c1
fixes
nikvas0 Jan 16, 2019
579832f
upd setSkipIndexes
nikvas0 Jan 16, 2019
62dde8c
fixed alter bug with drop all indices
nikvas0 Jan 16, 2019
f8fa36c
fix metadata editing
nikvas0 Jan 16, 2019
062819f
new test and repl fix
nikvas0 Jan 17, 2019
59cb1cb
rm test files
nikvas0 Jan 17, 2019
d514d37
fixed repl alter
nikvas0 Jan 17, 2019
2fbb706
Merge pull request #8 from nikvas0/nikvas0/fix_repl_alter
nikvas0 Jan 17, 2019
6a09340
Merge remote-tracking branch 'upstream/master' into nikvas0/index
nikvas0 Jan 17, 2019
8d47872
fix
nikvas0 Jan 17, 2019
6b8c7da
fix
nikvas0 Jan 17, 2019
c4a725a
indices
nikvas0 Jan 17, 2019
8c2a23a
MTReadStream
nikvas0 Jan 17, 2019
955b002
upd test for bug
nikvas0 Jan 17, 2019
0e6f5b4
fix
nikvas0 Jan 17, 2019
9975286
Merge pull request #9 from nikvas0/nikvas0/fix_duplicate_idx
nikvas0 Jan 17, 2019
4a19523
Merge remote-tracking branch 'upstream/master' into nikvas0/index
nikvas0 Jan 20, 2019
4bf0ac8
added useful parsers and ast classes
nikvas0 Jan 20, 2019
8152bc4
fix
nikvas0 Jan 20, 2019
bc0e4fa
fix comments
nikvas0 Jan 20, 2019
13a4fb2
replaced columns
nikvas0 Jan 20, 2019
5e626be
fix
nikvas0 Jan 20, 2019
cf377b9
fixed parsing
nikvas0 Jan 20, 2019
9120beb
fixed printing
nikvas0 Jan 20, 2019
d654517
fix err
nikvas0 Jan 20, 2019
093b94a
basic IndicesDescription
nikvas0 Jan 20, 2019
3f5447f
go to IndicesDescr
nikvas0 Jan 20, 2019
977b1e2
moved indices
nikvas0 Jan 20, 2019
c32d198
go to indicesDescr
nikvas0 Jan 21, 2019
9f1a093
fix test minmax_index*
nikvas0 Jan 21, 2019
506f2c4
fixed MT alter
nikvas0 Jan 21, 2019
f0a0dbb
fixed bug with replMT indices storing in zk
nikvas0 Jan 21, 2019
03cf70e
Merge remote-tracking branch 'upstream/master' into nikvas0/index
nikvas0 Jan 21, 2019
2a76e86
Merge branch 'nikvas0/index' into nikvas0/parse_index
nikvas0 Jan 21, 2019
08adef7
rename
nikvas0 Jan 21, 2019
5183022
refactoring
nikvas0 Jan 21, 2019
b220682
Merge pull request #10 from nikvas0/nikvas0/parse_index
nikvas0 Jan 21, 2019
0c601ec
docs ru
nikvas0 Jan 21, 2019
2d06486
docs ru
nikvas0 Jan 22, 2019
5ed3269
docs en
nikvas0 Jan 22, 2019
9ee50da
refactor
nikvas0 Jan 22, 2019
2c16614
rename tests
nikvas0 Jan 22, 2019
d47cd48
Merge remote-tracking branch 'upstream/master' into nikvas0/index
nikvas0 Jan 22, 2019
71e61d8
fix docs
nikvas0 Jan 22, 2019
d8f3bf7
refactoring
nikvas0 Jan 22, 2019
7996c6a
Merge pull request #11 from nikvas0/nikvas0/index_docs
nikvas0 Jan 22, 2019
296ad91
fix
nikvas0 Jan 23, 2019
276dc00
fix
nikvas0 Jan 24, 2019
84c7307
fix
nikvas0 Jan 24, 2019
0ea0b17
fixed style
nikvas0 Jan 26, 2019
b2915bc
Merge remote-tracking branch 'upstream/master' into nikvas0/index
nikvas0 Jan 26, 2019
6b6b0aa
unique idx
nikvas0 Jan 26, 2019
387ed1b
unique
nikvas0 Jan 26, 2019
077212f
fix
nikvas0 Jan 26, 2019
b94915b
better minmax calculation
nikvas0 Jan 26, 2019
0ea031d
Merge branch 'nikvas0/index' into nikvas0/unique_index
nikvas0 Jan 26, 2019
537b23e
upd
nikvas0 Jan 27, 2019
c701cb7
added getBlock
nikvas0 Jan 27, 2019
902c9a9
unique_condition
nikvas0 Jan 27, 2019
aa37d95
added termForAST
nikvas0 Jan 27, 2019
00ec4cc
unique
nikvas0 Jan 28, 2019
a74ed80
fixed not
nikvas0 Jan 28, 2019
b4d1bf8
uniqueCondition::mayBeTrueOnGranule
nikvas0 Jan 28, 2019
7c036e9
fix
nikvas0 Jan 28, 2019
149b0d8
fixed bug with double column
nikvas0 Jan 29, 2019
67af986
is always true
nikvas0 Jan 29, 2019
68ea3f0
fix
nikvas0 Jan 29, 2019
4ec0923
key set
nikvas0 Jan 29, 2019
9311c01
spaces
nikvas0 Jan 29, 2019
514987e
test
nikvas0 Jan 29, 2019
d3b430d
tests
nikvas0 Jan 29, 2019
c4dad05
fix
nikvas0 Jan 29, 2019
4de473a
unique
nikvas0 Jan 29, 2019
371e165
fix
nikvas0 Jan 29, 2019
f6a6a44
Merge pull request #12 from nikvas0/nikvas0/unique_index
nikvas0 Jan 29, 2019
c12b03d
Merge remote-tracking branch 'upstream/master' into nikvas0/index
nikvas0 Jan 29, 2019
6d7ccc6
fix
nikvas0 Jan 29, 2019
c0d7a8b
Merge branch 'nikvas0/index' of github.com:nikvas0/ClickHouse into ni…
nikvas0 Jan 30, 2019
160c8c0
fixed bug with duplicate column
nikvas0 Jan 30, 2019
69daa33
removed unused data
nikvas0 Jan 30, 2019
bcd07a4
fix
nikvas0 Jan 30, 2019
0492ed7
fixes
nikvas0 Jan 30, 2019
476f33f
__bitSwapLastTwo
nikvas0 Jan 30, 2019
094ae0f
fix
nikvas0 Jan 30, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions dbms/programs/copier/ClusterCopier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,7 @@ class ClusterCopier
/// Removes MATERIALIZED and ALIAS columns from create table query
static ASTPtr removeAliasColumnsFromCreateQuery(const ASTPtr & query_ast)
{
const ASTs & column_asts = typeid_cast<ASTCreateQuery &>(*query_ast).columns->children;
const ASTs & column_asts = typeid_cast<ASTCreateQuery &>(*query_ast).columns_list->columns->children;
auto new_columns = std::make_shared<ASTExpressionList>();

for (const ASTPtr & column_ast : column_asts)
Expand All @@ -1198,8 +1198,13 @@ class ClusterCopier

ASTPtr new_query_ast = query_ast->clone();
ASTCreateQuery & new_query = typeid_cast<ASTCreateQuery &>(*new_query_ast);
new_query.columns = new_columns.get();
new_query.children.at(0) = std::move(new_columns);

auto new_columns_list = std::make_shared<ASTColumns>();
new_columns_list->set(new_columns_list->columns, new_columns);
new_columns_list->set(
new_columns_list->indices, typeid_cast<ASTCreateQuery &>(*query_ast).columns_list->indices->clone());

new_query.replace(new_query.columns_list, new_columns_list);

return new_query_ast;
}
Expand All @@ -1217,7 +1222,7 @@ class ClusterCopier
res->table = new_table.second;

res->children.clear();
res->set(res->columns, create.columns->clone());
res->set(res->columns_list, create.columns_list->clone());
res->set(res->storage, new_storage_ast->clone());

return res;
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/DataStreams/MergingSortedBlockInputStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class MergingSortedBlockInputStream : public IBlockInputStream
using QueueWithCollation = std::priority_queue<SortCursorWithCollation>;
QueueWithCollation queue_with_collation;

/// Used in Vertical merge algorithm to gather non-PK columns (on next step)
/// Used in Vertical merge algorithm to gather non-PK/non-index columns (on next step)
/// If it is not nullptr then it should be populated during execution
WriteBuffer * out_row_sources_buf;

Expand Down
1 change: 1 addition & 0 deletions dbms/src/Databases/DatabaseDictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ void DatabaseDictionary::alterTable(
const Context &,
const String &,
const ColumnsDescription &,
const IndicesDescription &,
const ASTModifier &)
{
throw Exception("DatabaseDictionary: alterTable() is not supported", ErrorCodes::NOT_IMPLEMENTED);
Expand Down
1 change: 1 addition & 0 deletions dbms/src/Databases/DatabaseDictionary.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class DatabaseDictionary : public IDatabase
const Context & context,
const String & name,
const ColumnsDescription & columns,
const IndicesDescription & indices,
const ASTModifier & engine_modifier) override;

time_t getTableMetadataModificationTime(
Expand Down
1 change: 1 addition & 0 deletions dbms/src/Databases/DatabaseMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ void DatabaseMemory::alterTable(
const Context &,
const String &,
const ColumnsDescription &,
const IndicesDescription &,
const ASTModifier &)
{
throw Exception("DatabaseMemory: alterTable() is not supported", ErrorCodes::NOT_IMPLEMENTED);
Expand Down
1 change: 1 addition & 0 deletions dbms/src/Databases/DatabaseMemory.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class DatabaseMemory : public DatabaseWithOwnTablesBase
const Context & context,
const String & name,
const ColumnsDescription & columns,
const IndicesDescription & indices,
const ASTModifier & engine_modifier) override;

time_t getTableMetadataModificationTime(
Expand Down
10 changes: 9 additions & 1 deletion dbms/src/Databases/DatabaseOrdinary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ void DatabaseOrdinary::alterTable(
const Context & context,
const String & table_name,
const ColumnsDescription & columns,
const IndicesDescription & indices,
const ASTModifier & storage_modifier)
{
/// Read the definition of the table and replace the necessary parts with new ones.
Expand All @@ -531,7 +532,14 @@ void DatabaseOrdinary::alterTable(
ASTCreateQuery & ast_create_query = typeid_cast<ASTCreateQuery &>(*ast);

ASTPtr new_columns = InterpreterCreateQuery::formatColumns(columns);
ast_create_query.replace(ast_create_query.columns, new_columns);
ASTPtr new_indices = InterpreterCreateQuery::formatIndices(indices);

ast_create_query.columns_list->replace(ast_create_query.columns_list->columns, new_columns);

if (ast_create_query.columns_list->indices)
ast_create_query.columns_list->replace(ast_create_query.columns_list->indices, new_indices);
else
ast_create_query.columns_list->set(ast_create_query.columns_list->indices, new_indices);

if (storage_modifier)
storage_modifier(*ast_create_query.storage);
Expand Down
1 change: 1 addition & 0 deletions dbms/src/Databases/DatabaseOrdinary.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class DatabaseOrdinary : public DatabaseWithOwnTablesBase
const Context & context,
const String & name,
const ColumnsDescription & columns,
const IndicesDescription & indices,
const ASTModifier & engine_modifier) override;

time_t getTableMetadataModificationTime(
Expand Down
4 changes: 2 additions & 2 deletions dbms/src/Databases/DatabasesCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ std::pair<String, StoragePtr> createTableFromDefinition(
/// We do not directly use `InterpreterCreateQuery::execute`, because
/// - the database has not been created yet;
/// - the code is simpler, since the query is already brought to a suitable form.
if (!ast_create_query.columns)
if (!ast_create_query.columns_list || !ast_create_query.columns_list->columns)
throw Exception("Missing definition of columns.", ErrorCodes::EMPTY_LIST_OF_COLUMNS_PASSED);

ColumnsDescription columns = InterpreterCreateQuery::getColumnsDescription(*ast_create_query.columns, context);
ColumnsDescription columns = InterpreterCreateQuery::getColumnsDescription(*ast_create_query.columns_list->columns, context);

return
{
Expand Down
2 changes: 2 additions & 0 deletions dbms/src/Databases/IDatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <Core/Types.h>
#include <Core/NamesAndTypes.h>
#include <Storages/ColumnsDescription.h>
#include <Storages/IndicesDescription.h>
#include <ctime>
#include <memory>
#include <functional>
Expand Down Expand Up @@ -115,6 +116,7 @@ class IDatabase : public std::enable_shared_from_this<IDatabase>
const Context & context,
const String & name,
const ColumnsDescription & columns,
const IndicesDescription & indices,
const ASTModifier & engine_modifier) = 0;

/// Returns time of table's metadata change, 0 if there is no corresponding metadata file.
Expand Down
34 changes: 26 additions & 8 deletions dbms/src/Interpreters/InterpreterCreateQuery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ BlockIO InterpreterCreateQuery::createDatabase(ASTCreateQuery & create)
const ASTStorage & storage = *create.storage;
const ASTFunction & engine = *storage.engine;
/// Currently, there are no database engines, that support any arguments.
if (engine.arguments || engine.parameters || storage.partition_by || storage.primary_key || storage.order_by || storage.sample_by || storage.settings)
if (engine.arguments || engine.parameters || storage.partition_by || storage.primary_key
|| storage.order_by || storage.sample_by || storage.settings ||
(create.columns_list && create.columns_list->indices && !create.columns_list->indices->children.empty()))
{
std::stringstream ostr;
formatAST(storage, ostr, false, false);
Expand Down Expand Up @@ -397,6 +399,16 @@ ASTPtr InterpreterCreateQuery::formatColumns(const ColumnsDescription & columns)
return columns_list;
}

ASTPtr InterpreterCreateQuery::formatIndices(const IndicesDescription & indices)
{
auto res = std::make_shared<ASTExpressionList>();

for (const auto & index : indices.indices)
res->children.push_back(index->clone());

return res;
}

ColumnsDescription InterpreterCreateQuery::getColumnsDescription(const ASTExpressionList & columns, const Context & context)
{
ColumnsDescription res;
Expand Down Expand Up @@ -449,9 +461,9 @@ ColumnsDescription InterpreterCreateQuery::setColumns(
{
ColumnsDescription res;

if (create.columns)
if (create.columns_list && create.columns_list->columns)
{
res = getColumnsDescription(*create.columns, context);
res = getColumnsDescription(*create.columns_list->columns, context);
}
else if (!create.as_table.empty())
{
Expand All @@ -467,10 +479,16 @@ ColumnsDescription InterpreterCreateQuery::setColumns(

/// Even if query has list of columns, canonicalize it (unfold Nested columns).
ASTPtr new_columns = formatColumns(res);
if (create.columns)
create.replace(create.columns, new_columns);
if (!create.columns_list)
{
auto new_columns_list = std::make_shared<ASTColumns>();
create.set(create.columns_list, new_columns_list);
}

if (create.columns_list->columns)
create.columns_list->replace(create.columns_list->columns, new_columns);
else
create.set(create.columns, new_columns);
create.columns_list->set(create.columns_list->columns, new_columns);

/// Check for duplicates
std::set<String> all_columns;
Expand Down Expand Up @@ -550,7 +568,7 @@ BlockIO InterpreterCreateQuery::createTable(ASTCreateQuery & create)
String table_name_escaped = escapeForFileName(table_name);

// If this is a stub ATTACH query, read the query definition from the database
if (create.attach && !create.storage && !create.columns)
if (create.attach && !create.storage && !create.columns_list)
{
// Table SQL definition is available even if the table is detached
auto query = context.getCreateTableQuery(database_name, table_name);
Expand All @@ -569,7 +587,7 @@ BlockIO InterpreterCreateQuery::createTable(ASTCreateQuery & create)
}

Block as_select_sample;
if (create.select && (!create.attach || !create.columns))
if (create.select && (!create.attach || !create.columns_list))
as_select_sample = InterpreterSelectWithUnionQuery::getSampleBlock(create.select->clone(), context);

String as_database_name = create.as_database.empty() ? current_database : create.as_database;
Expand Down
3 changes: 3 additions & 0 deletions dbms/src/Interpreters/InterpreterCreateQuery.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <Interpreters/IInterpreter.h>
#include <Storages/ColumnsDescription.h>
#include <Storages/IndicesDescription.h>
#include <Common/ThreadPool.h>


Expand Down Expand Up @@ -29,6 +30,8 @@ class InterpreterCreateQuery : public IInterpreter
static ASTPtr formatColumns(const NamesAndTypesList & columns);
static ASTPtr formatColumns(const ColumnsDescription & columns);

static ASTPtr formatIndices(const IndicesDescription & indices);

void setDatabaseLoadingThreadpool(ThreadPool & thread_pool_)
{
thread_pool = &thread_pool_;
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Interpreters/InterpreterSystemQuery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ StoragePtr InterpreterSystemQuery::tryRestartReplica(const String & database_nam
create.attach = true;

std::string data_path = database->getDataPath();
auto columns = InterpreterCreateQuery::getColumnsDescription(*create.columns, system_context);
auto columns = InterpreterCreateQuery::getColumnsDescription(*create.columns_list->columns, system_context);

StoragePtr table = StorageFactory::instance().get(create,
data_path,
Expand Down
5 changes: 4 additions & 1 deletion dbms/src/Interpreters/SystemLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,10 @@ void SystemLog<LogElement>::prepareTable()
create->table = table_name;

Block sample = LogElement::createBlock();
create->set(create->columns, InterpreterCreateQuery::formatColumns(sample.getNamesAndTypesList()));

auto new_columns_list = std::make_shared<ASTColumns>();
new_columns_list->set(new_columns_list->columns, InterpreterCreateQuery::formatColumns(sample.getNamesAndTypesList()));
create->set(create->columns_list, new_columns_list);

ParserStorage storage_parser;
ASTPtr storage_ast = parseQuery(
Expand Down
18 changes: 18 additions & 0 deletions dbms/src/Parsers/ASTAlterQuery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,24 @@ void ASTAlterCommand::formatImpl(
settings.ostr << (settings.hilite ? hilite_keyword : "") << indent_str << "MODIFY ORDER BY " << (settings.hilite ? hilite_none : "");
order_by->formatImpl(settings, state, frame);
}
else if (type == ASTAlterCommand::ADD_INDEX)
{
settings.ostr << (settings.hilite ? hilite_keyword : "") << indent_str << "ADD INDEX " << (if_not_exists ? "IF NOT EXISTS " : "") << (settings.hilite ? hilite_none : "");
index_decl->formatImpl(settings, state, frame);

/// AFTER
if (index)
{
settings.ostr << (settings.hilite ? hilite_keyword : "") << indent_str << " AFTER " << (settings.hilite ? hilite_none : "");
index->formatImpl(settings, state, frame);
}
}
else if (type == ASTAlterCommand::DROP_INDEX)
{
settings.ostr << (settings.hilite ? hilite_keyword : "") << indent_str
<< "DROP INDEX " << (if_exists ? "IF EXISTS " : "") << (settings.hilite ? hilite_none : "");
index->formatImpl(settings, state, frame);
}
else if (type == ASTAlterCommand::DROP_PARTITION)
{
settings.ostr << (settings.hilite ? hilite_keyword : "") << indent_str << (detach ? "DETACH" : "DROP") << " PARTITION "
Expand Down
12 changes: 12 additions & 0 deletions dbms/src/Parsers/ASTAlterQuery.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class ASTAlterCommand : public IAST
COMMENT_COLUMN,
MODIFY_ORDER_BY,

ADD_INDEX,
DROP_INDEX,

DROP_PARTITION,
ATTACH_PARTITION,
REPLACE_PARTITION,
Expand Down Expand Up @@ -58,6 +61,15 @@ class ASTAlterCommand : public IAST
*/
ASTPtr order_by;

/** The ADD INDEX query stores the IndexDeclaration there.
*/
ASTPtr index_decl;

/** The ADD INDEX query stores the name of the index following AFTER.
* The DROP INDEX query stores the name for deletion.
*/
ASTPtr index;

/** Used in DROP PARTITION and ATTACH PARTITION FROM queries.
* The value or ID of the partition is stored here.
*/
Expand Down
Loading