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

Fix PREWHERE with distributed IN #9871

Merged
merged 2 commits into from
Mar 26, 2020
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
4 changes: 2 additions & 2 deletions dbms/src/Interpreters/InJoinSubqueriesPreprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ struct NonGlobalTableData
throw Exception("Distributed table should have an alias when distributed_product_mode set to local.",
ErrorCodes::DISTRIBUTED_IN_JOIN_SUBQUERY_DENIED);

database_and_table = createTableIdentifier(database, table);
database_and_table->setAlias(alias);
auto & identifier = database_and_table->as<ASTIdentifier &>();
identifier.resetTable(database, table);
}
else
throw Exception("InJoinSubqueriesPreprocessor: unexpected value of 'distributed_product_mode' setting",
Expand Down
9 changes: 9 additions & 0 deletions dbms/src/Parsers/ASTIdentifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ void ASTIdentifier::appendColumnNameImpl(WriteBuffer & ostr) const
writeString(name, ostr);
}

void ASTIdentifier::resetTable(const String & database_name, const String & table_name)
{
auto ast = createTableIdentifier(database_name, table_name);
auto & ident = ast->as<ASTIdentifier &>();
name.swap(ident.name);
name_parts.swap(ident.name_parts);
uuid = ident.uuid;
}

ASTPtr createTableIdentifier(const String & database_name, const String & table_name)
{
assert(database_name != "_temporary_and_external_tables");
Expand Down
2 changes: 2 additions & 0 deletions dbms/src/Parsers/ASTIdentifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class ASTIdentifier : public ASTWithAlias
return name;
}

void resetTable(const String & database_name, const String & table_name);

protected:
void formatImplWithoutAlias(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override;
void appendColumnNameImpl(WriteBuffer & ostr) const override;
Expand Down
Empty file.
24 changes: 24 additions & 0 deletions dbms/tests/queries/0_stateless/01102_distributed_local_in_bug.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
DROP TABLE IF EXISTS hits;
DROP TABLE IF EXISTS visits;
DROP TABLE IF EXISTS hits_layer;
DROP TABLE IF EXISTS visits_layer;

CREATE TABLE visits(StartDate Date) ENGINE MergeTree ORDER BY(StartDate);
CREATE TABLE hits(EventDate Date, WatchID UInt8) ENGINE MergeTree ORDER BY(EventDate);

CREATE TABLE visits_layer(StartDate Date) ENGINE Distributed(test_cluster_two_shards_localhost, currentDatabase(), 'visits');
CREATE TABLE hits_layer(EventDate Date, WatchID UInt8) ENGINE Distributed(test_cluster_two_shards_localhost, currentDatabase(), 'hits');

SET distributed_product_mode = 'local';

SELECT 0 FROM hits_layer AS hl
PREWHERE WatchID IN
(
SELECT 0 FROM visits_layer AS vl
)
WHERE 0;

DROP TABLE hits;
DROP TABLE visits;
DROP TABLE hits_layer;
DROP TABLE visits_layer;