Commit 83322e38 authored by Robert Haas's avatar Robert Haas

tableam: Allow choice of toast AM.

Previously, the toast table had to be implemented by the same AM that
was used for the main table, which was bad, because the detoasting
code won't work with anything but heap. This commit doesn't fix the
latter problem, although there's another patch coming which does,
but it does let you pick something that works (i.e. heap, right now).

Patch by me, reviewed by Andres Freund.

Discussion: http://postgr.es/m/CA+TgmoZv-=2iWM4jcw5ZhJeL18HF96+W1yJeYrnGMYdkFFnEpQ@mail.gmail.com
parent 81472785
......@@ -2037,6 +2037,15 @@ heapam_relation_needs_toast_table(Relation rel)
return (tuple_length > TOAST_TUPLE_THRESHOLD);
}
/*
* TOAST tables for heap relations are just heap relations.
*/
static Oid
heapam_relation_toast_am(Relation rel)
{
return rel->rd_rel->relam;
}
/* ------------------------------------------------------------------------
* Planner related callbacks for the heap AM
......@@ -2535,6 +2544,7 @@ static const TableAmRoutine heapam_methods = {
.relation_size = table_block_relation_size,
.relation_needs_toast_table = heapam_relation_needs_toast_table,
.relation_toast_am = heapam_relation_toast_am,
.relation_estimate_size = heapam_estimate_rel_size,
......
......@@ -258,7 +258,7 @@ create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid,
toast_typid,
InvalidOid,
rel->rd_rel->relowner,
rel->rd_rel->relam,
table_relation_toast_am(rel),
tupdesc,
NIL,
RELKIND_TOASTVALUE,
......
......@@ -581,6 +581,13 @@ typedef struct TableAmRoutine
*/
bool (*relation_needs_toast_table) (Relation rel);
/*
* This callback should return the OID of the table AM that implements
* TOAST tables for this AM. If the relation_needs_toast_table callback
* always returns false, this callback is not required.
*/
Oid (*relation_toast_am) (Relation rel);
/* ------------------------------------------------------------------------
* Planner related functions.
......@@ -1603,6 +1610,16 @@ table_relation_needs_toast_table(Relation rel)
return rel->rd_tableam->relation_needs_toast_table(rel);
}
/*
* Return the OID of the AM that should be used to implement the TOAST table
* for this relation.
*/
static inline Oid
table_relation_toast_am(Relation rel)
{
return rel->rd_tableam->relation_toast_am(rel);
}
/* ----------------------------------------------------------------------------
* Planner related functionality
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment