pgsql: Fix handling of opclauses in extended statistics

2019-07-18 Thread Tomas Vondra
Fix handling of opclauses in extended statistics We expect opclauses to have exactly one Var and one Const, but the code was checking the Const by calling is_pseudo_constant_clause() which is incorrect - we need a proper constant. Fixed by using plain IsA(x,Const) to check type of the node. We ne

pgsql: Remove unnecessary TYPECACHE_GT_OPR lookup

2019-07-18 Thread Tomas Vondra
Remove unnecessary TYPECACHE_GT_OPR lookup The TYPECACHE_GT_OPR is not needed (it used to be in older version of the MCV code), but the compiler failed to detect this as the result was used in a fmgr_info() call, populating a FmgrInfo entry. Backpatch to v12, where this code was introduced. Disc

pgsql: Simplify bitmap updates in multivariate MCV code

2019-07-18 Thread Tomas Vondra
Simplify bitmap updates in multivariate MCV code When evaluating clauses on a multivariate MCV list, we build a bitmap tracking how the clauses match each item of the MCV list. When updating the bitmap we need to consider the current value (tracking how the item matches preceding clauses), match

pgsql: Fix handling of NULLs in MCV items and constants

2019-07-18 Thread Tomas Vondra
Fix handling of NULLs in MCV items and constants There were two issues in how the extended statistics handled NULL values in opclauses. Firstly, the code was oblivious to the possibility that Const may be NULL (constisnull=true) in which case the constvalue is undefined. We need to treat this as a

pgsql: Simplify bitmap updates in multivariate MCV code

2019-07-18 Thread Tomas Vondra
Simplify bitmap updates in multivariate MCV code When evaluating clauses on a multivariate MCV list, we build a bitmap tracking how the clauses match each item of the MCV list. When updating the bitmap we need to consider the current value (tracking how the item matches preceding clauses), match

pgsql: Fix handling of NULLs in MCV items and constants

2019-07-18 Thread Tomas Vondra
Fix handling of NULLs in MCV items and constants There were two issues in how the extended statistics handled NULL values in opclauses. Firstly, the code was oblivious to the possibility that Const may be NULL (constisnull=true) in which case the constvalue is undefined. We need to treat this as a

pgsql: Remove unnecessary TYPECACHE_GT_OPR lookup

2019-07-18 Thread Tomas Vondra
Remove unnecessary TYPECACHE_GT_OPR lookup The TYPECACHE_GT_OPR is not needed (it used to be in older version of the MCV code), but the compiler failed to detect this as the result was used in a fmgr_info() call, populating a FmgrInfo entry. Backpatch to v12, where this code was introduced. Disc

pgsql: Fix handling of opclauses in extended statistics

2019-07-18 Thread Tomas Vondra
Fix handling of opclauses in extended statistics We expect opclauses to have exactly one Var and one Const, but the code was checking the Const by calling is_pseudo_constant_clause() which is incorrect - we need a proper constant. Fixed by using plain IsA(x,Const) to check type of the node. We ne

pgsql: Further adjust SPITupleTable to provide a public row-count field

2019-07-18 Thread Tom Lane
Further adjust SPITupleTable to provide a public row-count field. Now that commit fec0778c8 drew a clear line between public and private fields in SPITupleTable, it seems pretty silly that the count of valid tuples isn't on the public side of that line. The reason why not was that there wasn't su

pgsql: Fix nbtree metapage cache upgrade bug.

2019-07-18 Thread Peter Geoghegan
Fix nbtree metapage cache upgrade bug. Commit 857f9c36cda, which taught nbtree VACUUM to avoid unnecessary index scans, bumped the nbtree version number from 2 to 3, while adding the ability for nbtree indexes to be upgraded on-the-fly. Various assertions that assumed that an nbtree index was alw

pgsql: Fix nbtree metapage cache upgrade bug.

2019-07-18 Thread Peter Geoghegan
Fix nbtree metapage cache upgrade bug. Commit 857f9c36cda, which taught nbtree VACUUM to avoid unnecessary index scans, bumped the nbtree version number from 2 to 3, while adding the ability for nbtree indexes to be upgraded on-the-fly. Various assertions that assumed that an nbtree index was alw

pgsql: Fix nbtree metapage cache upgrade bug.

2019-07-18 Thread Peter Geoghegan
Fix nbtree metapage cache upgrade bug. Commit 857f9c36cda, which taught nbtree VACUUM to avoid unnecessary index scans, bumped the nbtree version number from 2 to 3, while adding the ability for nbtree indexes to be upgraded on-the-fly. Various assertions that assumed that an nbtree index was alw

pgsql: Fix typo in mvdistinct.c

2019-07-18 Thread Michael Paquier
Fix typo in mvdistinct.c Noticed while browsing the code. Branch -- master Details --- https://git.postgresql.org/pg/commitdiff/70a33b21099c046dc38f07ffb02b1e0cf2aff91d Modified Files -- src/backend/statistics/mvdistinct.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)

pgsql: Refactor parallelization processing code in src/bin/scripts/

2019-07-18 Thread Michael Paquier
Refactor parallelization processing code in src/bin/scripts/ The existing facility of vacuumdb to handle parallel connections into a given database with an authentication set is moved to a common file in src/bin/scripts/, named scripts_parallel.c. This introduces a set of routines to initialize,

pgsql: Fix daterange canonicalization for +/- infinity.

2019-07-18 Thread Jeff Davis
Fix daterange canonicalization for +/- infinity. The values 'infinity' and '-infinity' are a part of the DATE type itself, so a bound of the date 'infinity' is not the same as an unbounded/infinite range. However, it is still wrong to try to canonicalize such values, because adding or subtracting

pgsql: Fix error in commit e6feef57.

2019-07-18 Thread Jeff Davis
Fix error in commit e6feef57. I was careless passing a datum directly to DATE_NOT_FINITE without calling DatumGetDateADT() first. Backpatch-through: 9.4 Branch -- master Details --- https://git.postgresql.org/pg/commitdiff/b538c90b1bded5464787e2b8e4431302d24eb601 Modified Files ---

pgsql: Fix daterange canonicalization for +/- infinity.

2019-07-18 Thread Jeff Davis
Fix daterange canonicalization for +/- infinity. The values 'infinity' and '-infinity' are a part of the DATE type itself, so a bound of the date 'infinity' is not the same as an unbounded/infinite range. However, it is still wrong to try to canonicalize such values, because adding or subtracting

pgsql: Fix daterange canonicalization for +/- infinity.

2019-07-18 Thread Jeff Davis
Fix daterange canonicalization for +/- infinity. The values 'infinity' and '-infinity' are a part of the DATE type itself, so a bound of the date 'infinity' is not the same as an unbounded/infinite range. However, it is still wrong to try to canonicalize such values, because adding or subtracting

pgsql: Fix error in commit e6feef57.

2019-07-18 Thread Jeff Davis
Fix error in commit e6feef57. I was careless passing a datum directly to DATE_NOT_FINITE without calling DatumGetDateADT() first. Backpatch-through: 9.4 Branch -- REL9_6_STABLE Details --- https://git.postgresql.org/pg/commitdiff/390bf90f70a835278c7627fb65e4e9039855bcc3 Modified Files

pgsql: Fix error in commit e6feef57.

2019-07-18 Thread Jeff Davis
Fix error in commit e6feef57. I was careless passing a datum directly to DATE_NOT_FINITE without calling DatumGetDateADT() first. Backpatch-through: 9.4 Branch -- REL_10_STABLE Details --- https://git.postgresql.org/pg/commitdiff/b0a7e0f07fadba9542a711a4cbafc244c19d493b Modified Files

pgsql: Fix error in commit e6feef57.

2019-07-18 Thread Jeff Davis
Fix error in commit e6feef57. I was careless passing a datum directly to DATE_NOT_FINITE without calling DatumGetDateADT() first. Backpatch-through: 9.4 Branch -- REL9_4_STABLE Details --- https://git.postgresql.org/pg/commitdiff/812623b69eac3535bcf422e6aea335d6f7753fec Modified Files

pgsql: Fix error in commit e6feef57.

2019-07-18 Thread Jeff Davis
Fix error in commit e6feef57. I was careless passing a datum directly to DATE_NOT_FINITE without calling DatumGetDateADT() first. Backpatch-through: 9.4 Branch -- REL_11_STABLE Details --- https://git.postgresql.org/pg/commitdiff/477ebfc9695e267d3f345a77211579236bcac91c Modified Files

pgsql: Fix daterange canonicalization for +/- infinity.

2019-07-18 Thread Jeff Davis
Fix daterange canonicalization for +/- infinity. The values 'infinity' and '-infinity' are a part of the DATE type itself, so a bound of the date 'infinity' is not the same as an unbounded/infinite range. However, it is still wrong to try to canonicalize such values, because adding or subtracting

pgsql: Fix error in commit e6feef57.

2019-07-18 Thread Jeff Davis
Fix error in commit e6feef57. I was careless passing a datum directly to DATE_NOT_FINITE without calling DatumGetDateADT() first. Backpatch-through: 9.4 Branch -- REL9_5_STABLE Details --- https://git.postgresql.org/pg/commitdiff/f1c72294ba62ccc95bc510e2ee52f537fc9ec5bf Modified Files

pgsql: Fix daterange canonicalization for +/- infinity.

2019-07-18 Thread Jeff Davis
Fix daterange canonicalization for +/- infinity. The values 'infinity' and '-infinity' are a part of the DATE type itself, so a bound of the date 'infinity' is not the same as an unbounded/infinite range. However, it is still wrong to try to canonicalize such values, because adding or subtracting

pgsql: Fix daterange canonicalization for +/- infinity.

2019-07-18 Thread Jeff Davis
Fix daterange canonicalization for +/- infinity. The values 'infinity' and '-infinity' are a part of the DATE type itself, so a bound of the date 'infinity' is not the same as an unbounded/infinite range. However, it is still wrong to try to canonicalize such values, because adding or subtracting

pgsql: Fix daterange canonicalization for +/- infinity.

2019-07-18 Thread Jeff Davis
Fix daterange canonicalization for +/- infinity. The values 'infinity' and '-infinity' are a part of the DATE type itself, so a bound of the date 'infinity' is not the same as an unbounded/infinite range. However, it is still wrong to try to canonicalize such values, because adding or subtracting

pgsql: Fix error in commit e6feef57.

2019-07-18 Thread Jeff Davis
Fix error in commit e6feef57. I was careless passing a datum directly to DATE_NOT_FINITE without calling DatumGetDateADT() first. Backpatch-through: 9.4 Branch -- REL_12_STABLE Details --- https://git.postgresql.org/pg/commitdiff/5245552ddbc43b7705389cae9c5095e687a3c950 Modified Files

pgsql: Doc: clarify when table rewrites happen with column addition and

2019-07-18 Thread Michael Paquier
Doc: clarify when table rewrites happen with column addition and DEFAULT 16828d5 has improved ALTER TABLE so as a column addition does not require a rewrite for a non-NULL default with constant expressions, but one spot in the documentation did not get updated consistently. The documentation also

pgsql: Doc: clarify when table rewrites happen with column addition and

2019-07-18 Thread Michael Paquier
Doc: clarify when table rewrites happen with column addition and DEFAULT 16828d5 has improved ALTER TABLE so as a column addition does not require a rewrite for a non-NULL default with constant expressions, but one spot in the documentation did not get updated consistently. The documentation also

pgsql: Doc: clarify when table rewrites happen with column addition and

2019-07-18 Thread Michael Paquier
Doc: clarify when table rewrites happen with column addition and DEFAULT 16828d5 has improved ALTER TABLE so as a column addition does not require a rewrite for a non-NULL default with constant expressions, but one spot in the documentation did not get updated consistently. The documentation also