mirror of https://github.com/citusdata/citus.git
Fix schema name bug for sequences (#5937)
parent
187d06c3b5
commit
aa8f46ead0
|
@ -564,7 +564,7 @@ static DistributeObjectOps Sequence_AlterOwner = {
|
||||||
};
|
};
|
||||||
static DistributeObjectOps Sequence_Drop = {
|
static DistributeObjectOps Sequence_Drop = {
|
||||||
.deparse = DeparseDropSequenceStmt,
|
.deparse = DeparseDropSequenceStmt,
|
||||||
.qualify = NULL,
|
.qualify = QualifyDropSequenceStmt,
|
||||||
.preprocess = PreprocessDropSequenceStmt,
|
.preprocess = PreprocessDropSequenceStmt,
|
||||||
.postprocess = NULL,
|
.postprocess = NULL,
|
||||||
.address = NULL,
|
.address = NULL,
|
||||||
|
|
|
@ -226,7 +226,6 @@ PreprocessDropSequenceStmt(Node *node, const char *queryString,
|
||||||
ProcessUtilityContext processUtilityContext)
|
ProcessUtilityContext processUtilityContext)
|
||||||
{
|
{
|
||||||
DropStmt *stmt = castNode(DropStmt, node);
|
DropStmt *stmt = castNode(DropStmt, node);
|
||||||
List *deletingSequencesList = stmt->objects;
|
|
||||||
List *distributedSequencesList = NIL;
|
List *distributedSequencesList = NIL;
|
||||||
List *distributedSequenceAddresses = NIL;
|
List *distributedSequenceAddresses = NIL;
|
||||||
|
|
||||||
|
@ -259,6 +258,7 @@ PreprocessDropSequenceStmt(Node *node, const char *queryString,
|
||||||
* iterate over all sequences to be dropped and filter to keep only distributed
|
* iterate over all sequences to be dropped and filter to keep only distributed
|
||||||
* sequences.
|
* sequences.
|
||||||
*/
|
*/
|
||||||
|
List *deletingSequencesList = stmt->objects;
|
||||||
List *objectNameList = NULL;
|
List *objectNameList = NULL;
|
||||||
foreach_ptr(objectNameList, deletingSequencesList)
|
foreach_ptr(objectNameList, deletingSequencesList)
|
||||||
{
|
{
|
||||||
|
|
|
@ -86,12 +86,6 @@ AppendSequenceNameList(StringInfo buf, List *objects, ObjectType objtype)
|
||||||
|
|
||||||
RangeVar *seq = makeRangeVarFromNameList((List *) lfirst(objectCell));
|
RangeVar *seq = makeRangeVarFromNameList((List *) lfirst(objectCell));
|
||||||
|
|
||||||
if (seq->schemaname == NULL)
|
|
||||||
{
|
|
||||||
Oid schemaOid = RangeVarGetCreationNamespace(seq);
|
|
||||||
seq->schemaname = get_namespace_name(schemaOid);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *qualifiedSequenceName = quote_qualified_identifier(seq->schemaname,
|
char *qualifiedSequenceName = quote_qualified_identifier(seq->schemaname,
|
||||||
seq->relname);
|
seq->relname);
|
||||||
appendStringInfoString(buf, qualifiedSequenceName);
|
appendStringInfoString(buf, qualifiedSequenceName);
|
||||||
|
|
|
@ -17,7 +17,9 @@
|
||||||
|
|
||||||
#include "postgres.h"
|
#include "postgres.h"
|
||||||
|
|
||||||
|
#include "distributed/commands.h"
|
||||||
#include "distributed/deparser.h"
|
#include "distributed/deparser.h"
|
||||||
|
#include "distributed/listutils.h"
|
||||||
#include "distributed/version_compat.h"
|
#include "distributed/version_compat.h"
|
||||||
#include "parser/parse_func.h"
|
#include "parser/parse_func.h"
|
||||||
#include "utils/lsyscache.h"
|
#include "utils/lsyscache.h"
|
||||||
|
@ -38,8 +40,13 @@ QualifyAlterSequenceOwnerStmt(Node *node)
|
||||||
|
|
||||||
if (seq->schemaname == NULL)
|
if (seq->schemaname == NULL)
|
||||||
{
|
{
|
||||||
Oid schemaOid = RangeVarGetCreationNamespace(seq);
|
Oid seqOid = RangeVarGetRelid(seq, NoLock, stmt->missing_ok);
|
||||||
seq->schemaname = get_namespace_name(schemaOid);
|
|
||||||
|
if (OidIsValid(seqOid))
|
||||||
|
{
|
||||||
|
Oid schemaOid = get_rel_namespace(seqOid);
|
||||||
|
seq->schemaname = get_namespace_name(schemaOid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,12 +66,53 @@ QualifyAlterSequenceSchemaStmt(Node *node)
|
||||||
|
|
||||||
if (seq->schemaname == NULL)
|
if (seq->schemaname == NULL)
|
||||||
{
|
{
|
||||||
Oid schemaOid = RangeVarGetCreationNamespace(seq);
|
Oid seqOid = RangeVarGetRelid(seq, NoLock, stmt->missing_ok);
|
||||||
seq->schemaname = get_namespace_name(schemaOid);
|
|
||||||
|
if (OidIsValid(seqOid))
|
||||||
|
{
|
||||||
|
Oid schemaOid = get_rel_namespace(seqOid);
|
||||||
|
seq->schemaname = get_namespace_name(schemaOid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* QualifyDropSequenceStmt transforms a DROP SEQUENCE
|
||||||
|
* statement in place and makes the sequence name fully qualified.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
QualifyDropSequenceStmt(Node *node)
|
||||||
|
{
|
||||||
|
DropStmt *stmt = castNode(DropStmt, node);
|
||||||
|
|
||||||
|
Assert(stmt->removeType == OBJECT_SEQUENCE);
|
||||||
|
|
||||||
|
List *objectNameListWithSchema = NIL;
|
||||||
|
List *objectNameList = NULL;
|
||||||
|
foreach_ptr(objectNameList, stmt->objects)
|
||||||
|
{
|
||||||
|
RangeVar *seq = makeRangeVarFromNameList(objectNameList);
|
||||||
|
|
||||||
|
if (seq->schemaname == NULL)
|
||||||
|
{
|
||||||
|
Oid seqOid = RangeVarGetRelid(seq, NoLock, stmt->missing_ok);
|
||||||
|
|
||||||
|
if (OidIsValid(seqOid))
|
||||||
|
{
|
||||||
|
Oid schemaOid = get_rel_namespace(seqOid);
|
||||||
|
seq->schemaname = get_namespace_name(schemaOid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
objectNameListWithSchema = lappend(objectNameListWithSchema,
|
||||||
|
MakeNameListFromRangeVar(seq));
|
||||||
|
}
|
||||||
|
|
||||||
|
stmt->objects = objectNameListWithSchema;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* QualifyRenameSequenceStmt transforms a
|
* QualifyRenameSequenceStmt transforms a
|
||||||
* ALTER SEQUENCE .. RENAME TO ..
|
* ALTER SEQUENCE .. RENAME TO ..
|
||||||
|
|
|
@ -213,6 +213,7 @@ extern char * DeparseAlterSequenceOwnerStmt(Node *node);
|
||||||
|
|
||||||
/* forward declarations for qualify_sequence_stmt.c */
|
/* forward declarations for qualify_sequence_stmt.c */
|
||||||
extern void QualifyRenameSequenceStmt(Node *node);
|
extern void QualifyRenameSequenceStmt(Node *node);
|
||||||
|
extern void QualifyDropSequenceStmt(Node *node);
|
||||||
extern void QualifyAlterSequenceSchemaStmt(Node *node);
|
extern void QualifyAlterSequenceSchemaStmt(Node *node);
|
||||||
extern void QualifyAlterSequenceOwnerStmt(Node *node);
|
extern void QualifyAlterSequenceOwnerStmt(Node *node);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue