Backport #64957 to 24.3: Fix alter query clone with SQL security (#65538)

Co-authored-by: robot-clickhouse <robot-clickhouse@users.noreply.github.com>
This commit is contained in:
robot-clickhouse 2024-06-25 00:11:47 +02:00 committed by GitHub
parent 2083c84147
commit 3257f361b8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 21 additions and 1 deletions

View File

@ -60,6 +60,8 @@ ASTPtr ASTAlterCommand::clone() const
res->settings_resets = res->children.emplace_back(settings_resets->clone()).get();
if (select)
res->select = res->children.emplace_back(select->clone()).get();
if (sql_security)
res->sql_security = res->children.emplace_back(sql_security->clone()).get();
if (rename_to)
res->rename_to = res->children.emplace_back(rename_to->clone()).get();
@ -516,6 +518,7 @@ void ASTAlterCommand::forEachPointerToChild(std::function<void(void**)> f)
f(reinterpret_cast<void **>(&settings_changes));
f(reinterpret_cast<void **>(&settings_resets));
f(reinterpret_cast<void **>(&select));
f(reinterpret_cast<void **>(&sql_security));
f(reinterpret_cast<void **>(&rename_to));
}

View File

@ -7,7 +7,7 @@ namespace DB
void ASTSQLSecurity::formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const
{
if (!type.has_value())
if (!type)
return;
if (definer || is_definer_current_user)

View File

@ -35,5 +35,8 @@ OK
2 2
6 6
9 9
===== TestInsertChain =====
1000
1000
===== TestOnCluster =====
1

View File

@ -260,6 +260,8 @@ EOF
${CLICKHOUSE_CLIENT} --user $user2 --query "SELECT * FROM $db.test_mv_row_2"
echo "===== TestInsertChain ====="
${CLICKHOUSE_CLIENT} --multiquery <<EOF
CREATE TABLE $db.session_events(
clientId UUID,
@ -299,4 +301,16 @@ ${CLICKHOUSE_CLIENT} --user $user3 --query "INSERT INTO $db.session_events SELEC
${CLICKHOUSE_CLIENT} --user $user3 --query "SELECT count(*) FROM session_events"
${CLICKHOUSE_CLIENT} --query "SELECT count(*) FROM materialized_events"
echo "===== TestOnCluster ====="
${CLICKHOUSE_CLIENT} --multiquery <<EOF
CREATE TABLE $db.test_cluster ON CLUSTER test_shard_localhost (a String) Engine = MergeTree() ORDER BY a FORMAT Null;
CREATE TABLE $db.test_cluster_2 ON CLUSTER test_shard_localhost (a String) Engine = MergeTree() ORDER BY a FORMAT Null;
CREATE MATERIALIZED VIEW $db.cluster_mv ON CLUSTER test_shard_localhost TO $db.test_cluster_2 AS SELECT * FROM $db.test_cluster FORMAT Null;
ALTER TABLE $db.cluster_mv ON CLUSTER test_shard_localhost MODIFY DEFINER = $user3 FORMAT Null;
EOF
${CLICKHOUSE_CLIENT} --query "SHOW CREATE TABLE $db.cluster_mv" | grep -c "DEFINER = $user3"
${CLICKHOUSE_CLIENT} --query "DROP USER IF EXISTS $user1, $user2, $user3";