Fixes ALTER STATISTICS IF EXISTS bug (#5435)

* Fix ALTER STATISTICS IF EXISTS bug
pull/5417/head
Ahmet Gedemenli 2021-11-04 16:14:05 +03:00 committed by GitHub
parent 7597e5aee9
commit b30ed46068
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 1 deletions

View File

@ -348,7 +348,18 @@ PreprocessAlterStatisticsStmt(Node *node, const char *queryString,
{
AlterStatsStmt *stmt = castNode(AlterStatsStmt, node);
Oid statsOid = get_statistics_object_oid(stmt->defnames, false);
Oid statsOid = get_statistics_object_oid(stmt->defnames, stmt->missing_ok);
if (!OidIsValid(statsOid))
{
/*
* If statsOid is invalid, here we can assume that the query includes
* IF EXISTS clause, since get_statistics_object_oid would error out otherwise.
* So here we can safely return NIL here without checking stmt->missing_ok.
*/
return NIL;
}
Oid relationId = GetRelIdByStatsOid(statsOid);
if (!IsCitusTable(relationId) || !ShouldPropagate())

View File

@ -108,5 +108,16 @@ ORDER BY stxstattarget, stxrelid::regclass ASC;
(64 rows)
\c - - - :master_port
-- the first one should log a notice that says statistics object does not exist
ALTER STATISTICS IF EXISTS stats_that_doesnt_exists SET STATISTICS 0;
NOTICE: statistics object "stats_that_doesnt_exists" does not exist, skipping
-- these three should error out as ALTER STATISTICS syntax doesn't support these with IF EXISTS clause
-- if output of any of these three changes, we should support them and update the test output here
ALTER STATISTICS IF EXISTS stats_that_doesnt_exists RENAME TO this_should_error_out;
ERROR: syntax error at or near "RENAME"
ALTER STATISTICS IF EXISTS stats_that_doesnt_exists OWNER TO CURRENT_USER;
ERROR: syntax error at or near "OWNER"
ALTER STATISTICS IF EXISTS stats_that_doesnt_exists SET SCHEMA "statistics'Test";
ERROR: syntax error at or near "SCHEMA"
SET client_min_messages TO WARNING;
DROP SCHEMA "statistics'TestTarget" CASCADE;

View File

@ -41,5 +41,12 @@ WHERE stxnamespace IN (
ORDER BY stxstattarget, stxrelid::regclass ASC;
\c - - - :master_port
-- the first one should log a notice that says statistics object does not exist
ALTER STATISTICS IF EXISTS stats_that_doesnt_exists SET STATISTICS 0;
-- these three should error out as ALTER STATISTICS syntax doesn't support these with IF EXISTS clause
-- if output of any of these three changes, we should support them and update the test output here
ALTER STATISTICS IF EXISTS stats_that_doesnt_exists RENAME TO this_should_error_out;
ALTER STATISTICS IF EXISTS stats_that_doesnt_exists OWNER TO CURRENT_USER;
ALTER STATISTICS IF EXISTS stats_that_doesnt_exists SET SCHEMA "statistics'Test";
SET client_min_messages TO WARNING;
DROP SCHEMA "statistics'TestTarget" CASCADE;