Fixes review notes

pull/7253/head
gindibay 2023-11-21 23:36:32 +03:00
parent ed3ebf2296
commit 9d7e601e1d
5 changed files with 47 additions and 24 deletions

View File

@ -191,13 +191,25 @@ PreprocessGrantOnDatabaseStmt(Node *node, const char *queryString,
}
/*
* Checks if the provided ALTER DATABASE statement is a SET TABLESPACE statement.
*
* This function takes a Node pointer representing a AlterDatabaseStmt, and checks
* if it is a SET TABLESPACE statement, which is used to move a table to a new
* tablespace.
*
* Parameters:
* stmt: A pointer to a Node representing AlterDatabaseStmt.
*
* Returns:
* true if the statement is a SET TABLESPACE statement, false otherwise.
*/
static bool
isSetTablespaceStatement(AlterDatabaseStmt *stmt)
{
ListCell *lc = NULL;
foreach(lc, stmt->options)
DefElem *def = NULL;
foreach_ptr(def, stmt->options)
{
DefElem *def = (DefElem *) lfirst(lc);
if (strcmp(def->defname, "tablespace") == 0)
{
return true;
@ -290,8 +302,7 @@ PreprocessAlterDatabaseRefreshCollStmt(Node *node, const char *queryString,
* all workers.
*/
List *
PreprocessAlterDatabaseRenameStmt(Node *node, const char *queryString,
ProcessUtilityContext processUtilityContext)
PostprocessAlterDatabaseRenameStmt(Node *node, const char *queryString)
{
if (!ShouldPropagate())
{

View File

@ -524,8 +524,8 @@ static DistributeObjectOps Database_Set = {
static DistributeObjectOps Database_Rename = {
.deparse = DeparseAlterDatabaseRenameStmt,
.qualify = NULL,
.preprocess = PreprocessAlterDatabaseRenameStmt,
.postprocess = NULL,
.preprocess = NULL,
.postprocess = PostprocessAlterDatabaseRenameStmt,
.objectType = OBJECT_DATABASE,
.operationType = DIST_OPS_ALTER,
.address = NULL,

View File

@ -55,7 +55,7 @@ const DefElemOptionFormat create_database_option_formats[] = {
};
const DefElemOptionFormat alter_database_option_formats[] = {
const DefElemOptionFormat alterDatabaseOptionFormats[] = {
{ "is_template", " IS_TEMPLATE %s", OPTION_FORMAT_BOOLEAN },
{ "allow_connections", " ALLOW_CONNECTIONS %s", OPTION_FORMAT_BOOLEAN },
{ "connection_limit", " CONNECTION LIMIT %d", OPTION_FORMAT_INTEGER },
@ -147,16 +147,16 @@ AppendGrantOnDatabaseStmt(StringInfo buf, GrantStmt *stmt)
static bool
AppendBasicAlterDatabaseOptions(StringInfo buf, DefElem *def, bool
prefix_appended_for_basic_options, char *dbname)
prefixAppendedForBasicOptions, char *dbname)
{
if (!prefix_appended_for_basic_options)
if (!prefixAppendedForBasicOptions)
{
appendStringInfo(buf, "ALTER DATABASE %s WITH", quote_identifier(dbname));
prefix_appended_for_basic_options = true;
prefixAppendedForBasicOptions = true;
}
DefElemOptionToStatement(buf, def, alter_database_option_formats, lengthof(
alter_database_option_formats));
return prefix_appended_for_basic_options;
DefElemOptionToStatement(buf, def, alterDatabaseOptionFormats, lengthof(
alterDatabaseOptionFormats));
return prefixAppendedForBasicOptions;
}
@ -175,7 +175,7 @@ AppendAlterDatabaseStmt(StringInfo buf, AlterDatabaseStmt *stmt)
if (stmt->options)
{
ListCell *cell = NULL;
bool prefix_appended_for_basic_options = false;
bool prefixAppendedForBasicOptions = false;
foreach(cell, stmt->options)
{
DefElem *def = castNode(DefElem, lfirst(cell));
@ -186,11 +186,11 @@ AppendAlterDatabaseStmt(StringInfo buf, AlterDatabaseStmt *stmt)
}
else
{
prefix_appended_for_basic_options = AppendBasicAlterDatabaseOptions(buf,
def,
prefix_appended_for_basic_options,
stmt->
dbname);
prefixAppendedForBasicOptions = AppendBasicAlterDatabaseOptions(buf,
def,
prefixAppendedForBasicOptions,
stmt->
dbname);
}
}
}
@ -247,6 +247,21 @@ DeparseAlterDatabaseRefreshCollStmt(Node *node)
#endif
/*
* Deparses an ALTER DATABASE RENAME statement.
*
* This function takes a Node pointer representing an ALTER DATABASE RENAME
* statement, and returns a string that is the SQL representation of that
* statement.
*
* Parameters:
* node: A pointer to a Node representing an ALTER DATABASE RENAME statement.
*
* Returns:
* A string representing the SQL command to rename a database. The string is
* in the format "ALTER DATABASE <oldname> RENAME TO <newname>", where
* <oldname> and <newname> are the old and new database names, respectively.
*/
char *
DeparseAlterDatabaseRenameStmt(Node *node)
{

View File

@ -3,4 +3,3 @@
DROP FUNCTION pg_catalog.citus_internal_database_command(text);
#include "../udfs/citus_add_rebalance_strategy/10.1-1.sql"

View File

@ -246,9 +246,7 @@ extern List * CreateDatabaseStmtObjectAddress(Node *node, bool missingOk,
extern List * GenerateGrantDatabaseCommandList(void);
extern List * PreprocessAlterDatabaseRenameStmt(Node *node, const char *queryString,
ProcessUtilityContext
processUtilityContext);
extern List * PostprocessAlterDatabaseRenameStmt(Node *node, const char *queryString);
extern void EnsureSupportedCreateDatabaseCommand(CreatedbStmt *stmt);
extern char * CreateDatabaseDDLCommand(Oid dbId);