1
1
mirror of https://github.com/wader/fq.git synced 2024-11-23 00:57:15 +03:00

postgres: add page arg in pg_btree, change args names in pg_heap

This commit is contained in:
Pavel Safonov 2022-12-22 11:22:02 +03:00
parent 0ea20e6827
commit 97bbc22a1d
5 changed files with 26 additions and 14 deletions

View File

@ -333,6 +333,10 @@ 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"`
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"`
}

View File

@ -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"
@ -66,8 +67,9 @@ 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)
@ -75,13 +77,13 @@ func DecodePgBTree(d *decode.D) any {
}
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

View File

@ -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 {

View File

@ -18,6 +18,9 @@ func init() {
Name: format.PG_BTREE,
Description: "PostgreSQL btree index file",
DecodeFn: decodePgBTree,
DecodeInArg: format.PostgresBTreeIn{
Page: 0,
},
RootArray: true,
RootName: "pages",
})
@ -25,6 +28,9 @@ func init() {
}
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)
}

View File

@ -24,8 +24,8 @@ func init() {
DecodeFn: decodePgheap,
DecodeInArg: format.PostgresHeapIn{
Flavour: PG_FLAVOUR_POSTGRES14,
PageNumber: 0,
SegmentNumber: 0,
Page: 0,
Segment: 0,
},
RootArray: true,
RootName: "pages",