Skip to content

Commit

Permalink
Release 5.0.0 (v5), add Postgres 16 support
Browse files Browse the repository at this point in the history
  • Loading branch information
lfittl committed Dec 23, 2023
1 parent 7463430 commit d3f7487
Show file tree
Hide file tree
Showing 488 changed files with 243,219 additions and 198,886 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ benchmark:

# --- Below only needed for releasing new versions

LIB_PG_QUERY_TAG = 15-4.2.3
LIB_PG_QUERY_TAG = 16-5.0.0

root_dir := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
LIB_TMPDIR = $(root_dir)/tmp
Expand All @@ -41,7 +41,7 @@ update_source: $(LIBDIR)
rmdir parser/postgres
cp -a $(LIBDIR)/pg_query.h parser/include
# Make sure every .c in the top-level directory is its own translation unit
mv parser/*{_conds,_defs,_helper}.c parser/include
mv parser/*{_conds,_defs,_helper,.funcs}.c parser/include
# Protobuf definitions
mkdir -p $(PWD)/bin
GOBIN=$(PWD)/bin go install google.golang.org/protobuf/cmd/protoc-gen-go
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# pg_query_go [![GoDoc](https://godoc.org/github.com/pganalyze/pg_query_go/v4?status.svg)](https://godoc.org/github.com/pganalyze/pg_query_go/v4)
# pg_query_go [![GoDoc](https://godoc.org/github.com/pganalyze/pg_query_go/v5?status.svg)](https://godoc.org/github.com/pganalyze/pg_query_go/v5)

Go version of https://github.com/pganalyze/pg_query

Expand All @@ -10,7 +10,7 @@ You can find further background to why a query's parse tree is useful here: http
## Installation

```
go get github.com/pganalyze/pg_query_go/v4@latest
go get github.com/pganalyze/pg_query_go/v5@latest
```

Due to compiling parts of PostgreSQL, the first time you build against this library it will take a bit longer.
Expand Down Expand Up @@ -44,7 +44,7 @@ package main
import (
"fmt"

pg_query "github.com/pganalyze/pg_query_go/v4"
pg_query "github.com/pganalyze/pg_query_go/v5"
)

func main() {
Expand Down Expand Up @@ -72,7 +72,7 @@ package main
import (
"fmt"

pg_query "github.com/pganalyze/pg_query_go/v4"
pg_query "github.com/pganalyze/pg_query_go/v5"
)

func main() {
Expand All @@ -98,7 +98,7 @@ package main
import (
"fmt"

pg_query "github.com/pganalyze/pg_query_go/v4"
pg_query "github.com/pganalyze/pg_query_go/v5"
)

func main() {
Expand Down Expand Up @@ -135,7 +135,7 @@ package main
import (
"fmt"

pg_query "github.com/pganalyze/pg_query_go/v4"
pg_query "github.com/pganalyze/pg_query_go/v5"
)

func main() {
Expand Down Expand Up @@ -173,7 +173,7 @@ go build -a
go test -test.bench=. -test.run=XXX -test.benchtime 10s -test.benchmem -test.cpu=4
goos: darwin
goarch: arm64
pkg: github.com/pganalyze/pg_query_go/v4
pkg: github.com/pganalyze/pg_query_go/v5
BenchmarkParseSelect1-4 3230398 3656 ns/op 1104 B/op 20 allocs/op
BenchmarkParseSelect2-4 927363 12739 ns/op 2896 B/op 59 allocs/op
BenchmarkParseCreateTable-4 399819 30080 ns/op 8432 B/op 151 allocs/op
Expand All @@ -193,7 +193,7 @@ BenchmarkNormalizeSelect1-4 10073278 1171 ns/op 72 B/o
BenchmarkNormalizeSelect2-4 6029834 1932 ns/op 104 B/op 4 allocs/op
BenchmarkNormalizeCreateTable-4 4703816 2490 ns/op 184 B/op 4 allocs/op
PASS
ok github.com/pganalyze/pg_query_go/v4 273.449s
ok github.com/pganalyze/pg_query_go/v5 273.449s
```

Note that allocation counts exclude the cgo portion, so they are higher than shown here.
Expand Down
4 changes: 2 additions & 2 deletions benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ package pg_query_test
import (
"testing"

pg_query "github.com/pganalyze/pg_query_go/v4"
"github.com/pganalyze/pg_query_go/v4/parser"
pg_query "github.com/pganalyze/pg_query_go/v5"
"github.com/pganalyze/pg_query_go/v5/parser"
)

// Prevent compiler optimizations by assigning all results to global variables
Expand Down
2 changes: 1 addition & 1 deletion fingerprint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strconv"
"testing"

pg_query "github.com/pganalyze/pg_query_go/v4"
pg_query "github.com/pganalyze/pg_query_go/v5"
)

type fingerprintTest struct {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/pganalyze/pg_query_go/v4
module github.com/pganalyze/pg_query_go/v5

go 1.14

Expand Down
4 changes: 2 additions & 2 deletions normalize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"reflect"
"testing"

pg_query "github.com/pganalyze/pg_query_go/v4"
"github.com/pganalyze/pg_query_go/v4/parser"
pg_query "github.com/pganalyze/pg_query_go/v5"
"github.com/pganalyze/pg_query_go/v5/parser"
)

var normalizeTests = []struct {
Expand Down
42 changes: 21 additions & 21 deletions parse_test.go

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion parser/include/access/amapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* amapi.h
* API for Postgres index access methods.
*
* Copyright (c) 2015-2022, PostgreSQL Global Development Group
* Copyright (c) 2015-2023, PostgreSQL Global Development Group
*
* src/include/access/amapi.h
*
Expand Down Expand Up @@ -244,6 +244,8 @@ typedef struct IndexAmRoutine
bool amcaninclude;
/* does AM use maintenance_work_mem? */
bool amusemaintenanceworkmem;
/* does AM store tuple information only at block granularity? */
bool amsummarizing;
/* OR of parallel vacuum flags. See vacuum.h for flags. */
uint8 amparallelvacuumoptions;
/* type of data stored in index, or InvalidOid if variable */
Expand Down
8 changes: 5 additions & 3 deletions parser/include/access/attmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Definitions for PostgreSQL attribute mappings
*
*
* Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
* Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* src/include/access/attmap.h
Expand Down Expand Up @@ -42,9 +42,11 @@ extern void free_attrmap(AttrMap *map);

/* Conversion routines to build mappings */
extern AttrMap *build_attrmap_by_name(TupleDesc indesc,
TupleDesc outdesc);
TupleDesc outdesc,
bool missing_ok);
extern AttrMap *build_attrmap_by_name_if_req(TupleDesc indesc,
TupleDesc outdesc);
TupleDesc outdesc,
bool missing_ok);
extern AttrMap *build_attrmap_by_position(TupleDesc indesc,
TupleDesc outdesc,
const char *msg);
Expand Down
2 changes: 1 addition & 1 deletion parser/include/access/attnum.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* POSTGRES attribute number definitions.
*
*
* Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
* Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* src/include/access/attnum.h
Expand Down
2 changes: 1 addition & 1 deletion parser/include/access/clog.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* PostgreSQL transaction-commit-log manager
*
* Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
* Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* src/include/access/clog.h
Expand Down
2 changes: 1 addition & 1 deletion parser/include/access/commit_ts.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* PostgreSQL commit timestamp manager
*
* Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
* Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* src/include/access/commit_ts.h
Expand Down
2 changes: 1 addition & 1 deletion parser/include/access/detoast.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* detoast.h
* Access to compressed and external varlena values.
*
* Copyright (c) 2000-2022, PostgreSQL Global Development Group
* Copyright (c) 2000-2023, PostgreSQL Global Development Group
*
* src/include/access/detoast.h
*
Expand Down
12 changes: 7 additions & 5 deletions parser/include/access/genam.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* POSTGRES generalized index access method definitions.
*
*
* Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
* Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* src/include/access/genam.h
Expand Down Expand Up @@ -44,6 +44,7 @@ typedef struct IndexBuildResult
typedef struct IndexVacuumInfo
{
Relation index; /* the index being vacuumed */
Relation heaprel; /* the heap relation the index belongs to */
bool analyze_only; /* ANALYZE (without any actual vacuum) */
bool report_progress; /* emit progress.h status reports */
bool estimated_count; /* num_heap_tuples is an estimate */
Expand Down Expand Up @@ -161,9 +162,10 @@ extern void index_rescan(IndexScanDesc scan,
extern void index_endscan(IndexScanDesc scan);
extern void index_markpos(IndexScanDesc scan);
extern void index_restrpos(IndexScanDesc scan);
extern Size index_parallelscan_estimate(Relation indexrel, Snapshot snapshot);
extern void index_parallelscan_initialize(Relation heaprel, Relation indexrel,
Snapshot snapshot, ParallelIndexScanDesc target);
extern Size index_parallelscan_estimate(Relation indexRelation, Snapshot snapshot);
extern void index_parallelscan_initialize(Relation heapRelation,
Relation indexRelation, Snapshot snapshot,
ParallelIndexScanDesc target);
extern void index_parallelrescan(IndexScanDesc scan);
extern IndexScanDesc index_beginscan_parallel(Relation heaprel,
Relation indexrel, int nkeys, int norderbys,
Expand Down Expand Up @@ -191,7 +193,7 @@ extern void index_store_float8_orderby_distances(IndexScanDesc scan,
Oid *orderByTypes,
IndexOrderByDistance *distances,
bool recheckOrderBy);
extern bytea *index_opclass_options(Relation relation, AttrNumber attnum,
extern bytea *index_opclass_options(Relation indrel, AttrNumber attnum,
Datum attoptions, bool validate);


Expand Down
19 changes: 16 additions & 3 deletions parser/include/access/gin.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* gin.h
* Public header file for Generalized Inverted Index access method.
*
* Copyright (c) 2006-2022, PostgreSQL Global Development Group
* Copyright (c) 2006-2023, PostgreSQL Global Development Group
*
* src/include/access/gin.h
*--------------------------------------------------------------------------
Expand Down Expand Up @@ -57,13 +57,26 @@ typedef struct GinStatsData
*/
typedef char GinTernaryValue;

StaticAssertDecl(sizeof(GinTernaryValue) == sizeof(bool),
"sizes of GinTernaryValue and bool are not equal");

#define GIN_FALSE 0 /* item is not present / does not match */
#define GIN_TRUE 1 /* item is present / matches */
#define GIN_MAYBE 2 /* don't know if item is present / don't know
* if matches */

#define DatumGetGinTernaryValue(X) ((GinTernaryValue)(X))
#define GinTernaryValueGetDatum(X) ((Datum)(X))
static inline GinTernaryValue
DatumGetGinTernaryValue(Datum X)
{
return (GinTernaryValue) X;
}

static inline Datum
GinTernaryValueGetDatum(GinTernaryValue X)
{
return (Datum) X;
}

#define PG_RETURN_GIN_TERNARY_VALUE(x) return GinTernaryValueGetDatum(x)

/* GUC parameters */
Expand Down
2 changes: 1 addition & 1 deletion parser/include/access/htup.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* POSTGRES heap tuple definitions.
*
*
* Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
* Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* src/include/access/htup.h
Expand Down
8 changes: 6 additions & 2 deletions parser/include/access/htup_details.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* POSTGRES heap tuple header definitions.
*
*
* Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
* Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* src/include/access/htup_details.h
Expand All @@ -19,6 +19,7 @@
#include "access/tupdesc.h"
#include "access/tupmacs.h"
#include "storage/bufpage.h"
#include "varatt.h"

/*
* MaxTupleAttributeNumber limits the number of (user) columns in a tuple.
Expand Down Expand Up @@ -426,6 +427,9 @@ do { \
(tup)->t_choice.t_heap.t_field3.t_xvac = (xid); \
} while (0)

StaticAssertDecl(MaxOffsetNumber < SpecTokenOffsetNumber,
"invalid speculative token constant");

#define HeapTupleHeaderIsSpeculative(tup) \
( \
(ItemPointerGetOffsetNumberNoCheck(&(tup)->t_ctid) == SpecTokenOffsetNumber) \
Expand Down Expand Up @@ -699,7 +703,7 @@ extern void heap_fill_tuple(TupleDesc tupleDesc,
uint16 *infomask, bits8 *bit);
extern bool heap_attisnull(HeapTuple tup, int attnum, TupleDesc tupleDesc);
extern Datum nocachegetattr(HeapTuple tup, int attnum,
TupleDesc att);
TupleDesc tupleDesc);
extern Datum heap_getsysattr(HeapTuple tup, int attnum, TupleDesc tupleDesc,
bool *isnull);
extern Datum getmissingattr(TupleDesc tupleDesc,
Expand Down
Loading

0 comments on commit d3f7487

Please sign in to comment.