Skip to content

Commit

Permalink
postgres: add page arg in pg_btree, change args names in pg_heap
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Safonov committed Dec 22, 2022
1 parent 0ea20e6 commit 97bbc22
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
10 changes: 7 additions & 3 deletions format/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,11 @@ type PostgresIn struct {
}

type PostgresHeapIn struct {
Flavour string `doc:"PostgreSQL flavour: postgres14, pgproee14.., postgres10"`
PageNumber int `doc:"First page number in file, default is 0"`
SegmentNumber int `doc:"Segment file number (16790.1 is 1), default is 0"`
Flavour string `doc:"PostgreSQL flavour: postgres14, pgproee14.., postgres10"`
Page int `doc:"First page number in file, default is 0"`
Segment int `doc:"Segment file number (16790.1 is 1), default is 0"`
}

type PostgresBTreeIn struct {
Page int `doc:"First page number in file, default is 0"`
}
8 changes: 5 additions & 3 deletions format/postgres/common/pg_btree/postgres/pg_btree.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package postgres

import (
"github.com/wader/fq/format"
"github.com/wader/fq/format/postgres/common"
"github.com/wader/fq/format/postgres/common/pg_heap/postgres"
"github.com/wader/fq/pkg/decode"
Expand Down Expand Up @@ -66,22 +67,23 @@ const (
// IndexTupleData *IndexTuple;
/* total size (bytes): 8 */

func DecodePgBTree(d *decode.D) any {
func DecodePgBTree(d *decode.D, args format.PostgresBTreeIn) any {
btree := &BTree{
Args: args,
PageSize: common.PageSize,
}
decodeBTreePages(btree, d)
return nil
}

type BTree struct {
Args format.PostgresBTreeIn
PageSize uint64
page *postgres.HeapPage
}

func decodeBTreePages(btree *BTree, d *decode.D) {
for i := 0; ; i++ {

for i := btree.Args.Page; ; i++ {
page := &postgres.HeapPage{}
if btree.page != nil {
// use prev page
Expand Down
2 changes: 1 addition & 1 deletion format/postgres/common/pg_heap/postgres/pg_heap.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func Decode(heap *Heap, d *decode.D) any {
}

func decodeHeapPages(heap *Heap, d *decode.D) {
blockNumber := uint32(heap.Args.PageNumber + heap.Args.SegmentNumber*common.RelSegSize)
blockNumber := uint32(heap.Args.Page + heap.Args.Segment*common.RelSegSize)
count := int64(0)
for {
if end, _ := d.TryEnd(); end {
Expand Down
14 changes: 10 additions & 4 deletions format/postgres/pg_btree.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,19 @@ func init() {
Name: format.PG_BTREE,
Description: "PostgreSQL btree index file",
DecodeFn: decodePgBTree,
RootArray: true,
RootName: "pages",
DecodeInArg: format.PostgresBTreeIn{
Page: 0,
},
RootArray: true,
RootName: "pages",
})
interp.RegisterFS(pgBTreeFS)
}

func decodePgBTree(d *decode.D, in any) any {
d.Endian = decode.LittleEndian
return postgres.DecodePgBTree(d)
pgIn, ok := in.(format.PostgresBTreeIn)
if !ok {
d.Fatalf("DecodeInArg must be PostgresBTreeIn!\n")
}
return postgres.DecodePgBTree(d, pgIn)
}
6 changes: 3 additions & 3 deletions format/postgres/pg_heap.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ func init() {
Description: "PostgreSQL heap file",
DecodeFn: decodePgheap,
DecodeInArg: format.PostgresHeapIn{
Flavour: PG_FLAVOUR_POSTGRES14,
PageNumber: 0,
SegmentNumber: 0,
Flavour: PG_FLAVOUR_POSTGRES14,
Page: 0,
Segment: 0,
},
RootArray: true,
RootName: "pages",
Expand Down

0 comments on commit 97bbc22

Please sign in to comment.