From 6618e766c9f2def48925a8d20578d58842594a1e Mon Sep 17 00:00:00 2001
From: Pavel Safonov
Date: Wed, 3 Aug 2022 15:49:12 +0300
Subject: [PATCH] PostgreSQL: heap impl for version 11
---
format/postgres/flavours/postgres11/pgheap.go | 74 +++++++++++++++++++
format/postgres/pgheap.go | 3 +
2 files changed, 77 insertions(+)
create mode 100644 format/postgres/flavours/postgres11/pgheap.go
diff --git a/format/postgres/flavours/postgres11/pgheap.go b/format/postgres/flavours/postgres11/pgheap.go
new file mode 100644
index 000000000..cf027b9a1
--- /dev/null
+++ b/format/postgres/flavours/postgres11/pgheap.go
@@ -0,0 +1,74 @@
+package postgres11
+
+import (
+ "github.com/wader/fq/format/postgres/common"
+ "github.com/wader/fq/format/postgres/flavours/postgres14/common14"
+ "github.com/wader/fq/pkg/decode"
+)
+
+// type = struct PageHeaderData {
+/* 0 | 8 */ // PageXLogRecPtr pd_lsn;
+/* 8 | 2 */ // uint16 pd_checksum;
+/* 10 | 2 */ // uint16 pd_flags;
+/* 12 | 2 */ // LocationIndex pd_lower;
+/* 14 | 2 */ // LocationIndex pd_upper;
+/* 16 | 2 */ // LocationIndex pd_special;
+/* 18 | 2 */ // uint16 pd_pagesize_version
+/* 20 | 4 */ // TransactionId pd_prune_xid
+/* 24 | 0 */ // ItemIdData pd_linp[]
+//
+/* total size (bytes): 24 */
+
+// type = struct PageXLogRecPtr {
+/* 0 | 4 */ // uint32 xlogid;
+/* 4 | 4 */ // uint32 xrecoff;
+//
+/* total size (bytes): 8 */
+
+// type = struct HeapTupleHeaderData {
+/* 0 | 12 */ //union {
+/* 12 */ // HeapTupleFields t_heap;
+/* 12 */ // DatumTupleFields t_datum;
+// } t_choice;
+/* total size (bytes): 12 */
+//
+/* 12 | 6 */ // ItemPointerData t_ctid
+/* 18 | 2 */ // uint16 t_infomask2
+/* 20 | 2 */ // uint16 t_infomask
+/* 22 | 1 */ // uint8 t_hoff
+/* 23 | 0 */ // bits8 t_bits[]
+/* XXX 1-byte padding */
+//
+/* total size (bytes): 24 */
+
+// type = struct HeapTupleFields {
+/* 0 | 4 */ // TransactionId t_xmin;
+/* 4 | 4 */ // TransactionId t_xmax;
+/* 8 | 4 */ // union {
+/* 4 */ // CommandId t_cid;
+/* 4 */ // TransactionId t_xvac;
+// } t_field3;
+/* total size (bytes): 4 */
+//
+/* total size (bytes): 12 */
+
+// type = struct DatumTupleFields {
+/* 0 | 4 */ // int32 datum_len_;
+/* 4 | 4 */ // int32 datum_typmod;
+/* 8 | 4 */ // Oid datum_typeid;
+//
+/* total size (bytes): 12 */
+
+// type = struct ItemPointerData {
+/* 0 | 4 */ // BlockIdData ip_blkid;
+/* 4 | 2 */ // OffsetNumber ip_posid;
+//
+/* total size (bytes): 6 */
+
+func DecodeHeap(d *decode.D) any {
+ heap := &common14.HeapD{
+ PageSize: common.HeapPageSize,
+ DecodePageHeaderDataFn: common14.DecodePageHeaderData,
+ }
+ return common14.DecodeHeap(d, heap)
+}
diff --git a/format/postgres/pgheap.go b/format/postgres/pgheap.go
index 564660f07..7f35eb92b 100644
--- a/format/postgres/pgheap.go
+++ b/format/postgres/pgheap.go
@@ -4,6 +4,7 @@ import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/postgres/flavours/pgproee11"
"github.com/wader/fq/format/postgres/flavours/pgproee14"
+ "github.com/wader/fq/format/postgres/flavours/postgres11"
"github.com/wader/fq/format/postgres/flavours/postgres12"
"github.com/wader/fq/format/postgres/flavours/postgres14"
"github.com/wader/fq/pkg/decode"
@@ -26,6 +27,8 @@ func decodePgheap(d *decode.D, in any) any {
flavour := in.(format.PostgresIn).Flavour
switch flavour {
+ case PG_FLAVOUR_POSTGRES11:
+ return postgres11.DecodeHeap(d)
case PG_FLAVOUR_POSTGRES12:
return postgres12.DecodeHeap(d)
case PG_FLAVOUR_POSTGRES14, PG_FLAVOUR_POSTGRES: