mirror of https://github.com/citusdata/citus.git
Moves creation of ALTER INDEX STATISTICS commands next to index commands
parent
7124a7715d
commit
27c2bd1599
|
@ -49,7 +49,6 @@
|
||||||
#define ALTER_INDEX_COLUMN_SET_STATS_COMMAND \
|
#define ALTER_INDEX_COLUMN_SET_STATS_COMMAND \
|
||||||
"ALTER INDEX %s ALTER COLUMN %d SET STATISTICS %d"
|
"ALTER INDEX %s ALTER COLUMN %d SET STATISTICS %d"
|
||||||
|
|
||||||
static List * GetAlterIndexStatisticsCommands(Oid indexOid);
|
|
||||||
static List * GetExplicitStatisticsIdList(Oid relationId);
|
static List * GetExplicitStatisticsIdList(Oid relationId);
|
||||||
static char * GenerateAlterIndexColumnSetStatsCommand(char *indexNameWithSchema,
|
static char * GenerateAlterIndexColumnSetStatsCommand(char *indexNameWithSchema,
|
||||||
int16 attnum,
|
int16 attnum,
|
||||||
|
@ -474,21 +473,6 @@ GetExplicitStatisticsCommandList(Oid relationId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* find indexes on current relation, in case of modified stats target */
|
|
||||||
Relation relation = relation_open(relationId, AccessShareLock);
|
|
||||||
List *indexOidList = RelationGetIndexList(relation);
|
|
||||||
relation_close(relation, NoLock);
|
|
||||||
|
|
||||||
Oid indexId = InvalidOid;
|
|
||||||
foreach_oid(indexId, indexOidList)
|
|
||||||
{
|
|
||||||
/* we need alter index commands for altered targets on expression indexes */
|
|
||||||
List *alterIndexStatisticsCommands = GetAlterIndexStatisticsCommands(indexId);
|
|
||||||
|
|
||||||
explicitStatisticsCommandList =
|
|
||||||
list_concat(explicitStatisticsCommandList, alterIndexStatisticsCommands);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* revert back to original search_path */
|
/* revert back to original search_path */
|
||||||
PopOverrideSearchPath();
|
PopOverrideSearchPath();
|
||||||
|
|
||||||
|
@ -547,7 +531,7 @@ GetExplicitStatisticsSchemaIdList(Oid relationId)
|
||||||
* Note that this function only looks for expression indexes, since this command is
|
* Note that this function only looks for expression indexes, since this command is
|
||||||
* valid for only expression indexes.
|
* valid for only expression indexes.
|
||||||
*/
|
*/
|
||||||
static List *
|
List *
|
||||||
GetAlterIndexStatisticsCommands(Oid indexOid)
|
GetAlterIndexStatisticsCommands(Oid indexOid)
|
||||||
{
|
{
|
||||||
List *alterIndexStatisticsCommandList = NIL;
|
List *alterIndexStatisticsCommandList = NIL;
|
||||||
|
|
|
@ -736,6 +736,10 @@ GatherIndexAndConstraintDefinitionList(Form_pg_index indexForm, List **indexDDLE
|
||||||
*indexDDLEventList = lappend(*indexDDLEventList, makeTableDDLCommandString(
|
*indexDDLEventList = lappend(*indexDDLEventList, makeTableDDLCommandString(
|
||||||
clusteredDef));
|
clusteredDef));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* we need alter index commands for altered targets on expression indexes */
|
||||||
|
List *alterIndexStatisticsCommands = GetAlterIndexStatisticsCommands(indexId);
|
||||||
|
*indexDDLEventList = list_concat(*indexDDLEventList, alterIndexStatisticsCommands);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -348,6 +348,7 @@ extern List * PreprocessAlterStatisticsOwnerStmt(Node *node, const char *querySt
|
||||||
processUtilityContext);
|
processUtilityContext);
|
||||||
extern List * GetExplicitStatisticsCommandList(Oid relationId);
|
extern List * GetExplicitStatisticsCommandList(Oid relationId);
|
||||||
extern List * GetExplicitStatisticsSchemaIdList(Oid relationId);
|
extern List * GetExplicitStatisticsSchemaIdList(Oid relationId);
|
||||||
|
extern List * GetAlterIndexStatisticsCommands(Oid indexOid);
|
||||||
|
|
||||||
/* subscription.c - forward declarations */
|
/* subscription.c - forward declarations */
|
||||||
extern Node * ProcessCreateSubscriptionStmt(CreateSubscriptionStmt *createSubStmt);
|
extern Node * ProcessCreateSubscriptionStmt(CreateSubscriptionStmt *createSubStmt);
|
||||||
|
|
|
@ -294,11 +294,15 @@ DROP TABLE time_partitioned;
|
||||||
-- the index will be dropped
|
-- the index will be dropped
|
||||||
CREATE TABLE index_table (a INT) ;
|
CREATE TABLE index_table (a INT) ;
|
||||||
CREATE INDEX idx1 ON index_table (a);
|
CREATE INDEX idx1 ON index_table (a);
|
||||||
|
-- also create an index with statistics
|
||||||
|
CREATE INDEX idx2 ON index_table ((a+1));
|
||||||
|
ALTER INDEX idx2 ALTER COLUMN 1 SET STATISTICS 300;
|
||||||
SELECT indexname FROM pg_indexes WHERE schemaname = 'alter_table_set_access_method' AND tablename = 'index_table';
|
SELECT indexname FROM pg_indexes WHERE schemaname = 'alter_table_set_access_method' AND tablename = 'index_table';
|
||||||
indexname
|
indexname
|
||||||
---------------------------------------------------------------------
|
---------------------------------------------------------------------
|
||||||
idx1
|
idx1
|
||||||
(1 row)
|
idx2
|
||||||
|
(2 rows)
|
||||||
|
|
||||||
SELECT a.amname FROM pg_class c, pg_am a where c.relname = 'index_table' AND c.relnamespace = 'alter_table_set_access_method'::regnamespace AND c.relam = a.oid;
|
SELECT a.amname FROM pg_class c, pg_am a where c.relname = 'index_table' AND c.relnamespace = 'alter_table_set_access_method'::regnamespace AND c.relam = a.oid;
|
||||||
amname
|
amname
|
||||||
|
|
|
@ -99,6 +99,9 @@ DROP TABLE time_partitioned;
|
||||||
-- the index will be dropped
|
-- the index will be dropped
|
||||||
CREATE TABLE index_table (a INT) USING heap;
|
CREATE TABLE index_table (a INT) USING heap;
|
||||||
CREATE INDEX idx1 ON index_table (a);
|
CREATE INDEX idx1 ON index_table (a);
|
||||||
|
-- also create an index with statistics
|
||||||
|
CREATE INDEX idx2 ON index_table ((a+1));
|
||||||
|
ALTER INDEX idx2 ALTER COLUMN 1 SET STATISTICS 300;
|
||||||
SELECT indexname FROM pg_indexes WHERE schemaname = 'alter_table_set_access_method' AND tablename = 'index_table';
|
SELECT indexname FROM pg_indexes WHERE schemaname = 'alter_table_set_access_method' AND tablename = 'index_table';
|
||||||
SELECT a.amname FROM pg_class c, pg_am a where c.relname = 'index_table' AND c.relnamespace = 'alter_table_set_access_method'::regnamespace AND c.relam = a.oid;
|
SELECT a.amname FROM pg_class c, pg_am a where c.relname = 'index_table' AND c.relnamespace = 'alter_table_set_access_method'::regnamespace AND c.relam = a.oid;
|
||||||
SELECT alter_table_set_access_method('index_table', 'columnar');
|
SELECT alter_table_set_access_method('index_table', 'columnar');
|
||||||
|
|
Loading…
Reference in New Issue