Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 5.0.0, update to Postgres 16 parser #304

Merged
merged 2 commits into from
Dec 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

* ...

## 5.0.0 2023-12-22

* Upgrade to libpg_query 16-5.0.0
- Updates to the Postgres 16 parser
- Multiple deparser improvements


## 4.2.3 2023-08-04

Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
pg_query (4.2.3)
pg_query (5.0.0)
google-protobuf (>= 3.22.3)

GEM
Expand Down
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ Due to compiling parts of PostgreSQL, installation might take a while on slower
```ruby
PgQuery.parse("SELECT 1")

=> #<PgQuery::ParserResult:0x000000012000c438
=> #<PgQuery::ParserResult:0x000000012ec4e9e0
@query="SELECT 1",
@tree=<PgQuery::ParseResult:
version: 150001,
version: 160001,
stmts: [
<PgQuery::RawStmt:
stmt: <PgQuery::Node:
Expand All @@ -41,11 +41,9 @@ PgQuery.parse("SELECT 1")
indirection: [],
val: <PgQuery::Node:
a_const: <PgQuery::A_Const:
ival: <PgQuery::Integer: ival: 1>,
isnull: false,
location: 7,
ival: <PgQuery::Integer:
ival: 1
>
location: 7
>
>,
location: 7
Expand Down Expand Up @@ -139,7 +137,7 @@ PgQuery.fingerprint("SELECT $1")
```ruby
PgQuery.scan('SELECT 1 --comment')

=> [<PgQuery::ScanResult: version: 150001, tokens: [
=> [<PgQuery::ScanResult: version: 160001, tokens: [
<PgQuery::ScanToken: start: 0, end: 6, token: :SELECT, keyword_kind: :RESERVED_KEYWORD>,
<PgQuery::ScanToken: start: 7, end: 8, token: :ICONST, keyword_kind: :NO_KEYWORD>,
<PgQuery::ScanToken: start: 9, end: 18, token: :SQL_COMMENT, keyword_kind: :NO_KEYWORD>]>,
Expand All @@ -160,7 +158,7 @@ parsed_query.walk! { |node, k, v, location| puts k }
More usefully, this can be used to rewrite a query. For example:

```ruby
parsed_query.walk! do |node, k, v, location| puts k
parsed_query.walk! do |node, k, v, location|
next unless k.eql?(:range_var) || k.eql?(:relation)
next if v.relname.nil?
v.relname = "X_" + v.relname
Expand Down
6 changes: 3 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ require 'rspec/core/rake_task'
require 'rubocop/rake_task'
require 'open-uri'

LIB_PG_QUERY_TAG = '15-4.2.3'.freeze
LIB_PG_QUERY_SHA256SUM = '8b820d63442b1677ce4f0df2a95b3fafdbc520a82901def81217559ec4df9e6b'.freeze
LIB_PG_QUERY_TAG = '16-5.0.0'.freeze
LIB_PG_QUERY_SHA256SUM = '7cf26922cbc41668fa79332504f2d5638339baa9411912b8df4526ccd1d7029e'.freeze

Rake::ExtensionTask.new 'pg_query' do |ext|
ext.lib_dir = 'lib/pg_query'
Expand Down Expand Up @@ -66,7 +66,7 @@ task :update_source do
system("rmdir #{extdir}/postgres")
system("cp -a #{libdir}/pg_query.h #{extdir}/include")
# Make sure every .c file in the top-level directory is its own translation unit
system("mv #{extdir}/*{_conds,_defs,_helper}.c #{extdir}/include")
system("mv #{extdir}/*{_conds,_defs,_helper,.funcs}.c #{extdir}/include")
# Protobuf definitions
system("protoc --proto_path=#{libdir}/protobuf --ruby_out=#{File.join(__dir__, 'lib/pg_query')} #{libdir}/protobuf/pg_query.proto")
system("mkdir -p #{extdir}/include/protobuf")
Expand Down
4 changes: 1 addition & 3 deletions ext/pg_query/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@

$objs = Dir.glob(File.join(__dir__, '*.c')).map { |f| Pathname.new(f).sub_ext('.o').to_s }

# -Wno-deprecated-non-prototype avoids warnings on Clang 15.0+, this can be removed in Postgres 16:
# https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=1c27d16e6e5c1f463bbe1e9ece88dda811235165
$CFLAGS << " -fvisibility=hidden -O3 -Wall -fno-strict-aliasing -fwrapv -fstack-protector -Wno-unused-function -Wno-unused-variable -Wno-clobbered -Wno-sign-compare -Wno-discarded-qualifiers -Wno-deprecated-non-prototype -Wno-unknown-warning-option -g"
$CFLAGS << " -fvisibility=hidden -O3 -Wall -fno-strict-aliasing -fwrapv -fstack-protector -Wno-unused-function -Wno-unused-variable -Wno-clobbered -Wno-sign-compare -Wno-discarded-qualifiers -Wno-unknown-warning-option -g"

$INCFLAGS = "-I#{File.join(__dir__, 'include')} " + $INCFLAGS

Expand Down
4 changes: 3 additions & 1 deletion ext/pg_query/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 ext/pg_query/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 ext/pg_query/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 ext/pg_query/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 ext/pg_query/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 ext/pg_query/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 ext/pg_query/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 ext/pg_query/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 ext/pg_query/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 ext/pg_query/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