mirror of
https://github.com/postgres/postgres.git
synced 2025-05-25 00:04:05 -04:00
Fix bogus Name assignment in CreateStatistics
Apparently, it doesn't work to use a plain cstring as a Name datum: you may end up having random bytes because of failing to zero the bytes after the terminating \0, as indicated by valgrind. I introduced this bug in 5564c1181548, so backpatch this fix to REL_10_STABLE, like that commit. While at it, fix a slightly misleading comment, pointed out by David Rowley.
This commit is contained in:
parent
4c831aeaa7
commit
1ffb63a2a1
@ -57,6 +57,7 @@ CreateStatistics(CreateStatsStmt *stmt)
|
|||||||
int16 attnums[STATS_MAX_DIMENSIONS];
|
int16 attnums[STATS_MAX_DIMENSIONS];
|
||||||
int numcols = 0;
|
int numcols = 0;
|
||||||
char *namestr;
|
char *namestr;
|
||||||
|
NameData stxname;
|
||||||
Oid statoid;
|
Oid statoid;
|
||||||
Oid namespaceId;
|
Oid namespaceId;
|
||||||
Oid stxowner = GetUserId();
|
Oid stxowner = GetUserId();
|
||||||
@ -135,7 +136,8 @@ CreateStatistics(CreateStatsStmt *stmt)
|
|||||||
* object in the same namespace as the relation, and cons up a name for it.
|
* object in the same namespace as the relation, and cons up a name for it.
|
||||||
*/
|
*/
|
||||||
if (stmt->defnames)
|
if (stmt->defnames)
|
||||||
namespaceId = QualifiedNameGetCreationNamespace(stmt->defnames, &namestr);
|
namespaceId = QualifiedNameGetCreationNamespace(stmt->defnames,
|
||||||
|
&namestr);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
namespaceId = RelationGetNamespace(rel);
|
namespaceId = RelationGetNamespace(rel);
|
||||||
@ -144,6 +146,7 @@ CreateStatistics(CreateStatsStmt *stmt)
|
|||||||
"stat",
|
"stat",
|
||||||
namespaceId);
|
namespaceId);
|
||||||
}
|
}
|
||||||
|
namestrcpy(&stxname, namestr);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Deal with the possibility that the statistics object already exists.
|
* Deal with the possibility that the statistics object already exists.
|
||||||
@ -307,7 +310,7 @@ CreateStatistics(CreateStatsStmt *stmt)
|
|||||||
memset(values, 0, sizeof(values));
|
memset(values, 0, sizeof(values));
|
||||||
memset(nulls, false, sizeof(nulls));
|
memset(nulls, false, sizeof(nulls));
|
||||||
values[Anum_pg_statistic_ext_stxrelid - 1] = ObjectIdGetDatum(relid);
|
values[Anum_pg_statistic_ext_stxrelid - 1] = ObjectIdGetDatum(relid);
|
||||||
values[Anum_pg_statistic_ext_stxname - 1] = CStringGetDatum(namestr);
|
values[Anum_pg_statistic_ext_stxname - 1] = NameGetDatum(&stxname);
|
||||||
values[Anum_pg_statistic_ext_stxnamespace - 1] = ObjectIdGetDatum(namespaceId);
|
values[Anum_pg_statistic_ext_stxnamespace - 1] = ObjectIdGetDatum(namespaceId);
|
||||||
values[Anum_pg_statistic_ext_stxowner - 1] = ObjectIdGetDatum(stxowner);
|
values[Anum_pg_statistic_ext_stxowner - 1] = ObjectIdGetDatum(stxowner);
|
||||||
values[Anum_pg_statistic_ext_stxkeys - 1] = PointerGetDatum(stxkeys);
|
values[Anum_pg_statistic_ext_stxkeys - 1] = PointerGetDatum(stxkeys);
|
||||||
|
@ -2250,7 +2250,8 @@ transformIndexConstraint(Constraint *constraint, CreateStmtContext *cxt)
|
|||||||
* transformExtendedStatistics
|
* transformExtendedStatistics
|
||||||
* Handle extended statistic objects
|
* Handle extended statistic objects
|
||||||
*
|
*
|
||||||
* Right now, there's nothing to do here, so we just copy the list.
|
* Right now, there's nothing to do here, so we just append the list to
|
||||||
|
* the existing "after" list.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
transformExtendedStatistics(CreateStmtContext *cxt)
|
transformExtendedStatistics(CreateStmtContext *cxt)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user