Skip to content

Commit 5c7b64d

Browse files
bmdoilreshke
authored andcommitted
Remove upgrade_tuple and related code.
These functions were used to upgrade AO relations from formats that existed in GPDB 3/4X and are no longer relevant. - formatversion is always > AORelationVersion_Aligned64bit, so convert_alignment is false - PG82NumericConversionNeeded() is always false, so convert_numerics is always false This also resolves a FIXME in appendonlyam.c Authored-by: Brent Doil <[email protected]>
1 parent eec3f2b commit 5c7b64d

File tree

11 files changed

+0
-823
lines changed

11 files changed

+0
-823
lines changed

src/backend/access/aocs/aocsam.c

Lines changed: 0 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -675,80 +675,6 @@ aocs_endscan(AOCSScanDesc scan)
675675
pfree(scan);
676676
}
677677

678-
/*
679-
* Upgrades a Datum value from a previous version of the AOCS page format. The
680-
* DatumStreamRead that is passed must correspond to the column being upgraded.
681-
*/
682-
static void upgrade_datum_impl(DatumStreamRead *ds, int attno, Datum values[],
683-
bool isnull[], int formatversion)
684-
{
685-
bool convert_numeric = false;
686-
687-
if (PG82NumericConversionNeeded(formatversion))
688-
{
689-
/*
690-
* On the first call for this DatumStream, figure out if this column is
691-
* a numeric, or a domain over numerics.
692-
*
693-
* TODO: consolidate this code with upgrade_tuple() in appendonlyam.c.
694-
*/
695-
if (!OidIsValid(ds->baseTypeOid))
696-
{
697-
ds->baseTypeOid = getBaseType(ds->typeInfo.typid);
698-
}
699-
700-
/* If this Datum is a numeric, we need to convert it. */
701-
convert_numeric = (ds->baseTypeOid == NUMERICOID) && !isnull[attno];
702-
}
703-
704-
if (convert_numeric)
705-
{
706-
/*
707-
* Before PostgreSQL 8.3, the n_weight and n_sign_dscale fields were the
708-
* other way 'round. Swap them.
709-
*/
710-
Datum datum;
711-
char *numericdata;
712-
char *upgradedata;
713-
size_t datalen;
714-
uint16 tmp;
715-
716-
/*
717-
* We need to make a copy of this data so that any other tuples pointing
718-
* to it won't be affected. Store it in the upgrade space for this
719-
* DatumStream.
720-
*/
721-
datum = values[attno];
722-
datalen = VARSIZE_ANY(DatumGetPointer(datum));
723-
724-
upgradedata = datumstreamread_get_upgrade_space(ds, datalen);
725-
memcpy(upgradedata, DatumGetPointer(datum), datalen);
726-
727-
/* Swap the fields. */
728-
numericdata = VARDATA_ANY(upgradedata);
729-
730-
memcpy(&tmp, &numericdata[0], 2);
731-
memcpy(&numericdata[0], &numericdata[2], 2);
732-
memcpy(&numericdata[2], &tmp, 2);
733-
734-
/* Re-point the Datum to the upgraded numeric. */
735-
values[attno] = PointerGetDatum(upgradedata);
736-
}
737-
}
738-
739-
static void upgrade_datum_scan(AOCSScanDesc scan, int attno, Datum values[],
740-
bool isnull[], int formatversion)
741-
{
742-
upgrade_datum_impl(scan->columnScanInfo.ds[attno], attno, values, isnull, formatversion);
743-
}
744-
745-
static void upgrade_datum_fetch(AOCSFetchDesc fetch, int attno, Datum values[],
746-
bool isnull[], int formatversion)
747-
{
748-
upgrade_datum_impl(fetch->datumStreamFetchDesc[attno]->datumStream, attno,
749-
values, isnull, formatversion);
750-
}
751-
752678
bool
753679
aocs_getnext(AOCSScanDesc scan, ScanDirection direction, TupleTableSlot *slot)
754680
{
@@ -849,15 +775,6 @@ aocs_getnext(AOCSScanDesc scan, ScanDirection direction, TupleTableSlot *slot)
849775
*/
850776
datumstreamread_get(scan->columnScanInfo.ds[attno], &d[attno], &null[attno]);
851777

852-
/*
853-
* Perform any required upgrades on the Datum we just fetched.
854-
*/
855-
if (curseginfo->formatversion < AOSegfileFormatVersion_GetLatest ())
856-
{
857-
upgrade_datum_scan(scan, attno, d, null,
858-
curseginfo->formatversion);
859-
}
860-
861778
if (i == 0)
862779
{
863780
if (rowNum == INT64CONST(-1) &&
@@ -1291,18 +1208,8 @@ fetchFromCurrentBlock(AOCSFetchDesc aocsFetchDesc,
12911208
{
12921209
Datum *values = slot->tts_values;
12931210
bool *nulls = slot->tts_isnull;
1294-
int formatversion = datumStream->ao_read.formatVersion;
12951211

12961212
datumstreamread_get(datumStream, &(values[colno]), &(nulls[colno]));
1297-
1298-
/*
1299-
* Perform any required upgrades on the Datum we just fetched.
1300-
*/
1301-
if (formatversion < AOSegfileFormatVersion_GetLatest ())
1302-
{
1303-
upgrade_datum_fetch(aocsFetchDesc, colno, values, nulls,
1304-
formatversion);
1305-
}
13061213
}
13071214
else
13081215
{
@@ -2598,15 +2505,6 @@ aocs_getnext_sample(AOCSScanDesc scan, ScanDirection direction, TupleTableSlot *
25982505
*/
25992506
datumstreamread_get(scan->columnScanInfo.ds[attno], &d[attno], &null[attno]);
26002507

2601-
/*
2602-
* Perform any required upgrades on the Datum we just fetched.
2603-
*/
2604-
if (curseginfo->formatversion < AOSegfileFormatVersion_GetLatest ())
2605-
{
2606-
upgrade_datum_scan(scan, attno, d, null,
2607-
curseginfo->formatversion);
2608-
}
2609-
26102508
/*
26112509
* set rowNum, aoTupleId and test visibility.
26122510
*/

src/backend/access/appendonly/appendonlyam.c

Lines changed: 0 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -783,141 +783,6 @@ AppendOnlyExecutorReadBlock_ResetCounts(AppendOnlyExecutorReadBlock *executorRea
783783
executorReadBlock->totalRowsScanned = 0;
784784
}
785785

786-
/*
787-
* Given a tuple in 'formatversion', convert it to a format that is
788-
* understood by the rest of the system.
789-
*/
790-
static MemTuple
791-
upgrade_tuple(AppendOnlyExecutorReadBlock *executorReadBlock,
792-
MemTuple mtup, MemTupleBinding *pbind, int formatversion, bool *shouldFree)
793-
{
794-
TupleDesc tupdesc = pbind->tupdesc;
795-
const int natts = tupdesc->natts;
796-
MemTuple newtuple;
797-
int i;
798-
799-
static Datum *values = NULL;
800-
static bool *isnull = NULL;
801-
static int nallocated = 0;
802-
803-
bool convert_alignment = false;
804-
bool convert_numerics = false;
805-
806-
/*
807-
* MPP-7372: If the AO table was created before the fix for this issue, it
808-
* may contain tuples with misaligned bindings. Here we check if the
809-
* stored memtuple is problematic and then create a clone of the tuple
810-
* with properly aligned bindings to be used by the executor.
811-
*/
812-
if (formatversion < AOSegfileFormatVersion_Aligned64bit &&
813-
memtuple_has_misaligned_attribute(mtup, pbind))
814-
convert_alignment = true;
815-
816-
if (PG82NumericConversionNeeded(formatversion))
817-
{
818-
/*
819-
* On first call, figure out which columns are numerics, or domains
820-
* over numerics.
821-
*/
822-
if (executorReadBlock->numericAtts == NULL)
823-
{
824-
int n;
825-
826-
executorReadBlock->numericAtts = (int *) palloc(natts * sizeof(int));
827-
828-
n = 0;
829-
for (i = 0; i < natts; i++)
830-
{
831-
Oid typeoid;
832-
833-
typeoid = getBaseType(TupleDescAttr(tupdesc, i)->atttypid);
834-
if (typeoid == NUMERICOID)
835-
executorReadBlock->numericAtts[n++] = i;
836-
}
837-
executorReadBlock->numNumericAtts = n;
838-
}
839-
840-
/* If there were any numeric columns, we need to convert them. */
841-
if (executorReadBlock->numNumericAtts > 0)
842-
convert_numerics = true;
843-
}
844-
845-
if (!convert_alignment && !convert_numerics)
846-
{
847-
/* No conversion required. Return the original tuple unmodified. */
848-
*shouldFree = false;
849-
return mtup;
850-
}
851-
852-
/* Conversion is needed. */
853-
854-
/* enlarge the arrays if needed */
855-
if (natts > nallocated)
856-
{
857-
if (values)
858-
pfree(values);
859-
if (isnull)
860-
pfree(isnull);
861-
values = (Datum *) MemoryContextAlloc(TopMemoryContext, natts * sizeof(Datum));
862-
isnull = (bool *) MemoryContextAlloc(TopMemoryContext, natts * sizeof(bool));
863-
nallocated = natts;
864-
}
865-
866-
if (convert_alignment)
867-
{
868-
/* get attribute values form mis-aligned tuple */
869-
memtuple_deform_misaligned(mtup, pbind, values, isnull);
870-
/* Form a new, properly-aligned, tuple */
871-
newtuple = memtuple_form(pbind, values, isnull);
872-
}
873-
else
874-
{
875-
/*
876-
* make a modifiable copy
877-
*/
878-
newtuple = memtuple_copy(mtup);
879-
}
880-
881-
/*
882-
* NOTE: we do this *after* creating the new tuple, so that we can modify
883-
* the new, copied, tuple in-place.
884-
*/
885-
if (convert_numerics)
886-
{
887-
int i;
888-
889-
/*
890-
* Get pointers to the datums within the tuple
891-
*/
892-
memtuple_deform(newtuple, pbind, values, isnull);
893-
894-
for (i = 0; i < executorReadBlock->numNumericAtts; i++)
895-
{
896-
/*
897-
* Before PostgreSQL 8.3, the n_weight and n_sign_dscale fields
898-
* were the other way 'round. Swap them.
899-
*/
900-
Datum datum;
901-
char *numericdata;
902-
uint16 tmp;
903-
904-
if (isnull[executorReadBlock->numericAtts[i]])
905-
continue;
906-
907-
datum = values[executorReadBlock->numericAtts[i]];
908-
numericdata = VARDATA_ANY(DatumGetPointer(datum));
909-
910-
memcpy(&tmp, &numericdata[0], 2);
911-
memcpy(&numericdata[0], &numericdata[2], 2);
912-
memcpy(&numericdata[2], &tmp, 2);
913-
}
914-
}
915-
916-
*shouldFree = true;
917-
return newtuple;
918-
}
919-
920-
921786
static void
922787
AOExecutorReadBlockBindingInit(AppendOnlyExecutorReadBlock *executorReadBlock,
923788
TupleTableSlot *slot)
@@ -970,11 +835,6 @@ AppendOnlyExecutorReadBlock_ProcessTuple(AppendOnlyExecutorReadBlock *executorRe
970835

971836
Assert(executorReadBlock->mt_bind);
972837

973-
/* If the tuple is not in the latest format, convert it */
974-
// GPDB_12_MERGE_FIXME: Is pg_upgrade from old versions still a thing? Can we drop this?
975-
if (formatVersion < AOSegfileFormatVersion_GetLatest ())
976-
tuple = upgrade_tuple(executorReadBlock, tuple, executorReadBlock->mt_bind, formatVersion, &shouldFree);
977-
978838
ExecClearTuple(slot);
979839
memtuple_deform(tuple, executorReadBlock->mt_bind, slot->tts_values, slot->tts_isnull);
980840
slot->tts_tid = fake_ctid;

src/include/catalog/pg_appendonly.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,6 @@ static inline void AOSegfileFormatVersion_CheckValid(int version)
118118
(version > AOSegfileFormatVersion_Original) \
119119
)
120120

121-
/*
122-
* Are numerics stored in old, pre-PostgreSQL 8.3 format, and need converting?
123-
*/
124-
#define PG82NumericConversionNeeded(version) \
125-
( \
126-
AOSegfileFormatVersion_CheckValid(version), \
127-
(version > AOSegfileFormatVersion_Original) \
128-
)
129-
130121
extern void
131122
InsertAppendOnlyEntry(Oid relid,
132123
int blocksize,

src/test/isolation2/.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ regression.diffs
22
regression.out
33
*/dummy.sql
44
*/dummy.out
5-
sql/ao_upgrade.sql
6-
expected/ao_upgrade.out
7-
expected/ao_upgrade_optimizer.out
85
sql/external_table.sql
96
expected/external_table.out
107
sql/fts_manual_probe.sql

src/test/isolation2/expected/.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
# ignores only for this directory
2-
/ao_upgrade.out
3-
/ao_upgrade_optimizer.out
42
/external_table.out
53
/fts_manual_probe.out
64
/gp_collation.out

0 commit comments

Comments
 (0)