Skip to content

Commit

Permalink
Resolve cherry-pikc issues. Bring back toast_tuple_target logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
reshke committed Jan 28, 2025
1 parent 972ee7f commit 38a40d8
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/backend/access/appendonly/appendonlyam.c
Original file line number Diff line number Diff line change
Expand Up @@ -2897,7 +2897,7 @@ appendonly_insert(AppendOnlyInsertDesc aoInsertDesc,
*/
if (need_toast)
tup = memtup_toast_insert_or_update(relation, instup,
NULL, aoInsertDesc->mt_bind, 0);
NULL, aoInsertDesc->mt_bind, aoInsertDesc->toast_tuple_target, 0);
else
tup = instup;

Expand Down
54 changes: 54 additions & 0 deletions src/backend/access/common/reloptions_gp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1968,3 +1968,57 @@ ao_amoptions(Datum reloptions, char relkind, bool validate)
return NULL;
}
}

/*
* GPDB: Convenience function to judge a relation option whether already in opts
*/
bool
reloptions_has_opt(List *opts, const char *name)
{
ListCell *lc;
foreach(lc, opts)
{
DefElem *de = lfirst(lc);
if (pg_strcasecmp(de->defname, name) == 0)
return true;
}
return false;
}

/*
* GPDB: Convenience function to build storage reloptions for a given relation, just for AO table.
*/
List *
build_ao_rel_storage_opts(List *opts, Relation rel)
{
bool checksum = true;
int32 blocksize = -1;
int16 compresslevel = 0;
char *compresstype = NULL;
NameData compresstype_nd;

GetAppendOnlyEntryAttributes(RelationGetRelid(rel),
&blocksize,
NULL,
&compresslevel,
&checksum,
&compresstype_nd);
compresstype = NameStr(compresstype_nd);

if (!reloptions_has_opt(opts, "blocksize"))
opts = lappend(opts, makeDefElem("blocksize", (Node *) makeInteger(blocksize), -1));

if (!reloptions_has_opt(opts, "compresslevel"))
opts = lappend(opts, makeDefElem("compresslevel", (Node *) makeInteger(compresslevel), -1));

if (!reloptions_has_opt(opts, "checksum"))
opts = lappend(opts, makeDefElem("checksum", (Node *) makeInteger(checksum), -1));

if (!reloptions_has_opt(opts, "compresstype"))
{
compresstype = (compresstype && compresstype[0]) ? pstrdup(compresstype) : "none";
opts = lappend(opts, makeDefElem("compresstype", (Node *) makeString(compresstype), -1));
}

return opts;
}
10 changes: 5 additions & 5 deletions src/backend/access/heap/heaptoast.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

static void *
heap_toast_insert_or_update_generic(Relation rel, void *newtup, void *oldtup,
MemTupleBinding *pbind, int options, bool ismemtuple);
MemTupleBinding *pbind, int options, int toast_tuple_target, bool ismemtuple);

/* ----------
* heap_toast_delete -
Expand Down Expand Up @@ -100,18 +100,18 @@ heap_toast_delete(Relation rel, HeapTuple oldtup, bool is_speculative)
HeapTuple
heap_toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup, int options)
{
return (HeapTuple) heap_toast_insert_or_update_generic(rel, newtup, oldtup, NULL, options, false);
return (HeapTuple) heap_toast_insert_or_update_generic(rel, newtup, oldtup, NULL, options, TOAST_TUPLE_TARGET, false);
}

MemTuple memtup_toast_insert_or_update(Relation rel, MemTuple newtup, MemTuple oldtup,
MemTupleBinding *pbind, int options)
MemTupleBinding *pbind, int toast_tuple_target, int options)
{
return (MemTuple) heap_toast_insert_or_update_generic(rel, newtup, oldtup, pbind, options, true);
return (MemTuple) heap_toast_insert_or_update_generic(rel, newtup, oldtup, pbind, toast_tuple_target, options, true);
}

static void *
heap_toast_insert_or_update_generic(Relation rel, void *newtup, void *oldtup,
MemTupleBinding *pbind, int options, bool ismemtuple)
MemTupleBinding *pbind, int options, int toast_tuple_target, bool ismemtuple)
{
void *result_gtuple;
TupleDesc tupleDesc;
Expand Down
2 changes: 1 addition & 1 deletion src/include/access/heaptoast.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
*/
extern HeapTuple heap_toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup, int options);
extern MemTuple memtup_toast_insert_or_update(Relation rel, MemTuple newtup, MemTuple oldtup,
MemTupleBinding *pbind, int options);
MemTupleBinding *pbind, int toast_tuple_target, int options);

/* ----------
* heap_toast_delete -
Expand Down
2 changes: 2 additions & 0 deletions src/include/access/reloptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ List* transfromColumnEncodingAocoRootPartition(List *colDefs, List *stenc, List
extern List *transformStorageEncodingClause(List *options, bool validate);
extern List *form_default_storage_directive(List *enc);
extern bool is_storage_encoding_directive(const char *name);
extern bool reloptions_has_opt(List *opts, const char *name);
extern List *build_ao_rel_storage_opts(List *opts, Relation rel);

extern relopt_value *
parseRelOptions(Datum options, bool validate, relopt_kind kind, int *numrelopts);
Expand Down

0 comments on commit 38a40d8

Please sign in to comment.