Skip to content

Commit 5a05914

Browse files
Backport #66395 to 24.3: Ignore subquery for IN in DDLLoadingDependencyVisitor
1 parent b22ed81 commit 5a05914

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

src/Databases/DDLLoadingDependencyVisitor.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <Parsers/ASTFunction.h>
1212
#include <Parsers/ASTIdentifier.h>
1313
#include <Parsers/ASTLiteral.h>
14+
#include <Parsers/ASTSubquery.h>
1415
#include <Parsers/ASTSelectWithUnionQuery.h>
1516
#include <Parsers/ASTTTLElement.h>
1617
#include <Poco/String.h>
@@ -200,6 +201,13 @@ void DDLLoadingDependencyVisitor::extractTableNameFromArgument(const ASTFunction
200201
qualified_name.database = table_identifier->getDatabaseName();
201202
qualified_name.table = table_identifier->shortName();
202203
}
204+
else if (arg->as<ASTSubquery>())
205+
{
206+
/// Allow IN subquery.
207+
/// Do not add tables from the subquery into dependencies,
208+
/// because CREATE will succeed anyway.
209+
return;
210+
}
203211
else
204212
{
205213
assert(false);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
42
2+
42

tests/queries/0_stateless/02841_not_ready_set_constraints.sql

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,27 @@ ENGINE = MergeTree ORDER BY conversation;
1717
INSERT INTO t2(conversation) VALUES (42);
1818

1919
select * from t2;
20+
21+
drop table t1;
22+
23+
INSERT INTO t2(conversation) VALUES (42); -- { serverError UNKNOWN_TABLE }
24+
25+
drop table t2;
26+
27+
CREATE TABLE t2 (
28+
`conversation` UInt64,
29+
CONSTRAINT constraint_conversation CHECK conversation IN (SELECT id FROM t1)
30+
)
31+
ENGINE = MergeTree ORDER BY conversation;
32+
33+
INSERT INTO t2(conversation) VALUES (42); -- { serverError UNKNOWN_TABLE }
34+
35+
CREATE TABLE t1 (
36+
`id` UInt64
37+
)
38+
ENGINE = MergeTree ORDER BY id;
39+
40+
INSERT INTO t1(id) VALUES (42);
41+
42+
INSERT INTO t2(conversation) VALUES (42);
43+
select * from t2;

0 commit comments

Comments
 (0)