Add global counter to subqueries

This commit is contained in:
alesapin 2018-10-20 00:03:45 +03:00
parent 7449c25556
commit dcc8ca49d7
3 changed files with 28 additions and 4 deletions

View File

@ -72,13 +72,12 @@ void QueryAliasesVisitor::getNodeAlias(const ASTPtr & ast, Aliases & aliases, co
if (subquery->alias.empty())
{
size_t subquery_index = 1;
static std::atomic_uint64_t subquery_index = 1;
while (true)
{
alias = "_subquery" + toString(subquery_index);
if (!aliases.count("_subquery" + toString(subquery_index)))
alias = "_subquery" + std::to_string(subquery_index++);
if (!aliases.count(alias))
break;
++subquery_index;
}
subquery->setAlias(alias);

View File

@ -0,0 +1,23 @@
SET compile_expressions = 1;
SET min_count_to_compile = 1;
SET optimize_move_to_prewhere = 0;
SET enable_optimize_predicate_expression=0;
DROP TABLE IF EXISTS test.dt;
DROP TABLE IF EXISTS test.testx;
CREATE TABLE test.dt(tkey Int32) ENGINE = MergeTree order by tuple();
INSERT INTO test.dt VALUES (300000);
CREATE TABLE test.testx(t Int32, a UInt8) ENGINE = MergeTree ORDER BY tuple();
INSERT INTO test.testx VALUES (100000, 0);
SELECT COUNT(*) FROM test.testx WHERE NOT a AND t < (SELECT tkey FROM test.dt);
DROP TABLE test.dt;
CREATE TABLE test.dt(tkey Int32) ENGINE = MergeTree order by tuple();
INSERT INTO test.dt VALUES (0);
SELECT COUNT(*) FROM test.testx WHERE NOT a AND t < (SELECT tkey FROM test.dt);
DROP TABLE IF EXISTS test.dt;
DROP TABLE IF EXISTS test.testx;