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 75ce1cd
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 12 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/backend/commands/tablecmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -17912,7 +17912,7 @@ build_ctas_with_dist(Relation rel, DistributedBy *dist_clause,
into->options = storage_opts;
into->tableSpaceName = get_tablespace_name(tblspc);
into->distributedBy = (Node *)dist_clause;
if (RelationIsAoRows(rel))
if (RelationIsAppendOptimized(rel))
{
/*
* In order to avoid being affected by the GUC of gp_default_storage_options,
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
6 changes: 3 additions & 3 deletions src/test/regress/expected/expand_table_ao.out
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ select localoid::regclass::name, policytype, numsegments, distkey, distclass
from gp_distribution_policy where localoid = 't_9526'::regclass::oid;
localoid | policytype | numsegments | distkey | distclass
----------+------------+-------------+---------+-----------
t_9526 | p | 3 | 1 | 10054
t_9526 | p | 3 | 1 | 10020
(1 row)

-- storage paramter should be same with before
Expand Down Expand Up @@ -779,7 +779,7 @@ select localoid::regclass::name, policytype, numsegments, distkey, distclass
from gp_distribution_policy where localoid = 't_9527'::regclass::oid;
localoid | policytype | numsegments | distkey | distclass
----------+------------+-------------+---------+-----------
t_9527 | p | 3 | 1 | 10054
t_9527 | p | 3 | 1 | 10020
(1 row)

-- storage paramter should be same with before
Expand Down Expand Up @@ -818,7 +818,7 @@ select localoid::regclass::name, policytype, numsegments, distkey, distclass
from gp_distribution_policy where localoid = 't_9528'::regclass::oid;
localoid | policytype | numsegments | distkey | distclass
----------+------------+-------------+---------+-----------
t_9528 | p | 2 | 2 | 10072
t_9528 | p | 2 | 2 | 10039
(1 row)

-- storage paramter should be same with before
Expand Down
2 changes: 1 addition & 1 deletion src/test/regress/expected/toast.out
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ select gp_segment_id, get_rel_toast_count('toastable_heap') from gp_dist_random(
select gp_segment_id, get_rel_toast_count('toastable_ao') from gp_dist_random('gp_id') order by gp_segment_id;
gp_segment_id | get_rel_toast_count
---------------+---------------------
0 | 13
0 | 14
1 | 0
2 | 0
(3 rows)
Expand Down

0 comments on commit 75ce1cd

Please sign in to comment.