From: Robert Haas Date: Tue, 7 Jan 2020 19:23:25 +0000 (-0500) Subject: tableam: Allow choice of toast AM. X-Git-Tag: REL_13_BETA1~916 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=83322e38da1aa054e1b144cb37e6074a86854199;p=thirdparty%2Fpostgresql.git 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 --- diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c index a6c369eaea7..1ed60f4f4e5 100644 --- a/src/backend/access/heap/heapam_handler.c +++ b/src/backend/access/heap/heapam_handler.c @@ -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, diff --git a/src/backend/catalog/toasting.c b/src/backend/catalog/toasting.c index 2dfac45b5bc..33344476cac 100644 --- a/src/backend/catalog/toasting.c +++ b/src/backend/catalog/toasting.c @@ -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, diff --git a/src/include/access/tableam.h b/src/include/access/tableam.h index b14082a6f64..c30a435b72c 100644 --- a/src/include/access/tableam.h +++ b/src/include/access/tableam.h @@ -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