mirror of https://github.com/citusdata/citus.git
attstattarget is nullable, define pg compatible functions for it
Relevant PG commit:
4f622503d6de975ac87448aea5cea7de4bc140d5
4f622503d6
pg17_kickoff
parent
4eafd3a51b
commit
be2bec0b61
|
@ -651,14 +651,15 @@ GetAlterIndexStatisticsCommands(Oid indexOid)
|
|||
}
|
||||
|
||||
Form_pg_attribute targetAttr = (Form_pg_attribute) GETSTRUCT(attTuple);
|
||||
if (targetAttr->attstattarget != DEFAULT_STATISTICS_TARGET)
|
||||
int32 targetAttstattarget = getAttstattarget_compat(attTuple);
|
||||
if (targetAttstattarget != DEFAULT_STATISTICS_TARGET)
|
||||
{
|
||||
char *indexNameWithSchema = generate_qualified_relation_name(indexOid);
|
||||
|
||||
char *command =
|
||||
GenerateAlterIndexColumnSetStatsCommand(indexNameWithSchema,
|
||||
targetAttr->attnum,
|
||||
targetAttr->attstattarget);
|
||||
targetAttstattarget);
|
||||
|
||||
alterIndexStatisticsCommandList =
|
||||
lappend(alterIndexStatisticsCommandList,
|
||||
|
|
|
@ -738,7 +738,12 @@ pg_get_tablecolumnoptionsdef_string(Oid tableRelationId)
|
|||
* If the user changed the column's statistics target, create
|
||||
* alter statement and add statement to a list for later processing.
|
||||
*/
|
||||
if (attributeForm->attstattarget >= 0)
|
||||
HeapTuple tp = SearchSysCache2(ATTNUM,
|
||||
ObjectIdGetDatum(tableRelationId),
|
||||
Int16GetDatum(attributeForm->attnum));
|
||||
int32 targetAttstattarget = getAttstattarget_compat(tp);
|
||||
ReleaseSysCache(tp);
|
||||
if (targetAttstattarget >= 0)
|
||||
{
|
||||
StringInfoData statement = { NULL, 0, 0, 0 };
|
||||
initStringInfo(&statement);
|
||||
|
@ -746,7 +751,7 @@ pg_get_tablecolumnoptionsdef_string(Oid tableRelationId)
|
|||
appendStringInfo(&statement, "ALTER COLUMN %s ",
|
||||
quote_identifier(attributeName));
|
||||
appendStringInfo(&statement, "SET STATISTICS %d",
|
||||
attributeForm->attstattarget);
|
||||
targetAttstattarget);
|
||||
|
||||
columnOptionList = lappend(columnOptionList, statement.data);
|
||||
}
|
||||
|
|
|
@ -70,6 +70,29 @@ RangeVarCallbackOwnsTable(const RangeVar *relation,
|
|||
}
|
||||
|
||||
|
||||
#include "catalog/pg_attribute.h"
|
||||
#include "utils/syscache.h"
|
||||
|
||||
static inline int32
|
||||
getAttstattarget_compat(HeapTuple attTuple)
|
||||
{
|
||||
bool isnull;
|
||||
Datum dat = SysCacheGetAttr(ATTNUM, attTuple,
|
||||
Anum_pg_attribute_attstattarget, &isnull);
|
||||
return (isnull ? -1 : DatumGetInt16(dat));
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
|
||||
#include "access/htup_details.h"
|
||||
static inline int32
|
||||
getAttstattarget_compat(HeapTuple attTuple)
|
||||
{
|
||||
return ((Form_pg_attribute) GETSTRUCT(attTuple))->attstattarget;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#if PG_VERSION_NUM >= PG_VERSION_16
|
||||
|
|
Loading…
Reference in New Issue