mirror of https://github.com/citusdata/citus.git
Merge pull request #5934 from citusdata/fix-alter-statistics-nspname
Fix alter statistics namespace nameprev-process-utility
commit
613d9c0dca
|
@ -15,15 +15,19 @@
|
||||||
#include "postgres.h"
|
#include "postgres.h"
|
||||||
|
|
||||||
#include "catalog/namespace.h"
|
#include "catalog/namespace.h"
|
||||||
|
#include "catalog/pg_statistic_ext.h"
|
||||||
#include "distributed/commands.h"
|
#include "distributed/commands.h"
|
||||||
#include "distributed/deparser.h"
|
#include "distributed/deparser.h"
|
||||||
#include "distributed/listutils.h"
|
#include "distributed/listutils.h"
|
||||||
#include "nodes/parsenodes.h"
|
#include "nodes/parsenodes.h"
|
||||||
#include "nodes/value.h"
|
#include "nodes/value.h"
|
||||||
|
#include "utils/syscache.h"
|
||||||
#include "utils/lsyscache.h"
|
#include "utils/lsyscache.h"
|
||||||
#include "utils/rel.h"
|
#include "utils/rel.h"
|
||||||
#include "utils/relcache.h"
|
#include "utils/relcache.h"
|
||||||
|
|
||||||
|
static Oid GetStatsNamespaceOid(Oid statsOid);
|
||||||
|
|
||||||
void
|
void
|
||||||
QualifyCreateStatisticsStmt(Node *node)
|
QualifyCreateStatisticsStmt(Node *node)
|
||||||
{
|
{
|
||||||
|
@ -68,9 +72,15 @@ QualifyDropStatisticsStmt(Node *node)
|
||||||
|
|
||||||
if (stat->schemaname == NULL)
|
if (stat->schemaname == NULL)
|
||||||
{
|
{
|
||||||
Oid schemaOid = RangeVarGetCreationNamespace(stat);
|
Oid statsOid = get_statistics_object_oid(objectNameList,
|
||||||
|
dropStatisticsStmt->missing_ok);
|
||||||
|
|
||||||
|
if (OidIsValid(statsOid))
|
||||||
|
{
|
||||||
|
Oid schemaOid = GetStatsNamespaceOid(statsOid);
|
||||||
stat->schemaname = get_namespace_name(schemaOid);
|
stat->schemaname = get_namespace_name(schemaOid);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
objectNameListWithSchema = lappend(objectNameListWithSchema,
|
objectNameListWithSchema = lappend(objectNameListWithSchema,
|
||||||
MakeNameListFromRangeVar(stat));
|
MakeNameListFromRangeVar(stat));
|
||||||
|
@ -94,7 +104,14 @@ QualifyAlterStatisticsRenameStmt(Node *node)
|
||||||
if (list_length(nameList) == 1)
|
if (list_length(nameList) == 1)
|
||||||
{
|
{
|
||||||
RangeVar *stat = makeRangeVarFromNameList(nameList);
|
RangeVar *stat = makeRangeVarFromNameList(nameList);
|
||||||
Oid schemaOid = RangeVarGetCreationNamespace(stat);
|
Oid statsOid = get_statistics_object_oid(nameList, renameStmt->missing_ok);
|
||||||
|
|
||||||
|
if (!OidIsValid(statsOid))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Oid schemaOid = GetStatsNamespaceOid(statsOid);
|
||||||
stat->schemaname = get_namespace_name(schemaOid);
|
stat->schemaname = get_namespace_name(schemaOid);
|
||||||
renameStmt->object = (Node *) MakeNameListFromRangeVar(stat);
|
renameStmt->object = (Node *) MakeNameListFromRangeVar(stat);
|
||||||
}
|
}
|
||||||
|
@ -115,7 +132,14 @@ QualifyAlterStatisticsSchemaStmt(Node *node)
|
||||||
if (list_length(nameList) == 1)
|
if (list_length(nameList) == 1)
|
||||||
{
|
{
|
||||||
RangeVar *stat = makeRangeVarFromNameList(nameList);
|
RangeVar *stat = makeRangeVarFromNameList(nameList);
|
||||||
Oid schemaOid = RangeVarGetCreationNamespace(stat);
|
Oid statsOid = get_statistics_object_oid(nameList, stmt->missing_ok);
|
||||||
|
|
||||||
|
if (!OidIsValid(statsOid))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Oid schemaOid = GetStatsNamespaceOid(statsOid);
|
||||||
stat->schemaname = get_namespace_name(schemaOid);
|
stat->schemaname = get_namespace_name(schemaOid);
|
||||||
stmt->object = (Node *) MakeNameListFromRangeVar(stat);
|
stmt->object = (Node *) MakeNameListFromRangeVar(stat);
|
||||||
}
|
}
|
||||||
|
@ -136,7 +160,14 @@ QualifyAlterStatisticsStmt(Node *node)
|
||||||
if (list_length(stmt->defnames) == 1)
|
if (list_length(stmt->defnames) == 1)
|
||||||
{
|
{
|
||||||
RangeVar *stat = makeRangeVarFromNameList(stmt->defnames);
|
RangeVar *stat = makeRangeVarFromNameList(stmt->defnames);
|
||||||
Oid schemaOid = RangeVarGetCreationNamespace(stat);
|
Oid statsOid = get_statistics_object_oid(stmt->defnames, stmt->missing_ok);
|
||||||
|
|
||||||
|
if (!OidIsValid(statsOid))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Oid schemaOid = GetStatsNamespaceOid(statsOid);
|
||||||
stat->schemaname = get_namespace_name(schemaOid);
|
stat->schemaname = get_namespace_name(schemaOid);
|
||||||
stmt->defnames = MakeNameListFromRangeVar(stat);
|
stmt->defnames = MakeNameListFromRangeVar(stat);
|
||||||
}
|
}
|
||||||
|
@ -159,8 +190,40 @@ QualifyAlterStatisticsOwnerStmt(Node *node)
|
||||||
if (list_length(nameList) == 1)
|
if (list_length(nameList) == 1)
|
||||||
{
|
{
|
||||||
RangeVar *stat = makeRangeVarFromNameList(nameList);
|
RangeVar *stat = makeRangeVarFromNameList(nameList);
|
||||||
Oid schemaOid = RangeVarGetCreationNamespace(stat);
|
Oid statsOid = get_statistics_object_oid(nameList, /* missing_ok */ true);
|
||||||
|
|
||||||
|
if (!OidIsValid(statsOid))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Oid schemaOid = GetStatsNamespaceOid(statsOid);
|
||||||
stat->schemaname = get_namespace_name(schemaOid);
|
stat->schemaname = get_namespace_name(schemaOid);
|
||||||
stmt->object = (Node *) MakeNameListFromRangeVar(stat);
|
stmt->object = (Node *) MakeNameListFromRangeVar(stat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* GetStatsNamespaceOid takes the id of a Statistics object and returns
|
||||||
|
* the id of the schema that the statistics object belongs to.
|
||||||
|
* Errors out if the stats object is not found.
|
||||||
|
*/
|
||||||
|
static Oid
|
||||||
|
GetStatsNamespaceOid(Oid statsOid)
|
||||||
|
{
|
||||||
|
HeapTuple heapTuple = SearchSysCache1(STATEXTOID, ObjectIdGetDatum(statsOid));
|
||||||
|
if (!HeapTupleIsValid(heapTuple))
|
||||||
|
{
|
||||||
|
ereport(ERROR, (errmsg("cache lookup failed for statistics "
|
||||||
|
"object with oid %u", statsOid)));
|
||||||
|
}
|
||||||
|
FormData_pg_statistic_ext *statisticsForm =
|
||||||
|
(FormData_pg_statistic_ext *) GETSTRUCT(heapTuple);
|
||||||
|
|
||||||
|
Oid result = statisticsForm->stxnamespace;
|
||||||
|
|
||||||
|
ReleaseSysCache(heapTuple);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
|
@ -224,7 +224,7 @@ ERROR: operation is not allowed on this node
|
||||||
CREATE STATISTICS stx9 ON a, b FROM citus_local_table_stats2;
|
CREATE STATISTICS stx9 ON a, b FROM citus_local_table_stats2;
|
||||||
DROP STATISTICS stx8;
|
DROP STATISTICS stx8;
|
||||||
DROP STATISTICS stx4;
|
DROP STATISTICS stx4;
|
||||||
ERROR: statistics object "citus_local_tables_mx.stx4" does not exist
|
ERROR: statistics object "stx4" does not exist
|
||||||
SELECT stxname FROM pg_statistic_ext ORDER BY stxname;
|
SELECT stxname FROM pg_statistic_ext ORDER BY stxname;
|
||||||
stxname
|
stxname
|
||||||
---------------------------------------------------------------------
|
---------------------------------------------------------------------
|
||||||
|
|
|
@ -70,12 +70,12 @@ CREATE STATISTICS s5 ON a,b FROM test_stats4;
|
||||||
-- s6 doesn't exist
|
-- s6 doesn't exist
|
||||||
DROP STATISTICS IF EXISTS s3, sc2.s4, s6;
|
DROP STATISTICS IF EXISTS s3, sc2.s4, s6;
|
||||||
DROP STATISTICS s5,s6;
|
DROP STATISTICS s5,s6;
|
||||||
ERROR: statistics object "statistics'Test.s6" does not exist
|
ERROR: statistics object "s6" does not exist
|
||||||
DROP STATISTICS IF EXISTS s5,s5,s6,s6;
|
DROP STATISTICS IF EXISTS s5,s5,s6,s6;
|
||||||
-- test renaming statistics
|
-- test renaming statistics
|
||||||
CREATE STATISTICS s6 ON a,b FROM test_stats4;
|
CREATE STATISTICS s6 ON a,b FROM test_stats4;
|
||||||
DROP STATISTICS s7;
|
DROP STATISTICS s7;
|
||||||
ERROR: statistics object "statistics'Test.s7" does not exist
|
ERROR: statistics object "s7" does not exist
|
||||||
ALTER STATISTICS s6 RENAME TO s7;
|
ALTER STATISTICS s6 RENAME TO s7;
|
||||||
ALTER STATISTICS sc1.st1 RENAME TO st1_new;
|
ALTER STATISTICS sc1.st1 RENAME TO st1_new;
|
||||||
-- test altering stats schema
|
-- test altering stats schema
|
||||||
|
|
Loading…
Reference in New Issue