mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-09-06 15:39:21 +02:00
Fix freeing old values in index_store_float8_orderby_distances()
6cae9d2c10
has added an error in freeing old values in
index_store_float8_orderby_distances() function. It looks for old value in
scan->xs_orderbynulls[i] after setting a new value there.
This commit fixes that. Also it removes short-circuit in handling
distances == NULL situation. Now distances == NULL will be treated the same
way as array with all null distances. That is, previous values will be freed
if any.
Reported-by: Tom Lane, Nikita Glukhov
Discussion: https://postgr.es/m/CAPpHfdu2wcoAVAm3Ek66rP%3Duo_C-D84%2B%2Buf1VEcbyi_caBXWCA%40mail.gmail.com
Discussion: https://postgr.es/m/426580d3-a668-b9d1-7b8e-f74d1a6524e0%40postgrespro.ru
Backpatch-through: 12
This commit is contained in:
parent
31cbd76057
commit
8c58e480d9
@ -852,28 +852,12 @@ index_store_float8_orderby_distances(IndexScanDesc scan, Oid *orderByTypes,
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
Assert(distances || !recheckOrderBy);
|
||||||
|
|
||||||
scan->xs_recheckorderby = recheckOrderBy;
|
scan->xs_recheckorderby = recheckOrderBy;
|
||||||
|
|
||||||
if (!distances)
|
|
||||||
{
|
|
||||||
Assert(!scan->xs_recheckorderby);
|
|
||||||
|
|
||||||
for (i = 0; i < scan->numberOfOrderBys; i++)
|
for (i = 0; i < scan->numberOfOrderBys; i++)
|
||||||
{
|
{
|
||||||
scan->xs_orderbyvals[i] = (Datum) 0;
|
|
||||||
scan->xs_orderbynulls[i] = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < scan->numberOfOrderBys; i++)
|
|
||||||
{
|
|
||||||
scan->xs_orderbynulls[i] = distances[i].isnull;
|
|
||||||
|
|
||||||
if (scan->xs_orderbynulls[i])
|
|
||||||
scan->xs_orderbyvals[i] = (Datum) 0;
|
|
||||||
|
|
||||||
if (orderByTypes[i] == FLOAT8OID)
|
if (orderByTypes[i] == FLOAT8OID)
|
||||||
{
|
{
|
||||||
#ifndef USE_FLOAT8_BYVAL
|
#ifndef USE_FLOAT8_BYVAL
|
||||||
@ -881,8 +865,16 @@ index_store_float8_orderby_distances(IndexScanDesc scan, Oid *orderByTypes,
|
|||||||
if (!scan->xs_orderbynulls[i])
|
if (!scan->xs_orderbynulls[i])
|
||||||
pfree(DatumGetPointer(scan->xs_orderbyvals[i]));
|
pfree(DatumGetPointer(scan->xs_orderbyvals[i]));
|
||||||
#endif
|
#endif
|
||||||
if (!scan->xs_orderbynulls[i])
|
if (distances && !distances[i].isnull)
|
||||||
|
{
|
||||||
scan->xs_orderbyvals[i] = Float8GetDatum(distances[i].value);
|
scan->xs_orderbyvals[i] = Float8GetDatum(distances[i].value);
|
||||||
|
scan->xs_orderbynulls[i] = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
scan->xs_orderbyvals[i] = (Datum) 0;
|
||||||
|
scan->xs_orderbynulls[i] = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (orderByTypes[i] == FLOAT4OID)
|
else if (orderByTypes[i] == FLOAT4OID)
|
||||||
{
|
{
|
||||||
@ -892,8 +884,16 @@ index_store_float8_orderby_distances(IndexScanDesc scan, Oid *orderByTypes,
|
|||||||
if (!scan->xs_orderbynulls[i])
|
if (!scan->xs_orderbynulls[i])
|
||||||
pfree(DatumGetPointer(scan->xs_orderbyvals[i]));
|
pfree(DatumGetPointer(scan->xs_orderbyvals[i]));
|
||||||
#endif
|
#endif
|
||||||
if (!scan->xs_orderbynulls[i])
|
if (distances && !distances[i].isnull)
|
||||||
|
{
|
||||||
scan->xs_orderbyvals[i] = Float4GetDatum((float4) distances[i].value);
|
scan->xs_orderbyvals[i] = Float4GetDatum((float4) distances[i].value);
|
||||||
|
scan->xs_orderbynulls[i] = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
scan->xs_orderbyvals[i] = (Datum) 0;
|
||||||
|
scan->xs_orderbynulls[i] = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user