Skip to content

Commit

Permalink
PostgreSQL: pgproee11 heap impl
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Safonov committed Aug 2, 2022
1 parent 96a86e2 commit 2d3884a
Show file tree
Hide file tree
Showing 6 changed files with 232 additions and 53 deletions.
76 changes: 76 additions & 0 deletions format/postgres/flavours/pgproee11/pg_control.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package pgproee11

// type = struct ControlFileData {
/* 0 | 8 */ // uint64 system_identifier;
/* 8 | 4 */ // uint32 pg_control_version;
/* 12 | 4 */ // uint32 catalog_version_no;
/* 16 | 4 */ // DBState state;
/* XXX 4-byte hole */
/* 24 | 8 */ // pg_time_t time;
/* 32 | 8 */ // XLogRecPtr checkPoint;
/* 40 | 120 */ // CheckPoint checkPointCopy;
/* 160 | 8 */ // XLogRecPtr unloggedLSN;
/* 168 | 8 */ // XLogRecPtr minRecoveryPoint;
/* 176 | 4 */ // TimeLineID minRecoveryPointTLI;
/* XXX 4-byte hole */
/* 184 | 8 */ // XLogRecPtr backupStartPoint;
/* 192 | 8 */ // XLogRecPtr backupEndPoint;
/* 200 | 1 */ // _Bool backupEndRequired;
/* XXX 3-byte hole */
/* 204 | 4 */ // int wal_level;
/* 208 | 1 */ // _Bool wal_log_hints;
/* XXX 3-byte hole */
/* 212 | 4 */ // int MaxConnections;
/* 216 | 4 */ // int max_worker_processes;
/* 220 | 4 */ // int max_prepared_xacts;
/* 224 | 4 */ // int max_locks_per_xact;
/* 228 | 1 */ // _Bool track_commit_timestamp;
/* XXX 3-byte hole */
/* 232 | 4 */ // uint32 maxAlign;
/* XXX 4-byte hole */
/* 240 | 8 */ // double floatFormat;
/* 248 | 4 */ // uint32 blcksz;
/* 252 | 4 */ // uint32 relseg_size;
/* 256 | 4 */ // uint32 xlog_blcksz;
/* 260 | 4 */ // uint32 xlog_seg_size;
/* 264 | 4 */ // uint32 nameDataLen;
/* 268 | 4 */ // uint32 indexMaxKeys;
/* 272 | 4 */ // uint32 toast_max_chunk_size;
/* 276 | 4 */ // uint32 loblksize;
/* 280 | 1 */ // _Bool float4ByVal;
/* 281 | 1 */ // _Bool float8ByVal;
/* XXX 2-byte hole */
/* 284 | 4 */ // uint32 data_checksum_version;
/* 288 | 32 */ // char mock_authentication_nonce[32];
/* 320 | 4 */ // pg_icu_version icu_version;
/* 324 | 4 */ // uint32 pg_old_version;
/* 328 | 4 */ // SnapshotId oldest_snapshot;
/* 332 | 4 */ // SnapshotId recent_snapshot;
/* 336 | 4 */ // SnapshotId active_snapshot;
/* 340 | 4 */ // pg_crc32c crc;
//
/* total size (bytes): 344 */

// type = struct CheckPoint {
/* 0 | 8 */ // XLogRecPtr redo;
/* 8 | 4 */ // TimeLineID ThisTimeLineID;
/* 12 | 4 */ // TimeLineID PrevTimeLineID;
/* 16 | 1 */ // _Bool fullPageWrites;
/* XXX 7-byte hole */
/* 24 | 8 */ // TransactionId nextXid;
/* 32 | 4 */ // Oid nextOid;
/* XXX 4-byte hole */
/* 40 | 8 */ // MultiXactId nextMulti;
/* 48 | 8 */ // MultiXactOffset nextMultiOffset;
/* 56 | 8 */ // TransactionId oldestXid;
/* 64 | 4 */ // Oid oldestXidDB;
/* XXX 4-byte hole */
/* 72 | 8 */ // MultiXactId oldestMulti;
/* 80 | 4 */ // Oid oldestMultiDB;
/* XXX 4-byte hole */
/* 88 | 8 */ // pg_time_t time;
/* 96 | 8 */ // TransactionId oldestCommitTsXid;
/* 104 | 8 */ // TransactionId newestCommitTsXid;
/* 112 | 8 */ // TransactionId oldestActiveXid;
//
/* total size (bytes): 120 */
83 changes: 83 additions & 0 deletions format/postgres/flavours/pgproee11/pgheap.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package pgproee11

import (
"github.com/wader/fq/format/postgres/common"
"github.com/wader/fq/format/postgres/flavours/pgproee14/ee14"
"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 | 0 */ // ItemIdData pd_linp[];
//
/* total size (bytes): 20 */

// 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 */ // ShortTransactionId t_xmin;
/* 4 | 4 */ // ShortTransactionId t_xmax;
/* 8 | 4 */ // union {
/* 4 */ // CommandId t_cid;
/* 4 */ // ShortTransactionId 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 */

// type = struct HeapPageSpecialData {
/* 0 | 8 */ // TransactionId pd_xid_base;
/* 8 | 8 */ // TransactionId pd_multi_base;
/* 16 | 4 */ // ShortTransactionId pd_prune_xid;
/* 20 | 4 */ // uint32 pd_magic;
//
/* total size (bytes): 24 */

func DecodeHeap(d *decode.D) any {
heap := &common14.HeapD{
PageSize: common.HeapPageSize,
DecodePageHeaderDataFn: ee14.DecodePageHeaderData,
DecodePageSpecialFn: ee14.DecodePageSpecial,
}
return common14.DecodeHeap(d, heap)
}
60 changes: 60 additions & 0 deletions format/postgres/flavours/pgproee14/ee14/pgheap.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package ee14

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 | 0 */ // ItemIdData pd_linp[];
func DecodePageHeaderData(d *decode.D) {
heap := common14.GetHeapD(d)
page := heap.Page

d.FieldStruct("pd_lsn", func(d *decode.D) {
/* 0 | 4 */ // uint32 xlogid;
/* 4 | 4 */ // uint32 xrecoff;
d.FieldU32("xlogid", common.HexMapper)
d.FieldU32("xrecoff", common.HexMapper)
})
d.FieldU16("pd_checksum")
d.FieldU16("pd_flags")
page.PdLower = uint16(d.FieldU16("pd_lower"))
page.PdUpper = uint16(d.FieldU16("pd_upper"))
page.PdSpecial = uint16(d.FieldU16("pd_special"))
page.PdPagesizeVersion = uint16(d.FieldU16("pd_pagesize_version"))

// ItemIdData pd_linp[];
page.ItemsEnd = int64(page.PagePosBegin*8) + int64(page.PdLower*8)
d.FieldArray("pd_linp", common14.DecodeItemIds)
}

// type = struct HeapPageSpecialData {
/* 0 | 8 */ // TransactionId pd_xid_base;
/* 8 | 8 */ // TransactionId pd_multi_base;
/* 16 | 4 */ // ShortTransactionId pd_prune_xid;
/* 20 | 4 */ // uint32 pd_magic;
//
/* total size (bytes): 24 */
func DecodePageSpecial(d *decode.D) {
heap := common14.GetHeapD(d)
page := heap.Page

specialPos := int64(page.PagePosBegin*8) + int64(page.PdSpecial*8)
d.SeekAbs(specialPos)

d.FieldStruct("HeapPageSpecialData", func(d *decode.D) {
page.PdXidBase = d.FieldU64("pd_xid_base")
page.PdMultiBase = d.FieldU64("pd_multi_base")
page.PdPruneXid = d.FieldU32("pd_prune_xid")
page.PdMagic = d.FieldU32("pd_magic")
})
}
62 changes: 9 additions & 53 deletions format/postgres/flavours/pgproee14/pgheap.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pgproee14

import (
"github.com/wader/fq/format/postgres/common"
"github.com/wader/fq/format/postgres/flavours/pgproee14/ee14"
"github.com/wader/fq/format/postgres/flavours/postgres14/common14"
"github.com/wader/fq/pkg/decode"
)
Expand All @@ -18,7 +19,7 @@ import (
//
/* total size (bytes): 20 */

// type = struct {
// type = struct PageXLogRecPtr {
/* 0 | 4 */ // uint32 xlogid;
/* 4 | 4 */ // uint32 xrecoff;
//
Expand Down Expand Up @@ -72,64 +73,19 @@ import (
//
/* total size (bytes): 6 */

func DecodeHeap(d *decode.D) any {
heap := &common14.HeapD{
PageSize: common.HeapPageSize,
DecodePageHeaderDataFn: DecodePageHeaderData,
DecodePageSpecialFn: DecodePageSpecial,
}
return common14.DecodeHeap(d, heap)
}

// 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 | 0 */ // ItemIdData pd_linp[];
func DecodePageHeaderData(d *decode.D) {
heap := common14.GetHeapD(d)
page := heap.Page

d.FieldStruct("pd_lsn", func(d *decode.D) {
/* 0 | 4 */ // uint32 xlogid;
/* 4 | 4 */ // uint32 xrecoff;
d.FieldU32("xlogid", common.HexMapper)
d.FieldU32("xrecoff", common.HexMapper)
})
d.FieldU16("pd_checksum")
d.FieldU16("pd_flags")
page.PdLower = uint16(d.FieldU16("pd_lower"))
page.PdUpper = uint16(d.FieldU16("pd_upper"))
page.PdSpecial = uint16(d.FieldU16("pd_special"))
page.PdPagesizeVersion = uint16(d.FieldU16("pd_pagesize_version"))

// ItemIdData pd_linp[];
page.ItemsEnd = int64(page.PagePosBegin*8) + int64(page.PdLower*8)
d.FieldArray("pd_linp", common14.DecodeItemIds)
}

// type = struct HeapPageSpecialData {
/* 0 | 8 */ // TransactionId pd_xid_base;
/* 8 | 8 */ // TransactionId pd_multi_base;
/* 16 | 4 */ // ShortTransactionId pd_prune_xid;
/* 20 | 4 */ // uint32 pd_magic;
//
/* total size (bytes): 24 */
func DecodePageSpecial(d *decode.D) {
heap := common14.GetHeapD(d)
page := heap.Page

specialPos := int64(page.PagePosBegin*8) + int64(page.PdSpecial*8)
d.SeekAbs(specialPos)

d.FieldStruct("HeapPageSpecialData", func(d *decode.D) {
page.PdXidBase = d.FieldU64("pd_xid_base")
page.PdMultiBase = d.FieldU64("pd_multi_base")
page.PdPruneXid = d.FieldU32("pd_prune_xid")
page.PdMagic = d.FieldU32("pd_magic")
})
func DecodeHeap(d *decode.D) any {
heap := &common14.HeapD{
PageSize: common.HeapPageSize,
DecodePageHeaderDataFn: ee14.DecodePageHeaderData,
DecodePageSpecialFn: ee14.DecodePageSpecial,
}
return common14.DecodeHeap(d, heap)
}
1 change: 1 addition & 0 deletions format/postgres/pg_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const (
PG_FLAVOUR_POSTGRES = "postgres"
PG_FLAVOUR_POSTGRES11 = "postgres11"
PG_FLAVOUR_POSTGRES14 = "postgres14"
PG_FLAVOUR_PGPROEE11 = "pgproee11"
PG_FLAVOUR_PGPROEE14 = "pgproee14"
)

Expand Down
3 changes: 3 additions & 0 deletions format/postgres/pgheap.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package postgres

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/postgres14"
"github.com/wader/fq/pkg/decode"
Expand All @@ -26,6 +27,8 @@ func decodePgheap(d *decode.D, in any) any {
switch flavour {
case PG_FLAVOUR_POSTGRES14, PG_FLAVOUR_POSTGRES:
return postgres14.DecodeHeap(d)
case PG_FLAVOUR_PGPROEE11:
return pgproee11.DecodeHeap(d)
case PG_FLAVOUR_PGPROEE14:
return pgproee14.DecodeHeap(d)
default:
Expand Down

0 comments on commit 2d3884a

Please sign in to comment.