diff --git a/.gitignore b/.gitignore
index 36882a0176..b11acc3a93 100644
--- a/.gitignore
+++ b/.gitignore
@@ -21,8 +21,9 @@ objfiles.txt
*.gcda
*.gcov
*.gcov.out
-lcov.info
+lcov*.info
coverage/
+coverage-html-stamp
*.vcproj
*.vcxproj
win32ver.rc
@@ -58,3 +59,4 @@ lib*.pc
/src/test/isolation/regression.out
/src/test/isolation/regression.diffs
/src/test/isolation/regression.out
+/contrib/pgcrypto/rijndael.tbl
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 120c89414f..1d989ce96d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -25,7 +25,7 @@ set(POSTGRES_VERSION
${POSTGRES_MAJOR_VERSION}.${POSTGRES_MINOR_VERSION}.${POSTGRES_PATCH_VERSION})
set(PG_VERSION "11devel")
-set(PG_VERSION_NUM 100000)
+set(PG_VERSION_NUM 110000)
set(PACKAGE_BUGREPORT "pgsql-bugs@postgresql.org")
# Offer the user the choice of overriding the installation directories
@@ -286,6 +286,15 @@ if(USE_BONJOUR)
endif()
endif()
+option(WITH_SYSTEM_TZDATA "Define to use system tzdata information." OFF)
+if (WITH_SYSTEM_TZDATA)
+ if (EXISTS ${WITH_SYSTEM_TZDATA})
+ add_compile_options(-DSYSTEMTZDIR="${WITH_SYSTEM_TZDATA}")
+ else()
+ message(FATAL_ERROR "tzdata directory \"${WITH_SYSTEM_TZDATA}\" does not exists")
+ endif()
+endif()
+
option(STRONG_RANDOM "Strong random number source" ON)
option(STRONG_RANDOM_SOURCE "which random number source to use - openssl, win32, dev" OFF)
if(STRONG_RANDOM)
@@ -691,6 +700,8 @@ if(OPENSSL_FOUND)
set(CMAKE_REQUIRED_INCLUDES "${CMAKE_REQUIRED_INCLUDES};${OPENSSL_INCLUDE_DIR}")
set(CMAKE_REQUIRED_LIBRARIES ${OPENSSL_LIBRARIES})
check_function_exists(SSL_get_current_compression HAVE_SSL_GET_CURRENT_COMPRESSION)
+ check_function_exists(BIO_get_data HAVE_BIO_GET_DATA)
+ check_function_exists(BIO_meth_new HAVE_BIO_METH_NEW)
endif(OPENSSL_FOUND)
if(USE_SYSTEMD)
@@ -1416,7 +1427,11 @@ add_subdirectory(contrib)
message(STATUS "------------------")
message(STATUS " Conclusion")
message(STATUS "Host tuple: ${HOST_TUPLE}")
-message(STATUS "OpenSSL: ${OPENSSL_FOUND} version: ${OPENSSL_VERSION} libs: ${OPENSSL_LIBRARIES} include: ${OPENSSL_INCLUDE_DIR}")
+if(OPENSSL_FOUND)
+ message(STATUS "OpenSSL version: ${OPENSSL_VERSION} libs: ${OPENSSL_LIBRARIES} include: ${OPENSSL_INCLUDE_DIR}")
+else()
+ message(STATUS "OpenSSL: off")
+endif()
message(STATUS "Python: ${PYTHONINTERP_FOUND}")
message(STATUS "PythonLibs: ${PYTHONLIBS_FOUND}")
message(STATUS "PerlLibs: ${PERLLIBS_FOUND}")
diff --git a/COPYRIGHT b/COPYRIGHT
index c320eccac0..33e6e4842a 100644
--- a/COPYRIGHT
+++ b/COPYRIGHT
@@ -1,7 +1,7 @@
PostgreSQL Database Management System
(formerly known as Postgres, then as Postgres95)
-Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
+Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
Portions Copyright (c) 1994, The Regents of the University of California
diff --git a/Makefile b/Makefile
index 4c68950e90..c400854cd3 100644
--- a/Makefile
+++ b/Makefile
@@ -11,6 +11,10 @@
# GNUmakefile won't exist yet, so we catch that case as well.
+# AIX make defaults to building *every* target of the first rule. Start with
+# a single-target, empty rule to make the other targets non-default.
+all:
+
all check install installdirs installcheck installcheck-parallel uninstall clean distclean maintainer-clean dist distcheck world check-world install-world installcheck-world:
@if [ ! -f GNUmakefile ] ; then \
echo "You need to run the 'configure' program first. See the file"; \
diff --git a/README.md b/README.md
index 2465a6ebb4..2c158ad3a7 100644
--- a/README.md
+++ b/README.md
@@ -103,6 +103,8 @@ CMake build options
**-DSTRONG_RANDOM_SOURCE** default OFF (autodetect), which random number source to use - openssl, win32, dev
+**-DWITH_SYSTEM_TZDATA=
** default OFF, custom tzdata directory
+
Only **MSVC** options:
**-DUSE_FP_STRICT** default ON, if we use /fp:stirct compiler option we much closer to C99 standart in float part
diff --git a/cmake/CheckRestrict.cmake b/cmake/CheckRestrict.cmake
new file mode 100644
index 0000000000..f8f00c0c4f
--- /dev/null
+++ b/cmake/CheckRestrict.cmake
@@ -0,0 +1,3 @@
+CHECK_C_SOURCE_COMPILES (
+ "int test (void *restrict x); int main (void) {return 0;}"
+ HAVE_RESTRICT)
diff --git a/config/c-compiler.m4 b/config/c-compiler.m4
index 7275ea69fe..689bb7f181 100644
--- a/config/c-compiler.m4
+++ b/config/c-compiler.m4
@@ -96,9 +96,11 @@ undefine([Ac_cachevar])dnl
# PGAC_TYPE_128BIT_INT
# ---------------------
# Check if __int128 is a working 128 bit integer type, and if so
-# define PG_INT128_TYPE to that typename. This currently only detects
-# a GCC/clang extension, but support for different environments may be
-# added in the future.
+# define PG_INT128_TYPE to that typename, and define ALIGNOF_PG_INT128_TYPE
+# as its alignment requirement.
+#
+# This currently only detects a GCC/clang extension, but support for other
+# environments may be added in the future.
#
# For the moment we only test for support for 128bit math; support for
# 128bit literals and snprintf is not required.
@@ -106,28 +108,61 @@ AC_DEFUN([PGAC_TYPE_128BIT_INT],
[AC_CACHE_CHECK([for __int128], [pgac_cv__128bit_int],
[AC_LINK_IFELSE([AC_LANG_PROGRAM([
/*
+ * We don't actually run this test, just link it to verify that any support
+ * functions needed for __int128 are present.
+ *
* These are globals to discourage the compiler from folding all the
* arithmetic tests down to compile-time constants. We do not have
- * convenient support for 64bit literals at this point...
+ * convenient support for 128bit literals at this point...
*/
__int128 a = 48828125;
-__int128 b = 97656255;
+__int128 b = 97656250;
],[
__int128 c,d;
a = (a << 12) + 1; /* 200000000001 */
b = (b << 12) + 5; /* 400000000005 */
-/* use the most relevant arithmetic ops */
+/* try the most relevant arithmetic ops */
c = a * b;
d = (c + b) / b;
-/* return different values, to prevent optimizations */
+/* must use the results, else compiler may optimize arithmetic away */
if (d != a+1)
- return 0;
-return 1;
+ return 1;
])],
[pgac_cv__128bit_int=yes],
[pgac_cv__128bit_int=no])])
if test x"$pgac_cv__128bit_int" = xyes ; then
- AC_DEFINE(PG_INT128_TYPE, __int128, [Define to the name of a signed 128-bit integer type.])
+ # Use of non-default alignment with __int128 tickles bugs in some compilers.
+ # If not cross-compiling, we can test for bugs and disable use of __int128
+ # with buggy compilers. If cross-compiling, hope for the best.
+ # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83925
+ AC_CACHE_CHECK([for __int128 alignment bug], [pgac_cv__128bit_int_bug],
+ [AC_RUN_IFELSE([AC_LANG_PROGRAM([
+/* This must match the corresponding code in c.h: */
+#if defined(__GNUC__) || defined(__SUNPRO_C) || defined(__IBMC__)
+#define pg_attribute_aligned(a) __attribute__((aligned(a)))
+#endif
+typedef __int128 int128a
+#if defined(pg_attribute_aligned)
+pg_attribute_aligned(8)
+#endif
+;
+int128a holder;
+void pass_by_val(void *buffer, int128a par) { holder = par; }
+],[
+long int i64 = 97656225L << 12;
+int128a q;
+pass_by_val(main, (int128a) i64);
+q = (int128a) i64;
+if (q != holder)
+ return 1;
+])],
+ [pgac_cv__128bit_int_bug=ok],
+ [pgac_cv__128bit_int_bug=broken],
+ [pgac_cv__128bit_int_bug="assuming ok"])])
+ if test x"$pgac_cv__128bit_int_bug" != xbroken ; then
+ AC_DEFINE(PG_INT128_TYPE, __int128, [Define to the name of a signed 128-bit integer type.])
+ AC_CHECK_ALIGNOF(PG_INT128_TYPE)
+ fi
fi])# PGAC_TYPE_128BIT_INT
@@ -224,6 +259,23 @@ AC_DEFINE(HAVE__BUILTIN_TYPES_COMPATIBLE_P, 1,
fi])# PGAC_C_TYPES_COMPATIBLE
+# PGAC_C_BUILTIN_BSWAP16
+# -------------------------
+# Check if the C compiler understands __builtin_bswap16(),
+# and define HAVE__BUILTIN_BSWAP16 if so.
+AC_DEFUN([PGAC_C_BUILTIN_BSWAP16],
+[AC_CACHE_CHECK(for __builtin_bswap16, pgac_cv__builtin_bswap16,
+[AC_COMPILE_IFELSE([AC_LANG_SOURCE(
+[static unsigned long int x = __builtin_bswap16(0xaabb);]
+)],
+[pgac_cv__builtin_bswap16=yes],
+[pgac_cv__builtin_bswap16=no])])
+if test x"$pgac_cv__builtin_bswap16" = xyes ; then
+AC_DEFINE(HAVE__BUILTIN_BSWAP16, 1,
+ [Define to 1 if your compiler understands __builtin_bswap16.])
+fi])# PGAC_C_BUILTIN_BSWAP16
+
+
# PGAC_C_BUILTIN_BSWAP32
# -------------------------
@@ -265,10 +317,15 @@ fi])# PGAC_C_BUILTIN_BSWAP64
# -------------------------
# Check if the C compiler understands __builtin_constant_p(),
# and define HAVE__BUILTIN_CONSTANT_P if so.
+# We need __builtin_constant_p("string literal") to be true, but some older
+# compilers don't think that, so test for that case explicitly.
AC_DEFUN([PGAC_C_BUILTIN_CONSTANT_P],
[AC_CACHE_CHECK(for __builtin_constant_p, pgac_cv__builtin_constant_p,
[AC_COMPILE_IFELSE([AC_LANG_SOURCE(
-[[static int x; static int y[__builtin_constant_p(x) ? x : 1];]]
+[[static int x;
+ static int y[__builtin_constant_p(x) ? x : 1];
+ static int z[__builtin_constant_p("string literal") ? 1 : x];
+]]
)],
[pgac_cv__builtin_constant_p=yes],
[pgac_cv__builtin_constant_p=no])])
@@ -279,6 +336,34 @@ fi])# PGAC_C_BUILTIN_CONSTANT_P
+# PGAC_C_BUILTIN_OP_OVERFLOW
+# -------------------------
+# Check if the C compiler understands __builtin_$op_overflow(),
+# and define HAVE__BUILTIN_OP_OVERFLOW if so.
+#
+# Check for the most complicated case, 64 bit multiplication, as a
+# proxy for all of the operations. To detect the case where the compiler
+# knows the function but library support is missing, we must link not just
+# compile, and store the results in global variables so the compiler doesn't
+# optimize away the call.
+AC_DEFUN([PGAC_C_BUILTIN_OP_OVERFLOW],
+[AC_CACHE_CHECK(for __builtin_mul_overflow, pgac_cv__builtin_op_overflow,
+[AC_LINK_IFELSE([AC_LANG_PROGRAM([
+PG_INT64_TYPE a = 1;
+PG_INT64_TYPE b = 1;
+PG_INT64_TYPE result;
+int oflo;
+],
+[oflo = __builtin_mul_overflow(a, b, &result);])],
+[pgac_cv__builtin_op_overflow=yes],
+[pgac_cv__builtin_op_overflow=no])])
+if test x"$pgac_cv__builtin_op_overflow" = xyes ; then
+AC_DEFINE(HAVE__BUILTIN_OP_OVERFLOW, 1,
+ [Define to 1 if your compiler understands __builtin_$op_overflow.])
+fi])# PGAC_C_BUILTIN_OP_OVERFLOW
+
+
+
# PGAC_C_BUILTIN_UNREACHABLE
# --------------------------
# Check if the C compiler understands __builtin_unreachable(),
diff --git a/config/docbook.m4 b/config/docbook.m4
index f9307f329e..34b829eade 100644
--- a/config/docbook.m4
+++ b/config/docbook.m4
@@ -1,18 +1,18 @@
# config/docbook.m4
-# PGAC_PROG_NSGMLS
-# ----------------
-AC_DEFUN([PGAC_PROG_NSGMLS],
-[PGAC_PATH_PROGS(NSGMLS, [onsgmls nsgmls])])
+# PGAC_PATH_XMLLINT
+# -----------------
+AC_DEFUN([PGAC_PATH_XMLLINT],
+[PGAC_PATH_PROGS(XMLLINT, xmllint)])
# PGAC_CHECK_DOCBOOK(VERSION)
# ---------------------------
AC_DEFUN([PGAC_CHECK_DOCBOOK],
-[AC_REQUIRE([PGAC_PROG_NSGMLS])
-AC_CACHE_CHECK([for DocBook V$1], [pgac_cv_check_docbook],
-[cat >conftest.sgml <
+[AC_REQUIRE([PGAC_PATH_XMLLINT])
+AC_CACHE_CHECK([for DocBook XML V$1], [pgac_cv_check_docbook],
+[cat >conftest.xml <test
@@ -27,13 +27,13 @@ EOF
pgac_cv_check_docbook=no
-if test -n "$NSGMLS"; then
- $NSGMLS -s conftest.sgml 1>&AS_MESSAGE_LOG_FD 2>&1
+if test -n "$XMLLINT"; then
+ $XMLLINT --noout --valid conftest.xml 1>&AS_MESSAGE_LOG_FD 2>&1
if test $? -eq 0; then
pgac_cv_check_docbook=yes
fi
fi
-rm -f conftest.sgml])
+rm -f conftest.xml])
have_docbook=$pgac_cv_check_docbook
AC_SUBST([have_docbook])
diff --git a/config/perl.m4 b/config/perl.m4
index 8c21d0fb39..caefb0705e 100644
--- a/config/perl.m4
+++ b/config/perl.m4
@@ -48,19 +48,23 @@ AC_DEFUN([PGAC_CHECK_PERL_CONFIGS],
# PGAC_CHECK_PERL_EMBED_CCFLAGS
# -----------------------------
-# We selectively extract stuff from $Config{ccflags}. We don't really need
-# anything except -D switches, and other sorts of compiler switches can
-# actively break things if Perl was compiled with a different compiler.
-# Moreover, although Perl likes to put stuff like -D_LARGEFILE_SOURCE and
-# -D_FILE_OFFSET_BITS=64 here, it would be fatal to try to compile PL/Perl
-# to a different libc ABI than core Postgres uses. The available information
-# says that all the symbols that affect Perl's own ABI begin with letters,
-# so it should be sufficient to adopt -D switches for symbols not beginning
-# with underscore. An exception is that we need to let through
-# -D_USE_32BIT_TIME_T if it's present. (We probably could restrict that to
-# only get through on Windows, but for the moment we let it through always.)
-# For debugging purposes, let's have the configure output report the raw
-# ccflags value as well as the set of flags we chose to adopt.
+# We selectively extract stuff from $Config{ccflags}. For debugging purposes,
+# let's have the configure output report the raw ccflags value as well as the
+# set of flags we chose to adopt. We don't really need anything except -D
+# switches, and other sorts of compiler switches can actively break things if
+# Perl was compiled with a different compiler. Moreover, although Perl likes
+# to put stuff like -D_LARGEFILE_SOURCE and -D_FILE_OFFSET_BITS=64 here, it
+# would be fatal to try to compile PL/Perl to a different libc ABI than core
+# Postgres uses. The available information says that most symbols that affect
+# Perl's own ABI begin with letters, so it's almost sufficient to adopt -D
+# switches for symbols not beginning with underscore. Some exceptions are the
+# Windows-specific -D_USE_32BIT_TIME_T and -D__MINGW_USE_VC2005_COMPAT; see
+# Mkvcbuild.pm for details. We absorb the former when Perl reports it. Perl
+# never reports the latter, and we don't attempt to deduce when it's needed.
+# Consequently, we don't support using MinGW to link to MSVC-built Perl. As
+# of 2017, all supported ActivePerl and Strawberry Perl are MinGW-built. If
+# that changes or an MSVC-built Perl distribution becomes prominent, we can
+# revisit this limitation.
AC_DEFUN([PGAC_CHECK_PERL_EMBED_CCFLAGS],
[AC_REQUIRE([PGAC_PATH_PERL])
AC_MSG_CHECKING([for CFLAGS recommended by Perl])
@@ -83,12 +87,19 @@ AC_DEFUN([PGAC_CHECK_PERL_EMBED_LDFLAGS],
[AC_REQUIRE([PGAC_PATH_PERL])
AC_MSG_CHECKING(for flags to link embedded Perl)
if test "$PORTNAME" = "win32" ; then
-perl_lib=`basename $perl_archlibexp/CORE/perl[[5-9]]*.lib .lib`
-test -e "$perl_archlibexp/CORE/$perl_lib.lib" && perl_embed_ldflags="-L$perl_archlibexp/CORE -l$perl_lib"
+ perl_lib=`basename $perl_archlibexp/CORE/perl[[5-9]]*.lib .lib`
+ if test -e "$perl_archlibexp/CORE/$perl_lib.lib"; then
+ perl_embed_ldflags="-L$perl_archlibexp/CORE -l$perl_lib"
+ else
+ perl_lib=`basename $perl_archlibexp/CORE/libperl[[5-9]]*.a .a | sed 's/^lib//'`
+ if test -e "$perl_archlibexp/CORE/lib$perl_lib.a"; then
+ perl_embed_ldflags="-L$perl_archlibexp/CORE -l$perl_lib"
+ fi
+ fi
else
-pgac_tmp1=`$PERL -MExtUtils::Embed -e ldopts`
-pgac_tmp2=`$PERL -MConfig -e 'print $Config{ccdlflags}'`
-perl_embed_ldflags=`echo X"$pgac_tmp1" | sed -e "s/^X//" -e "s%$pgac_tmp2%%" -e ["s/ -arch [-a-zA-Z0-9_]*//g"]`
+ pgac_tmp1=`$PERL -MExtUtils::Embed -e ldopts`
+ pgac_tmp2=`$PERL -MConfig -e 'print $Config{ccdlflags}'`
+ perl_embed_ldflags=`echo X"$pgac_tmp1" | sed -e "s/^X//" -e "s%$pgac_tmp2%%" -e ["s/ -arch [-a-zA-Z0-9_]*//g"]`
fi
AC_SUBST(perl_embed_ldflags)dnl
if test -z "$perl_embed_ldflags" ; then
diff --git a/configure b/configure
index a2f9a256b4..7dcca506f8 100755
--- a/configure
+++ b/configure
@@ -11,7 +11,7 @@
# This configure script is free software; the Free Software Foundation
# gives unlimited permission to copy, distribute and modify it.
#
-# Copyright (c) 1996-2017, PostgreSQL Global Development Group
+# Copyright (c) 1996-2018, PostgreSQL Global Development Group
## -------------------- ##
## M4sh Initialization. ##
## -------------------- ##
@@ -630,12 +630,10 @@ vpath_build
PG_VERSION_NUM
PROVE
FOP
-OSX
XSLTPROC
-XMLLINT
DBTOEPUB
have_docbook
-NSGMLS
+XMLLINT
TCL_SHLIB_LD_LIBS
TCL_SHARED_BUILD
TCL_LIB_SPEC
@@ -821,7 +819,6 @@ enable_tap_tests
with_blocksize
with_segsize
with_wal_blocksize
-with_wal_segsize
with_CC
enable_depend
enable_cassert
@@ -1518,8 +1515,6 @@ Optional Packages:
--with-segsize=SEGSIZE set table segment size in GB [1]
--with-wal-blocksize=BLOCKSIZE
set WAL block size in kB [8]
- --with-wal-segsize=SEGSIZE
- set WAL segment size in MB [16]
--with-CC=CMD set compiler (deprecated)
--with-icu build with ICU support
--with-tcl build Tcl modules (PL/Tcl)
@@ -1640,7 +1635,7 @@ Copyright (C) 2012 Free Software Foundation, Inc.
This configure script is free software; the Free Software Foundation
gives unlimited permission to copy, distribute and modify it.
-Copyright (c) 1996-2017, PostgreSQL Global Development Group
+Copyright (c) 1996-2018, PostgreSQL Global Development Group
_ACEOF
exit
fi
@@ -3733,57 +3728,6 @@ cat >>confdefs.h <<_ACEOF
_ACEOF
-#
-# WAL segment size
-#
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for WAL segment size" >&5
-$as_echo_n "checking for WAL segment size... " >&6; }
-
-
-
-# Check whether --with-wal-segsize was given.
-if test "${with_wal_segsize+set}" = set; then :
- withval=$with_wal_segsize;
- case $withval in
- yes)
- as_fn_error $? "argument required for --with-wal-segsize option" "$LINENO" 5
- ;;
- no)
- as_fn_error $? "argument required for --with-wal-segsize option" "$LINENO" 5
- ;;
- *)
- wal_segsize=$withval
- ;;
- esac
-
-else
- wal_segsize=16
-fi
-
-
-case ${wal_segsize} in
- 1) ;;
- 2) ;;
- 4) ;;
- 8) ;;
- 16) ;;
- 32) ;;
- 64) ;;
- 128) ;;
- 256) ;;
- 512) ;;
- 1024) ;;
- *) as_fn_error $? "Invalid WAL segment size. Allowed values are 1,2,4,8,16,32,64,128,256,512,1024." "$LINENO" 5
-esac
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: ${wal_segsize}MB" >&5
-$as_echo "${wal_segsize}MB" >&6; }
-
-
-cat >>confdefs.h <<_ACEOF
-#define XLOG_SEG_SIZE (${wal_segsize} * 1024 * 1024)
-_ACEOF
-
-
#
# C compiler
#
@@ -7874,12 +7818,19 @@ $as_echo "$perl_embed_ccflags" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for flags to link embedded Perl" >&5
$as_echo_n "checking for flags to link embedded Perl... " >&6; }
if test "$PORTNAME" = "win32" ; then
-perl_lib=`basename $perl_archlibexp/CORE/perl[5-9]*.lib .lib`
-test -e "$perl_archlibexp/CORE/$perl_lib.lib" && perl_embed_ldflags="-L$perl_archlibexp/CORE -l$perl_lib"
+ perl_lib=`basename $perl_archlibexp/CORE/perl[5-9]*.lib .lib`
+ if test -e "$perl_archlibexp/CORE/$perl_lib.lib"; then
+ perl_embed_ldflags="-L$perl_archlibexp/CORE -l$perl_lib"
+ else
+ perl_lib=`basename $perl_archlibexp/CORE/libperl[5-9]*.a .a | sed 's/^lib//'`
+ if test -e "$perl_archlibexp/CORE/lib$perl_lib.a"; then
+ perl_embed_ldflags="-L$perl_archlibexp/CORE -l$perl_lib"
+ fi
+ fi
else
-pgac_tmp1=`$PERL -MExtUtils::Embed -e ldopts`
-pgac_tmp2=`$PERL -MConfig -e 'print $Config{ccdlflags}'`
-perl_embed_ldflags=`echo X"$pgac_tmp1" | sed -e "s/^X//" -e "s%$pgac_tmp2%%" -e "s/ -arch [-a-zA-Z0-9_]*//g"`
+ pgac_tmp1=`$PERL -MExtUtils::Embed -e ldopts`
+ pgac_tmp2=`$PERL -MConfig -e 'print $Config{ccdlflags}'`
+ perl_embed_ldflags=`echo X"$pgac_tmp1" | sed -e "s/^X//" -e "s%$pgac_tmp2%%" -e "s/ -arch [-a-zA-Z0-9_]*//g"`
fi
if test -z "$perl_embed_ldflags" ; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
@@ -10174,12 +10125,13 @@ else
fi
fi
- for ac_func in SSL_get_current_compression
+ for ac_func in SSL_get_current_compression X509_get_signature_nid
do :
- ac_fn_c_check_func "$LINENO" "SSL_get_current_compression" "ac_cv_func_SSL_get_current_compression"
-if test "x$ac_cv_func_SSL_get_current_compression" = xyes; then :
+ as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
+ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
+if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
cat >>confdefs.h <<_ACEOF
-#define HAVE_SSL_GET_CURRENT_COMPRESSION 1
+#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
_ACEOF
fi
@@ -10473,6 +10425,17 @@ fi
else
LDAP_LIBS_FE="-lldap $EXTRA_LDAP_LIBS"
fi
+ for ac_func in ldap_initialize
+do :
+ ac_fn_c_check_func "$LINENO" "ldap_initialize" "ac_cv_func_ldap_initialize"
+if test "x$ac_cv_func_ldap_initialize" = xyes; then :
+ cat >>confdefs.h <<_ACEOF
+#define HAVE_LDAP_INITIALIZE 1
+_ACEOF
+
+fi
+done
+
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ldap_bind in -lwldap32" >&5
$as_echo_n "checking for ldap_bind in -lwldap32... " >&6; }
@@ -11870,6 +11833,30 @@ if test x"$pgac_cv__types_compatible" = xyes ; then
$as_echo "#define HAVE__BUILTIN_TYPES_COMPATIBLE_P 1" >>confdefs.h
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __builtin_bswap16" >&5
+$as_echo_n "checking for __builtin_bswap16... " >&6; }
+if ${pgac_cv__builtin_bswap16+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+static unsigned long int x = __builtin_bswap16(0xaabb);
+
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+ pgac_cv__builtin_bswap16=yes
+else
+ pgac_cv__builtin_bswap16=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv__builtin_bswap16" >&5
+$as_echo "$pgac_cv__builtin_bswap16" >&6; }
+if test x"$pgac_cv__builtin_bswap16" = xyes ; then
+
+$as_echo "#define HAVE__BUILTIN_BSWAP16 1" >>confdefs.h
+
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __builtin_bswap32" >&5
$as_echo_n "checking for __builtin_bswap32... " >&6; }
@@ -11926,7 +11913,10 @@ if ${pgac_cv__builtin_constant_p+:} false; then :
else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
-static int x; static int y[__builtin_constant_p(x) ? x : 1];
+static int x;
+ static int y[__builtin_constant_p(x) ? x : 1];
+ static int z[__builtin_constant_p("string literal") ? 1 : x];
+
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
@@ -12492,6 +12482,71 @@ $as_echo "#define LOCALE_T_IN_XLOCALE 1" >>confdefs.h
fi
+# MSVC doesn't cope well with defining restrict to __restrict, the
+# spelling it understands, because it conflicts with
+# __declspec(restrict). Therefore we define pg_restrict to the
+# appropriate definition, which presumably won't conflict.
+#
+# Allow platforms with buggy compilers to force restrict to not be
+# used by setting $FORCE_DISABLE_RESTRICT=yes in the relevant
+# template.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for C/C++ restrict keyword" >&5
+$as_echo_n "checking for C/C++ restrict keyword... " >&6; }
+if ${ac_cv_c_restrict+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ ac_cv_c_restrict=no
+ # The order here caters to the fact that C++ does not require restrict.
+ for ac_kw in __restrict __restrict__ _Restrict restrict; do
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+typedef int * int_ptr;
+ int foo (int_ptr $ac_kw ip) {
+ return ip[0];
+ }
+int
+main ()
+{
+int s[1];
+ int * $ac_kw t = s;
+ t[0] = 0;
+ return foo(t)
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+ ac_cv_c_restrict=$ac_kw
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ test "$ac_cv_c_restrict" != no && break
+ done
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_restrict" >&5
+$as_echo "$ac_cv_c_restrict" >&6; }
+
+ case $ac_cv_c_restrict in
+ restrict) ;;
+ no) $as_echo "#define restrict /**/" >>confdefs.h
+ ;;
+ *) cat >>confdefs.h <<_ACEOF
+#define restrict $ac_cv_c_restrict
+_ACEOF
+ ;;
+ esac
+
+if test "$ac_cv_c_restrict" = "no" -o "x$FORCE_DISABLE_RESTRICT" = "xyes"; then
+ pg_restrict=""
+else
+ pg_restrict="$ac_cv_c_restrict"
+fi
+
+cat >>confdefs.h <<_ACEOF
+#define pg_restrict $pg_restrict
+_ACEOF
+
+
ac_fn_c_check_type "$LINENO" "struct cmsgcred" "ac_cv_type_struct_cmsgcred" "#include
#include
#ifdef HAVE_SYS_UCRED_H
@@ -13024,7 +13079,7 @@ fi
LIBS_including_readline="$LIBS"
LIBS=`echo "$LIBS" | sed -e 's/-ledit//g' -e 's/-lreadline//g'`
-for ac_func in cbrt clock_gettime dlopen fdatasync getifaddrs getpeerucred getrlimit mbstowcs_l memmove poll pstat pthread_is_threaded_np readlink setproctitle setsid shm_open symlink sync_file_range towlower utime utimes wcstombs wcstombs_l
+for ac_func in cbrt clock_gettime dlopen fdatasync getifaddrs getpeerucred getrlimit mbstowcs_l memmove poll posix_fallocate pstat pthread_is_threaded_np readlink setproctitle setsid shm_open symlink sync_file_range utime utimes wcstombs_l
do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
@@ -13191,6 +13246,16 @@ fi
cat >>confdefs.h <<_ACEOF
#define HAVE_DECL_STRLCPY $ac_have_decl
_ACEOF
+ac_fn_c_check_decl "$LINENO" "strnlen" "ac_cv_have_decl_strnlen" "$ac_includes_default"
+if test "x$ac_cv_have_decl_strnlen" = xyes; then :
+ ac_have_decl=1
+else
+ ac_have_decl=0
+fi
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_STRNLEN $ac_have_decl
+_ACEOF
# This is probably only present on macOS, but may as well check always
ac_fn_c_check_decl "$LINENO" "F_FULLFSYNC" "ac_cv_have_decl_F_FULLFSYNC" "#include
@@ -13558,6 +13623,19 @@ esac
fi
+ac_fn_c_check_func "$LINENO" "strnlen" "ac_cv_func_strnlen"
+if test "x$ac_cv_func_strnlen" = xyes; then :
+ $as_echo "#define HAVE_STRNLEN 1" >>confdefs.h
+
+else
+ case " $LIBOBJS " in
+ *" strnlen.$ac_objext "* ) ;;
+ *) LIBOBJS="$LIBOBJS strnlen.$ac_objext"
+ ;;
+esac
+
+fi
+
case $host_os in
@@ -14254,24 +14332,6 @@ cat >>confdefs.h <<_ACEOF
_ACEOF
-
-if test x"$HAVE_LONG_LONG_INT_64" = xyes ; then
- cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h. */
-
-#define INT64CONST(x) x##LL
-long long int foo = INT64CONST(0x1234567890123456);
-
-_ACEOF
-if ac_fn_c_try_compile "$LINENO"; then :
-
-$as_echo "#define HAVE_LL_CONSTANTS 1" >>confdefs.h
-
-fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-fi
-
-
# If we found "long int" is 64 bits, assume snprintf handles it. If
# we found we need to use "long long int", better check. We cope with
# snprintfs that use %lld, %qd, or %I64d as the format. If none of these
@@ -14427,6 +14487,45 @@ esac
fi
+# has to be down here, rather than with the other builtins, because
+# the test uses PG_INT64_TYPE.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __builtin_mul_overflow" >&5
+$as_echo_n "checking for __builtin_mul_overflow... " >&6; }
+if ${pgac_cv__builtin_op_overflow+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+PG_INT64_TYPE a = 1;
+PG_INT64_TYPE b = 1;
+PG_INT64_TYPE result;
+int oflo;
+
+int
+main ()
+{
+oflo = __builtin_mul_overflow(a, b, &result);
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+ pgac_cv__builtin_op_overflow=yes
+else
+ pgac_cv__builtin_op_overflow=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv__builtin_op_overflow" >&5
+$as_echo "$pgac_cv__builtin_op_overflow" >&6; }
+if test x"$pgac_cv__builtin_op_overflow" = xyes ; then
+
+$as_echo "#define HAVE__BUILTIN_OP_OVERFLOW 1" >>confdefs.h
+
+fi
+
# Check size of void *, size_t (enables tweaks for > 32bit address space)
# The cast to long int works around a bug in the HP C Compiler
# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
@@ -14824,7 +14923,10 @@ _ACEOF
# Compute maximum alignment of any basic type.
# We assume long's alignment is at least as strong as char, short, or int;
-# but we must check long long (if it exists) and double.
+# but we must check long long (if it is being used for int64) and double.
+# Note that we intentionally do not consider any types wider than 64 bits,
+# as allowing MAXIMUM_ALIGNOF to exceed 8 would be too much of a penalty
+# for disk and memory space.
MAX_ALIGNOF=$ac_cv_alignof_long
if test $MAX_ALIGNOF -lt $ac_cv_alignof_double ; then
@@ -14884,7 +14986,7 @@ _ACEOF
fi
-# Check for extensions offering the integer scalar type __int128.
+# Some compilers offer a 128-bit integer scalar type.
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __int128" >&5
$as_echo_n "checking for __int128... " >&6; }
if ${pgac_cv__128bit_int+:} false; then :
@@ -14894,12 +14996,15 @@ else
/* end confdefs.h. */
/*
+ * We don't actually run this test, just link it to verify that any support
+ * functions needed for __int128 are present.
+ *
* These are globals to discourage the compiler from folding all the
* arithmetic tests down to compile-time constants. We do not have
- * convenient support for 64bit literals at this point...
+ * convenient support for 128bit literals at this point...
*/
__int128 a = 48828125;
-__int128 b = 97656255;
+__int128 b = 97656250;
int
main ()
@@ -14908,13 +15013,12 @@ main ()
__int128 c,d;
a = (a << 12) + 1; /* 200000000001 */
b = (b << 12) + 5; /* 400000000005 */
-/* use the most relevant arithmetic ops */
+/* try the most relevant arithmetic ops */
c = a * b;
d = (c + b) / b;
-/* return different values, to prevent optimizations */
+/* must use the results, else compiler may optimize arithmetic away */
if (d != a+1)
- return 0;
-return 1;
+ return 1;
;
return 0;
@@ -14931,9 +15035,100 @@ fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv__128bit_int" >&5
$as_echo "$pgac_cv__128bit_int" >&6; }
if test x"$pgac_cv__128bit_int" = xyes ; then
+ # Use of non-default alignment with __int128 tickles bugs in some compilers.
+ # If not cross-compiling, we can test for bugs and disable use of __int128
+ # with buggy compilers. If cross-compiling, hope for the best.
+ # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83925
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for __int128 alignment bug" >&5
+$as_echo_n "checking for __int128 alignment bug... " >&6; }
+if ${pgac_cv__128bit_int_bug+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ if test "$cross_compiling" = yes; then :
+ pgac_cv__128bit_int_bug="assuming ok"
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+/* This must match the corresponding code in c.h: */
+#if defined(__GNUC__) || defined(__SUNPRO_C) || defined(__IBMC__)
+#define pg_attribute_aligned(a) __attribute__((aligned(a)))
+#endif
+typedef __int128 int128a
+#if defined(pg_attribute_aligned)
+pg_attribute_aligned(8)
+#endif
+;
+int128a holder;
+void pass_by_val(void *buffer, int128a par) { holder = par; }
+
+int
+main ()
+{
+
+long int i64 = 97656225L << 12;
+int128a q;
+pass_by_val(main, (int128a) i64);
+q = (int128a) i64;
+if (q != holder)
+ return 1;
+
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+ pgac_cv__128bit_int_bug=ok
+else
+ pgac_cv__128bit_int_bug=broken
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+ conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv__128bit_int_bug" >&5
+$as_echo "$pgac_cv__128bit_int_bug" >&6; }
+ if test x"$pgac_cv__128bit_int_bug" != xbroken ; then
$as_echo "#define PG_INT128_TYPE __int128" >>confdefs.h
+ # The cast to long int works around a bug in the HP C Compiler,
+# see AC_CHECK_SIZEOF for more information.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking alignment of PG_INT128_TYPE" >&5
+$as_echo_n "checking alignment of PG_INT128_TYPE... " >&6; }
+if ${ac_cv_alignof_PG_INT128_TYPE+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ if ac_fn_c_compute_int "$LINENO" "(long int) offsetof (ac__type_alignof_, y)" "ac_cv_alignof_PG_INT128_TYPE" "$ac_includes_default
+#ifndef offsetof
+# define offsetof(type, member) ((char *) &((type *) 0)->member - (char *) 0)
+#endif
+typedef struct { char x; PG_INT128_TYPE y; } ac__type_alignof_;"; then :
+
+else
+ if test "$ac_cv_type_PG_INT128_TYPE" = yes; then
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error 77 "cannot compute alignment of PG_INT128_TYPE
+See \`config.log' for more details" "$LINENO" 5; }
+ else
+ ac_cv_alignof_PG_INT128_TYPE=0
+ fi
+fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_alignof_PG_INT128_TYPE" >&5
+$as_echo "$ac_cv_alignof_PG_INT128_TYPE" >&6; }
+
+
+
+cat >>confdefs.h <<_ACEOF
+#define ALIGNOF_PG_INT128_TYPE $ac_cv_alignof_PG_INT128_TYPE
+_ACEOF
+
+
+ fi
fi
# Check for various atomic operations now that we have checked how to declare
@@ -16054,19 +16249,19 @@ fi
#
# Check for DocBook and tools
#
-if test -z "$NSGMLS"; then
- for ac_prog in onsgmls nsgmls
+if test -z "$XMLLINT"; then
+ for ac_prog in xmllint
do
# Extract the first word of "$ac_prog", so it can be a program name with args.
set dummy $ac_prog; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_path_NSGMLS+:} false; then :
+if ${ac_cv_path_XMLLINT+:} false; then :
$as_echo_n "(cached) " >&6
else
- case $NSGMLS in
+ case $XMLLINT in
[\\/]* | ?:[\\/]*)
- ac_cv_path_NSGMLS="$NSGMLS" # Let the user override the test with a path.
+ ac_cv_path_XMLLINT="$XMLLINT" # Let the user override the test with a path.
;;
*)
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
@@ -16076,7 +16271,7 @@ do
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
- ac_cv_path_NSGMLS="$as_dir/$ac_word$ac_exec_ext"
+ ac_cv_path_XMLLINT="$as_dir/$ac_word$ac_exec_ext"
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
fi
@@ -16087,35 +16282,35 @@ IFS=$as_save_IFS
;;
esac
fi
-NSGMLS=$ac_cv_path_NSGMLS
-if test -n "$NSGMLS"; then
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: $NSGMLS" >&5
-$as_echo "$NSGMLS" >&6; }
+XMLLINT=$ac_cv_path_XMLLINT
+if test -n "$XMLLINT"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $XMLLINT" >&5
+$as_echo "$XMLLINT" >&6; }
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi
- test -n "$NSGMLS" && break
+ test -n "$XMLLINT" && break
done
else
- # Report the value of NSGMLS in configure's output in all cases.
- { $as_echo "$as_me:${as_lineno-$LINENO}: checking for NSGMLS" >&5
-$as_echo_n "checking for NSGMLS... " >&6; }
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: $NSGMLS" >&5
-$as_echo "$NSGMLS" >&6; }
+ # Report the value of XMLLINT in configure's output in all cases.
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for XMLLINT" >&5
+$as_echo_n "checking for XMLLINT... " >&6; }
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $XMLLINT" >&5
+$as_echo "$XMLLINT" >&6; }
fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for DocBook V4.2" >&5
-$as_echo_n "checking for DocBook V4.2... " >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for DocBook XML V4.2" >&5
+$as_echo_n "checking for DocBook XML V4.2... " >&6; }
if ${pgac_cv_check_docbook+:} false; then :
$as_echo_n "(cached) " >&6
else
- cat >conftest.sgml <
+ cat >conftest.xml <test
@@ -16130,13 +16325,13 @@ EOF
pgac_cv_check_docbook=no
-if test -n "$NSGMLS"; then
- $NSGMLS -s conftest.sgml 1>&5 2>&1
+if test -n "$XMLLINT"; then
+ $XMLLINT --noout --valid conftest.xml 1>&5 2>&1
if test $? -eq 0; then
pgac_cv_check_docbook=yes
fi
fi
-rm -f conftest.sgml
+rm -f conftest.xml
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_check_docbook" >&5
$as_echo "$pgac_cv_check_docbook" >&6; }
@@ -16198,60 +16393,6 @@ $as_echo_n "checking for DBTOEPUB... " >&6; }
$as_echo "$DBTOEPUB" >&6; }
fi
-if test -z "$XMLLINT"; then
- for ac_prog in xmllint
-do
- # Extract the first word of "$ac_prog", so it can be a program name with args.
-set dummy $ac_prog; ac_word=$2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
-$as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_path_XMLLINT+:} false; then :
- $as_echo_n "(cached) " >&6
-else
- case $XMLLINT in
- [\\/]* | ?:[\\/]*)
- ac_cv_path_XMLLINT="$XMLLINT" # Let the user override the test with a path.
- ;;
- *)
- as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
- IFS=$as_save_IFS
- test -z "$as_dir" && as_dir=.
- for ac_exec_ext in '' $ac_executable_extensions; do
- if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
- ac_cv_path_XMLLINT="$as_dir/$ac_word$ac_exec_ext"
- $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
- break 2
- fi
-done
- done
-IFS=$as_save_IFS
-
- ;;
-esac
-fi
-XMLLINT=$ac_cv_path_XMLLINT
-if test -n "$XMLLINT"; then
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: $XMLLINT" >&5
-$as_echo "$XMLLINT" >&6; }
-else
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-fi
-
-
- test -n "$XMLLINT" && break
-done
-
-else
- # Report the value of XMLLINT in configure's output in all cases.
- { $as_echo "$as_me:${as_lineno-$LINENO}: checking for XMLLINT" >&5
-$as_echo_n "checking for XMLLINT... " >&6; }
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: $XMLLINT" >&5
-$as_echo "$XMLLINT" >&6; }
-fi
-
if test -z "$XSLTPROC"; then
for ac_prog in xsltproc
do
@@ -16306,60 +16447,6 @@ $as_echo_n "checking for XSLTPROC... " >&6; }
$as_echo "$XSLTPROC" >&6; }
fi
-if test -z "$OSX"; then
- for ac_prog in osx sgml2xml sx
-do
- # Extract the first word of "$ac_prog", so it can be a program name with args.
-set dummy $ac_prog; ac_word=$2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
-$as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_path_OSX+:} false; then :
- $as_echo_n "(cached) " >&6
-else
- case $OSX in
- [\\/]* | ?:[\\/]*)
- ac_cv_path_OSX="$OSX" # Let the user override the test with a path.
- ;;
- *)
- as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
- IFS=$as_save_IFS
- test -z "$as_dir" && as_dir=.
- for ac_exec_ext in '' $ac_executable_extensions; do
- if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
- ac_cv_path_OSX="$as_dir/$ac_word$ac_exec_ext"
- $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
- break 2
- fi
-done
- done
-IFS=$as_save_IFS
-
- ;;
-esac
-fi
-OSX=$ac_cv_path_OSX
-if test -n "$OSX"; then
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OSX" >&5
-$as_echo "$OSX" >&6; }
-else
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-fi
-
-
- test -n "$OSX" && break
-done
-
-else
- # Report the value of OSX in configure's output in all cases.
- { $as_echo "$as_me:${as_lineno-$LINENO}: checking for OSX" >&5
-$as_echo_n "checking for OSX... " >&6; }
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OSX" >&5
-$as_echo "$OSX" >&6; }
-fi
-
if test -z "$FOP"; then
for ac_prog in fop
do
@@ -16767,7 +16854,7 @@ _ACEOF
# awk -F is a regex on some platforms, and not on others, so make "." a tab
PG_VERSION_NUM="`echo "$PACKAGE_VERSION" | sed 's/[A-Za-z].*$//' |
tr '.' ' ' |
-$AWK '{printf "%d%02d%02d", $1, $2, (NF >= 3) ? $3 : 0}'`"
+$AWK '{printf "%d%04d", $1, $2}'`"
cat >>confdefs.h <<_ACEOF
#define PG_VERSION_NUM $PG_VERSION_NUM
diff --git a/configure.in b/configure.in
index e94fba5235..4d26034579 100644
--- a/configure.in
+++ b/configure.in
@@ -23,7 +23,7 @@ m4_if(m4_defn([m4_PACKAGE_VERSION]), [2.69], [], [m4_fatal([Autoconf version 2.6
Untested combinations of 'autoconf' and PostgreSQL versions are not
recommended. You can remove the check from 'configure.in' but it is then
your responsibility whether the result works or not.])])
-AC_COPYRIGHT([Copyright (c) 1996-2017, PostgreSQL Global Development Group])
+AC_COPYRIGHT([Copyright (c) 1996-2018, PostgreSQL Global Development Group])
AC_CONFIG_SRCDIR([src/backend/access/common/heaptuple.c])
AC_CONFIG_AUX_DIR(config)
AC_PREFIX_DEFAULT(/usr/local/pgsql)
@@ -343,37 +343,6 @@ AC_DEFINE_UNQUOTED([XLOG_BLCKSZ], ${XLOG_BLCKSZ}, [
Changing XLOG_BLCKSZ requires an initdb.
])
-#
-# WAL segment size
-#
-AC_MSG_CHECKING([for WAL segment size])
-PGAC_ARG_REQ(with, wal-segsize, [SEGSIZE], [set WAL segment size in MB [16]],
- [wal_segsize=$withval],
- [wal_segsize=16])
-case ${wal_segsize} in
- 1) ;;
- 2) ;;
- 4) ;;
- 8) ;;
- 16) ;;
- 32) ;;
- 64) ;;
- 128) ;;
- 256) ;;
- 512) ;;
- 1024) ;;
- *) AC_MSG_ERROR([Invalid WAL segment size. Allowed values are 1,2,4,8,16,32,64,128,256,512,1024.])
-esac
-AC_MSG_RESULT([${wal_segsize}MB])
-
-AC_DEFINE_UNQUOTED([XLOG_SEG_SIZE], [(${wal_segsize} * 1024 * 1024)], [
- XLOG_SEG_SIZE is the size of a single WAL file. This must be a power of 2
- and larger than XLOG_BLCKSZ (preferably, a great deal larger than
- XLOG_BLCKSZ).
-
- Changing XLOG_SEG_SIZE requires an initdb.
-])
-
#
# C compiler
#
@@ -1092,10 +1061,10 @@ if test "$with_openssl" = yes ; then
AC_CHECK_LIB(crypto, CRYPTO_new_ex_data, [], [AC_MSG_ERROR([library 'crypto' is required for OpenSSL])])
AC_CHECK_LIB(ssl, SSL_new, [], [AC_MSG_ERROR([library 'ssl' is required for OpenSSL])])
else
- AC_SEARCH_LIBS(CRYPTO_new_ex_data, eay32 crypto, [], [AC_MSG_ERROR([library 'eay32' or 'crypto' is required for OpenSSL])])
- AC_SEARCH_LIBS(SSL_new, ssleay32 ssl, [], [AC_MSG_ERROR([library 'ssleay32' or 'ssl' is required for OpenSSL])])
+ AC_SEARCH_LIBS(CRYPTO_new_ex_data, [eay32 crypto], [], [AC_MSG_ERROR([library 'eay32' or 'crypto' is required for OpenSSL])])
+ AC_SEARCH_LIBS(SSL_new, [ssleay32 ssl], [], [AC_MSG_ERROR([library 'ssleay32' or 'ssl' is required for OpenSSL])])
fi
- AC_CHECK_FUNCS([SSL_get_current_compression])
+ AC_CHECK_FUNCS([SSL_get_current_compression X509_get_signature_nid])
# Functions introduced in OpenSSL 1.1.0. We used to check for
# OPENSSL_VERSION_NUMBER, but that didn't work with 1.1.0, because LibreSSL
# defines OPENSSL_VERSION_NUMBER to claim version 2.0.0, even though it
@@ -1137,6 +1106,7 @@ if test "$with_ldap" = yes ; then
else
LDAP_LIBS_FE="-lldap $EXTRA_LDAP_LIBS"
fi
+ AC_CHECK_FUNCS([ldap_initialize])
else
AC_CHECK_LIB(wldap32, ldap_bind, [], [AC_MSG_ERROR([library 'wldap32' is required for LDAP])])
LDAP_LIBS_FE="-lwldap32"
@@ -1293,6 +1263,12 @@ fi
if test "$with_bonjour" = yes ; then
AC_CHECK_HEADER(dns_sd.h, [], [AC_MSG_ERROR([header file is required for Bonjour])])
+dnl At some point we might add something like
+dnl AC_SEARCH_LIBS(DNSServiceRegister, dns_sd)
+dnl but right now, what that would mainly accomplish is to encourage
+dnl people to try to use the avahi implementation, which does not work.
+dnl If you want to use Apple's own Bonjour code on another platform,
+dnl just add -ldns_sd to LIBS manually.
fi
# for contrib/uuid-ossp
@@ -1337,6 +1313,7 @@ PGAC_C_FUNCNAME_SUPPORT
PGAC_C_STATIC_ASSERT
PGAC_C_TYPEOF
PGAC_C_TYPES_COMPATIBLE
+PGAC_C_BUILTIN_BSWAP16
PGAC_C_BUILTIN_BSWAP32
PGAC_C_BUILTIN_BSWAP64
PGAC_C_BUILTIN_CONSTANT_P
@@ -1355,6 +1332,24 @@ AC_TYPE_LONG_LONG_INT
PGAC_TYPE_LOCALE_T
+# MSVC doesn't cope well with defining restrict to __restrict, the
+# spelling it understands, because it conflicts with
+# __declspec(restrict). Therefore we define pg_restrict to the
+# appropriate definition, which presumably won't conflict.
+#
+# Allow platforms with buggy compilers to force restrict to not be
+# used by setting $FORCE_DISABLE_RESTRICT=yes in the relevant
+# template.
+AC_C_RESTRICT
+if test "$ac_cv_c_restrict" = "no" -o "x$FORCE_DISABLE_RESTRICT" = "xyes"; then
+ pg_restrict=""
+else
+ pg_restrict="$ac_cv_c_restrict"
+fi
+AC_DEFINE_UNQUOTED([pg_restrict], [$pg_restrict],
+[Define to keyword to use for C99 restrict support, or to nothing if not
+supported])
+
AC_CHECK_TYPES([struct cmsgcred], [], [],
[#include
#include
@@ -1430,7 +1425,7 @@ PGAC_FUNC_WCSTOMBS_L
LIBS_including_readline="$LIBS"
LIBS=`echo "$LIBS" | sed -e 's/-ledit//g' -e 's/-lreadline//g'`
-AC_CHECK_FUNCS([cbrt clock_gettime dlopen fdatasync getifaddrs getpeerucred getrlimit mbstowcs_l memmove poll pstat pthread_is_threaded_np readlink setproctitle setsid shm_open symlink sync_file_range towlower utime utimes wcstombs wcstombs_l])
+AC_CHECK_FUNCS([cbrt clock_gettime dlopen fdatasync getifaddrs getpeerucred getrlimit mbstowcs_l memmove poll posix_fallocate pstat pthread_is_threaded_np readlink setproctitle setsid shm_open symlink sync_file_range utime utimes wcstombs_l])
AC_REPLACE_FUNCS(fseeko)
case $host_os in
@@ -1452,7 +1447,7 @@ AC_CHECK_DECLS(posix_fadvise, [], [], [#include ])
fi
AC_CHECK_DECLS(fdatasync, [], [], [#include ])
-AC_CHECK_DECLS([strlcat, strlcpy])
+AC_CHECK_DECLS([strlcat, strlcpy, strnlen])
# This is probably only present on macOS, but may as well check always
AC_CHECK_DECLS(F_FULLFSYNC, [], [], [#include ])
@@ -1544,7 +1539,7 @@ else
AC_CHECK_FUNCS([fpclass fp_class fp_class_d class], [break])
fi
-AC_REPLACE_FUNCS([crypt fls getopt getrusage inet_aton mkdtemp random rint srandom strerror strlcat strlcpy])
+AC_REPLACE_FUNCS([crypt fls getopt getrusage inet_aton mkdtemp random rint srandom strerror strlcat strlcpy strnlen])
case $host_os in
@@ -1735,18 +1730,6 @@ fi
AC_DEFINE_UNQUOTED(PG_INT64_TYPE, $pg_int64_type,
[Define to the name of a signed 64-bit integer type.])
-dnl If we need to use "long long int", figure out whether nnnLL notation works.
-
-if test x"$HAVE_LONG_LONG_INT_64" = xyes ; then
- AC_COMPILE_IFELSE([AC_LANG_SOURCE([
-#define INT64CONST(x) x##LL
-long long int foo = INT64CONST(0x1234567890123456);
-])],
- [AC_DEFINE(HAVE_LL_CONSTANTS, 1, [Define to 1 if constants of type 'long long int' should have the suffix LL.])],
- [])
-fi
-
-
# If we found "long int" is 64 bits, assume snprintf handles it. If
# we found we need to use "long long int", better check. We cope with
# snprintfs that use %lld, %qd, or %I64d as the format. If none of these
@@ -1788,6 +1771,10 @@ if test $pgac_need_repl_snprintf = yes; then
AC_LIBOBJ(snprintf)
fi
+# has to be down here, rather than with the other builtins, because
+# the test uses PG_INT64_TYPE.
+PGAC_C_BUILTIN_OP_OVERFLOW
+
# Check size of void *, size_t (enables tweaks for > 32bit address space)
AC_CHECK_SIZEOF([void *])
AC_CHECK_SIZEOF([size_t])
@@ -1838,7 +1825,10 @@ AC_CHECK_ALIGNOF(double)
# Compute maximum alignment of any basic type.
# We assume long's alignment is at least as strong as char, short, or int;
-# but we must check long long (if it exists) and double.
+# but we must check long long (if it is being used for int64) and double.
+# Note that we intentionally do not consider any types wider than 64 bits,
+# as allowing MAXIMUM_ALIGNOF to exceed 8 would be too much of a penalty
+# for disk and memory space.
MAX_ALIGNOF=$ac_cv_alignof_long
if test $MAX_ALIGNOF -lt $ac_cv_alignof_double ; then
@@ -1855,7 +1845,7 @@ AC_DEFINE_UNQUOTED(MAXIMUM_ALIGNOF, $MAX_ALIGNOF, [Define as the maximum alignme
AC_CHECK_TYPES([int8, uint8, int64, uint64], [], [],
[#include ])
-# Check for extensions offering the integer scalar type __int128.
+# Some compilers offer a 128-bit integer scalar type.
PGAC_TYPE_128BIT_INT
# Check for various atomic operations now that we have checked how to declare
@@ -2106,12 +2096,10 @@ fi
#
# Check for DocBook and tools
#
-PGAC_PROG_NSGMLS
+PGAC_PATH_XMLLINT
PGAC_CHECK_DOCBOOK(4.2)
PGAC_PATH_PROGS(DBTOEPUB, dbtoepub)
-PGAC_PATH_PROGS(XMLLINT, xmllint)
PGAC_PATH_PROGS(XSLTPROC, xsltproc)
-PGAC_PATH_PROGS(OSX, [osx sgml2xml sx])
PGAC_PATH_PROGS(FOP, fop)
#
@@ -2205,7 +2193,7 @@ AC_DEFINE_UNQUOTED(PG_VERSION_STR,
# awk -F is a regex on some platforms, and not on others, so make "." a tab
[PG_VERSION_NUM="`echo "$PACKAGE_VERSION" | sed 's/[A-Za-z].*$//' |
tr '.' ' ' |
-$AWK '{printf "%d%02d%02d", $1, $2, (NF >= 3) ? $3 : 0}'`"]
+$AWK '{printf "%d%04d", $1, $2}'`"]
AC_DEFINE_UNQUOTED(PG_VERSION_NUM, $PG_VERSION_NUM, [PostgreSQL version as a number])
AC_SUBST(PG_VERSION_NUM)
diff --git a/contrib/CMakeLists.txt b/contrib/CMakeLists.txt
index 71a2d77a79..d8e91d42ba 100644
--- a/contrib/CMakeLists.txt
+++ b/contrib/CMakeLists.txt
@@ -26,7 +26,6 @@ add_subdirectory(auto_explain)
add_subdirectory(btree_gin)
add_subdirectory(btree_gist)
add_subdirectory(bloom)
-add_subdirectory(chkpass)
add_subdirectory(citext)
add_subdirectory(cube)
add_subdirectory(dblink)
diff --git a/contrib/Makefile b/contrib/Makefile
index e84eb67008..8046ca4f39 100644
--- a/contrib/Makefile
+++ b/contrib/Makefile
@@ -12,7 +12,6 @@ SUBDIRS = \
bloom \
btree_gin \
btree_gist \
- chkpass \
citext \
cube \
dblink \
diff --git a/contrib/adminpack/.gitignore b/contrib/adminpack/.gitignore
new file mode 100644
index 0000000000..5dcb3ff972
--- /dev/null
+++ b/contrib/adminpack/.gitignore
@@ -0,0 +1,4 @@
+# Generated subdirectories
+/log/
+/results/
+/tmp_check/
diff --git a/contrib/adminpack/Makefile b/contrib/adminpack/Makefile
index f065f84bfb..89c249bc0d 100644
--- a/contrib/adminpack/Makefile
+++ b/contrib/adminpack/Makefile
@@ -8,6 +8,8 @@ EXTENSION = adminpack
DATA = adminpack--1.0.sql
PGFILEDESC = "adminpack - support functions for pgAdmin"
+REGRESS = adminpack
+
ifdef USE_PGXS
PG_CONFIG = pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
diff --git a/contrib/adminpack/adminpack.c b/contrib/adminpack/adminpack.c
index f3f8e7f1e4..1785dee3a1 100644
--- a/contrib/adminpack/adminpack.c
+++ b/contrib/adminpack/adminpack.c
@@ -3,7 +3,7 @@
* adminpack.c
*
*
- * Copyright (c) 2002-2017, PostgreSQL Global Development Group
+ * Copyright (c) 2002-2018, PostgreSQL Global Development Group
*
* Author: Andreas Pflug
*
@@ -319,7 +319,7 @@ pg_logdir_ls(PG_FUNCTION_ARGS)
if (!fctx->dirdesc)
ereport(ERROR,
(errcode_for_file_access(),
- errmsg("could not read directory \"%s\": %m",
+ errmsg("could not open directory \"%s\": %m",
fctx->location)));
funcctx->user_fctx = fctx;
diff --git a/contrib/adminpack/expected/adminpack.out b/contrib/adminpack/expected/adminpack.out
new file mode 100644
index 0000000000..b0d72ddab2
--- /dev/null
+++ b/contrib/adminpack/expected/adminpack.out
@@ -0,0 +1,146 @@
+CREATE EXTENSION adminpack;
+-- create new file
+SELECT pg_file_write('test_file1', 'test1', false);
+ pg_file_write
+---------------
+ 5
+(1 row)
+
+SELECT pg_read_file('test_file1');
+ pg_read_file
+--------------
+ test1
+(1 row)
+
+-- append
+SELECT pg_file_write('test_file1', 'test1', true);
+ pg_file_write
+---------------
+ 5
+(1 row)
+
+SELECT pg_read_file('test_file1');
+ pg_read_file
+--------------
+ test1test1
+(1 row)
+
+-- error, already exists
+SELECT pg_file_write('test_file1', 'test1', false);
+ERROR: file "test_file1" exists
+SELECT pg_read_file('test_file1');
+ pg_read_file
+--------------
+ test1test1
+(1 row)
+
+-- disallowed file paths
+SELECT pg_file_write('../test_file0', 'test0', false);
+ERROR: path must be in or below the current directory
+SELECT pg_file_write('/tmp/test_file0', 'test0', false);
+ERROR: absolute path not allowed
+SELECT pg_file_write(current_setting('data_directory') || '/test_file4', 'test4', false);
+ pg_file_write
+---------------
+ 5
+(1 row)
+
+SELECT pg_file_write(current_setting('data_directory') || '/../test_file4', 'test4', false);
+ERROR: reference to parent directory ("..") not allowed
+-- rename file
+SELECT pg_file_rename('test_file1', 'test_file2');
+ pg_file_rename
+----------------
+ t
+(1 row)
+
+SELECT pg_read_file('test_file1'); -- not there
+ERROR: could not stat file "test_file1": No such file or directory
+SELECT pg_read_file('test_file2');
+ pg_read_file
+--------------
+ test1test1
+(1 row)
+
+-- error
+SELECT pg_file_rename('test_file1', 'test_file2');
+WARNING: file "test_file1" is not accessible: No such file or directory
+ pg_file_rename
+----------------
+ f
+(1 row)
+
+-- rename file and archive
+SELECT pg_file_write('test_file3', 'test3', false);
+ pg_file_write
+---------------
+ 5
+(1 row)
+
+SELECT pg_file_rename('test_file2', 'test_file3', 'test_file3_archive');
+ pg_file_rename
+----------------
+ t
+(1 row)
+
+SELECT pg_read_file('test_file2'); -- not there
+ERROR: could not stat file "test_file2": No such file or directory
+SELECT pg_read_file('test_file3');
+ pg_read_file
+--------------
+ test1test1
+(1 row)
+
+SELECT pg_read_file('test_file3_archive');
+ pg_read_file
+--------------
+ test3
+(1 row)
+
+-- unlink
+SELECT pg_file_unlink('test_file1'); -- does not exist
+ pg_file_unlink
+----------------
+ f
+(1 row)
+
+SELECT pg_file_unlink('test_file2'); -- does not exist
+ pg_file_unlink
+----------------
+ f
+(1 row)
+
+SELECT pg_file_unlink('test_file3');
+ pg_file_unlink
+----------------
+ t
+(1 row)
+
+SELECT pg_file_unlink('test_file3_archive');
+ pg_file_unlink
+----------------
+ t
+(1 row)
+
+SELECT pg_file_unlink('test_file4');
+ pg_file_unlink
+----------------
+ t
+(1 row)
+
+-- superuser checks
+CREATE USER regress_user1;
+SET ROLE regress_user1;
+SELECT pg_file_write('test_file0', 'test0', false);
+ERROR: only superuser may access generic file functions
+SELECT pg_file_rename('test_file0', 'test_file0');
+ERROR: only superuser may access generic file functions
+CONTEXT: SQL function "pg_file_rename" statement 1
+SELECT pg_file_unlink('test_file0');
+ERROR: only superuser may access generic file functions
+SELECT pg_logdir_ls();
+ERROR: only superuser can list the log directory
+RESET ROLE;
+DROP USER regress_user1;
+-- no further tests for pg_logdir_ls() because it depends on the
+-- server's logging setup
diff --git a/contrib/adminpack/sql/adminpack.sql b/contrib/adminpack/sql/adminpack.sql
new file mode 100644
index 0000000000..13621bd043
--- /dev/null
+++ b/contrib/adminpack/sql/adminpack.sql
@@ -0,0 +1,60 @@
+CREATE EXTENSION adminpack;
+
+-- create new file
+SELECT pg_file_write('test_file1', 'test1', false);
+SELECT pg_read_file('test_file1');
+
+-- append
+SELECT pg_file_write('test_file1', 'test1', true);
+SELECT pg_read_file('test_file1');
+
+-- error, already exists
+SELECT pg_file_write('test_file1', 'test1', false);
+SELECT pg_read_file('test_file1');
+
+-- disallowed file paths
+SELECT pg_file_write('../test_file0', 'test0', false);
+SELECT pg_file_write('/tmp/test_file0', 'test0', false);
+SELECT pg_file_write(current_setting('data_directory') || '/test_file4', 'test4', false);
+SELECT pg_file_write(current_setting('data_directory') || '/../test_file4', 'test4', false);
+
+
+-- rename file
+SELECT pg_file_rename('test_file1', 'test_file2');
+SELECT pg_read_file('test_file1'); -- not there
+SELECT pg_read_file('test_file2');
+
+-- error
+SELECT pg_file_rename('test_file1', 'test_file2');
+
+-- rename file and archive
+SELECT pg_file_write('test_file3', 'test3', false);
+SELECT pg_file_rename('test_file2', 'test_file3', 'test_file3_archive');
+SELECT pg_read_file('test_file2'); -- not there
+SELECT pg_read_file('test_file3');
+SELECT pg_read_file('test_file3_archive');
+
+
+-- unlink
+SELECT pg_file_unlink('test_file1'); -- does not exist
+SELECT pg_file_unlink('test_file2'); -- does not exist
+SELECT pg_file_unlink('test_file3');
+SELECT pg_file_unlink('test_file3_archive');
+SELECT pg_file_unlink('test_file4');
+
+
+-- superuser checks
+CREATE USER regress_user1;
+SET ROLE regress_user1;
+
+SELECT pg_file_write('test_file0', 'test0', false);
+SELECT pg_file_rename('test_file0', 'test_file0');
+SELECT pg_file_unlink('test_file0');
+SELECT pg_logdir_ls();
+
+RESET ROLE;
+DROP USER regress_user1;
+
+
+-- no further tests for pg_logdir_ls() because it depends on the
+-- server's logging setup
diff --git a/contrib/amcheck/verify_nbtree.c b/contrib/amcheck/verify_nbtree.c
index 9ae83dc839..da518daea3 100644
--- a/contrib/amcheck/verify_nbtree.c
+++ b/contrib/amcheck/verify_nbtree.c
@@ -9,7 +9,7 @@
* verification).
*
*
- * Copyright (c) 2017, PostgreSQL Global Development Group
+ * Copyright (c) 2017-2018, PostgreSQL Global Development Group
*
* IDENTIFICATION
* contrib/amcheck/verify_nbtree.c
@@ -295,9 +295,7 @@ bt_check_every_level(Relation rel, bool readonly)
/* Create context for page */
state->targetcontext = AllocSetContextCreate(CurrentMemoryContext,
"amcheck context",
- ALLOCSET_DEFAULT_MINSIZE,
- ALLOCSET_DEFAULT_INITSIZE,
- ALLOCSET_DEFAULT_MAXSIZE);
+ ALLOCSET_DEFAULT_SIZES);
state->checkstrategy = GetAccessStrategy(BAS_BULKREAD);
/* Get true root block from meta-page */
@@ -1195,7 +1193,7 @@ palloc_btree_page(BtreeCheckState *state, BlockNumber blocknum)
opaque = (BTPageOpaque) PageGetSpecialPointer(page);
- if (opaque->btpo_flags & BTP_META && blocknum != BTREE_METAPAGE)
+ if (P_ISMETA(opaque) && blocknum != BTREE_METAPAGE)
ereport(ERROR,
(errcode(ERRCODE_INDEX_CORRUPTED),
errmsg("invalid meta page found at block %u in index \"%s\"",
@@ -1206,7 +1204,7 @@ palloc_btree_page(BtreeCheckState *state, BlockNumber blocknum)
{
BTMetaPageData *metad = BTPageGetMeta(page);
- if (!(opaque->btpo_flags & BTP_META) ||
+ if (!P_ISMETA(opaque) ||
metad->btm_magic != BTREE_MAGIC)
ereport(ERROR,
(errcode(ERRCODE_INDEX_CORRUPTED),
diff --git a/contrib/auth_delay/auth_delay.c b/contrib/auth_delay/auth_delay.c
index cd12a86b99..ad047b365f 100644
--- a/contrib/auth_delay/auth_delay.c
+++ b/contrib/auth_delay/auth_delay.c
@@ -2,7 +2,7 @@
*
* auth_delay.c
*
- * Copyright (c) 2010-2017, PostgreSQL Global Development Group
+ * Copyright (c) 2010-2018, PostgreSQL Global Development Group
*
* IDENTIFICATION
* contrib/auth_delay/auth_delay.c
diff --git a/contrib/auto_explain/auto_explain.c b/contrib/auto_explain/auto_explain.c
index edcb91542a..ea4f957cfa 100644
--- a/contrib/auto_explain/auto_explain.c
+++ b/contrib/auto_explain/auto_explain.c
@@ -3,7 +3,7 @@
* auto_explain.c
*
*
- * Copyright (c) 2008-2017, PostgreSQL Global Development Group
+ * Copyright (c) 2008-2018, PostgreSQL Global Development Group
*
* IDENTIFICATION
* contrib/auto_explain/auto_explain.c
@@ -78,7 +78,7 @@ _PG_init(void)
"Zero prints all plans. -1 turns this feature off.",
&auto_explain_log_min_duration,
-1,
- -1, INT_MAX / 1000,
+ -1, INT_MAX,
PGC_SUSET,
GUC_UNIT_MS,
NULL,
diff --git a/contrib/bloom/blcost.c b/contrib/bloom/blcost.c
index ba39f627fd..fa0f17a217 100644
--- a/contrib/bloom/blcost.c
+++ b/contrib/bloom/blcost.c
@@ -3,7 +3,7 @@
* blcost.c
* Cost estimate function for bloom indexes.
*
- * Copyright (c) 2016-2017, PostgreSQL Global Development Group
+ * Copyright (c) 2016-2018, PostgreSQL Global Development Group
*
* IDENTIFICATION
* contrib/bloom/blcost.c
diff --git a/contrib/bloom/blinsert.c b/contrib/bloom/blinsert.c
index 0d506e3c1a..d231e5331f 100644
--- a/contrib/bloom/blinsert.c
+++ b/contrib/bloom/blinsert.c
@@ -3,7 +3,7 @@
* blinsert.c
* Bloom index build and insert functions.
*
- * Copyright (c) 2016-2017, PostgreSQL Global Development Group
+ * Copyright (c) 2016-2018, PostgreSQL Global Development Group
*
* IDENTIFICATION
* contrib/bloom/blinsert.c
@@ -135,7 +135,8 @@ blbuild(Relation heap, Relation index, IndexInfo *indexInfo)
/* Do the heap scan */
reltuples = IndexBuildHeapScan(heap, index, indexInfo, true,
- bloomBuildCallback, (void *) &buildstate);
+ bloomBuildCallback, (void *) &buildstate,
+ NULL);
/*
* There are could be some items in cached page. Flush this page if
@@ -175,7 +176,7 @@ blbuildempty(Relation index)
smgrwrite(index->rd_smgr, INIT_FORKNUM, BLOOM_METAPAGE_BLKNO,
(char *) metapage, true);
log_newpage(&index->rd_smgr->smgr_rnode.node, INIT_FORKNUM,
- BLOOM_METAPAGE_BLKNO, metapage, false);
+ BLOOM_METAPAGE_BLKNO, metapage, true);
/*
* An immediate sync is required even if we xlog'd the page, because the
diff --git a/contrib/bloom/bloom.h b/contrib/bloom/bloom.h
index f3df1af781..3973ac75e8 100644
--- a/contrib/bloom/bloom.h
+++ b/contrib/bloom/bloom.h
@@ -3,7 +3,7 @@
* bloom.h
* Header for bloom index.
*
- * Copyright (c) 2016-2017, PostgreSQL Global Development Group
+ * Copyright (c) 2016-2018, PostgreSQL Global Development Group
*
* IDENTIFICATION
* contrib/bloom/bloom.h
diff --git a/contrib/bloom/blscan.c b/contrib/bloom/blscan.c
index b8fa2d0a71..0744d74de7 100644
--- a/contrib/bloom/blscan.c
+++ b/contrib/bloom/blscan.c
@@ -3,7 +3,7 @@
* blscan.c
* Bloom index scan functions.
*
- * Copyright (c) 2016-2017, PostgreSQL Global Development Group
+ * Copyright (c) 2016-2018, PostgreSQL Global Development Group
*
* IDENTIFICATION
* contrib/bloom/blscan.c
diff --git a/contrib/bloom/blutils.c b/contrib/bloom/blutils.c
index f2eda67e0a..bbe7183207 100644
--- a/contrib/bloom/blutils.c
+++ b/contrib/bloom/blutils.c
@@ -3,7 +3,7 @@
* blutils.c
* Bloom index utilities.
*
- * Portions Copyright (c) 2016-2017, PostgreSQL Global Development Group
+ * Portions Copyright (c) 2016-2018, PostgreSQL Global Development Group
* Portions Copyright (c) 1990-1993, Regents of the University of California
*
* IDENTIFICATION
diff --git a/contrib/bloom/blvacuum.c b/contrib/bloom/blvacuum.c
index 2e060871b6..7530a664ab 100644
--- a/contrib/bloom/blvacuum.c
+++ b/contrib/bloom/blvacuum.c
@@ -3,7 +3,7 @@
* blvacuum.c
* Bloom VACUUM functions.
*
- * Copyright (c) 2016-2017, PostgreSQL Global Development Group
+ * Copyright (c) 2016-2018, PostgreSQL Global Development Group
*
* IDENTIFICATION
* contrib/bloom/blvacuum.c
@@ -125,7 +125,7 @@ blbulkdelete(IndexVacuumInfo *info, IndexBulkDeleteResult *stats,
/* Is it empty page now? */
if (BloomPageGetMaxOffset(page) == 0)
BloomPageSetDeleted(page);
- /* Adjust pg_lower */
+ /* Adjust pd_lower */
((PageHeader) page)->pd_lower = (Pointer) itupPtr - page;
/* Finish WAL-logging */
GenericXLogFinish(gxlogState);
diff --git a/contrib/bloom/blvalidate.c b/contrib/bloom/blvalidate.c
index cb75d23199..7235f12307 100644
--- a/contrib/bloom/blvalidate.c
+++ b/contrib/bloom/blvalidate.c
@@ -3,7 +3,7 @@
* blvalidate.c
* Opclass validator for bloom.
*
- * Copyright (c) 2016-2017, PostgreSQL Global Development Group
+ * Copyright (c) 2016-2018, PostgreSQL Global Development Group
*
* IDENTIFICATION
* contrib/bloom/blvalidate.c
diff --git a/contrib/bloom/expected/bloom.out b/contrib/bloom/expected/bloom.out
index cbc50f757b..5ab9e34f82 100644
--- a/contrib/bloom/expected/bloom.out
+++ b/contrib/bloom/expected/bloom.out
@@ -210,3 +210,20 @@ ORDER BY 1;
text_ops | t
(2 rows)
+--
+-- relation options
+--
+DROP INDEX bloomidx;
+CREATE INDEX bloomidx ON tst USING bloom (i, t) WITH (length=7, col1=4);
+SELECT reloptions FROM pg_class WHERE oid = 'bloomidx'::regclass;
+ reloptions
+-------------------
+ {length=7,col1=4}
+(1 row)
+
+-- check for min and max values
+\set VERBOSITY terse
+CREATE INDEX bloomidx2 ON tst USING bloom (i, t) WITH (length=0);
+ERROR: value 0 out of bounds for option "length"
+CREATE INDEX bloomidx2 ON tst USING bloom (i, t) WITH (col1=0);
+ERROR: value 0 out of bounds for option "col1"
diff --git a/contrib/bloom/sql/bloom.sql b/contrib/bloom/sql/bloom.sql
index 22274609f2..32755f2b1a 100644
--- a/contrib/bloom/sql/bloom.sql
+++ b/contrib/bloom/sql/bloom.sql
@@ -81,3 +81,14 @@ SELECT opcname, amvalidate(opc.oid)
FROM pg_opclass opc JOIN pg_am am ON am.oid = opcmethod
WHERE amname = 'bloom'
ORDER BY 1;
+
+--
+-- relation options
+--
+DROP INDEX bloomidx;
+CREATE INDEX bloomidx ON tst USING bloom (i, t) WITH (length=7, col1=4);
+SELECT reloptions FROM pg_class WHERE oid = 'bloomidx'::regclass;
+-- check for min and max values
+\set VERBOSITY terse
+CREATE INDEX bloomidx2 ON tst USING bloom (i, t) WITH (length=0);
+CREATE INDEX bloomidx2 ON tst USING bloom (i, t) WITH (col1=0);
diff --git a/contrib/bloom/t/001_wal.pl b/contrib/bloom/t/001_wal.pl
index dbba198254..1b319c993c 100644
--- a/contrib/bloom/t/001_wal.pl
+++ b/contrib/bloom/t/001_wal.pl
@@ -32,8 +32,8 @@ sub test_index_replay
);
# Run test queries and compare their result
- my $master_result = $node_master->psql("postgres", $queries);
- my $standby_result = $node_standby->psql("postgres", $queries);
+ my $master_result = $node_master->safe_psql("postgres", $queries);
+ my $standby_result = $node_standby->safe_psql("postgres", $queries);
is($master_result, $standby_result, "$test_name: query result matches");
}
@@ -54,12 +54,12 @@ sub test_index_replay
$node_standby->start;
# Create some bloom index on master
-$node_master->psql("postgres", "CREATE EXTENSION bloom;");
-$node_master->psql("postgres", "CREATE TABLE tst (i int4, t text);");
-$node_master->psql("postgres",
+$node_master->safe_psql("postgres", "CREATE EXTENSION bloom;");
+$node_master->safe_psql("postgres", "CREATE TABLE tst (i int4, t text);");
+$node_master->safe_psql("postgres",
"INSERT INTO tst SELECT i%10, substr(md5(i::text), 1, 1) FROM generate_series(1,100000) i;"
);
-$node_master->psql("postgres",
+$node_master->safe_psql("postgres",
"CREATE INDEX bloomidx ON tst USING bloom (i, t) WITH (col1 = 3);");
# Test that queries give same result
@@ -68,12 +68,12 @@ sub test_index_replay
# Run 10 cycles of table modification. Run test queries after each modification.
for my $i (1 .. 10)
{
- $node_master->psql("postgres", "DELETE FROM tst WHERE i = $i;");
+ $node_master->safe_psql("postgres", "DELETE FROM tst WHERE i = $i;");
test_index_replay("delete $i");
- $node_master->psql("postgres", "VACUUM tst;");
+ $node_master->safe_psql("postgres", "VACUUM tst;");
test_index_replay("vacuum $i");
my ($start, $end) = (100001 + ($i - 1) * 10000, 100000 + $i * 10000);
- $node_master->psql("postgres",
+ $node_master->safe_psql("postgres",
"INSERT INTO tst SELECT i%10, substr(md5(i::text), 1, 1) FROM generate_series($start,$end) i;"
);
test_index_replay("insert $i");
diff --git a/contrib/btree_gist/btree_bit.c b/contrib/btree_gist/btree_bit.c
index a56a2752a7..2225244ded 100644
--- a/contrib/btree_gist/btree_bit.c
+++ b/contrib/btree_gist/btree_bit.c
@@ -111,7 +111,7 @@ static const gbtree_vinfo tinfo =
{
gbt_t_bit,
0,
- TRUE,
+ true,
gbt_bitgt,
gbt_bitge,
gbt_biteq,
@@ -152,13 +152,13 @@ gbt_bit_consistent(PG_FUNCTION_ARGS)
if (GIST_LEAF(entry))
retval = gbt_var_consistent(&r, query, strategy, PG_GET_COLLATION(),
- TRUE, &tinfo, fcinfo->flinfo);
+ true, &tinfo, fcinfo->flinfo);
else
{
bytea *q = gbt_bit_xfrm((bytea *) query);
retval = gbt_var_consistent(&r, q, strategy, PG_GET_COLLATION(),
- FALSE, &tinfo, fcinfo->flinfo);
+ false, &tinfo, fcinfo->flinfo);
}
PG_RETURN_BOOL(retval);
}
diff --git a/contrib/btree_gist/btree_bytea.c b/contrib/btree_gist/btree_bytea.c
index 00753e7f48..6b005f0157 100644
--- a/contrib/btree_gist/btree_bytea.c
+++ b/contrib/btree_gist/btree_bytea.c
@@ -75,7 +75,7 @@ static const gbtree_vinfo tinfo =
{
gbt_t_bytea,
0,
- TRUE,
+ true,
gbt_byteagt,
gbt_byteage,
gbt_byteaeq,
diff --git a/contrib/btree_gist/btree_cash.c b/contrib/btree_gist/btree_cash.c
index 81131af4dc..894d0a2665 100644
--- a/contrib/btree_gist/btree_cash.c
+++ b/contrib/btree_gist/btree_cash.c
@@ -5,6 +5,7 @@
#include "btree_gist.h"
#include "btree_utils_num.h"
+#include "common/int.h"
#include "utils/cash.h"
typedef struct
@@ -99,15 +100,14 @@ cash_dist(PG_FUNCTION_ARGS)
Cash r;
Cash ra;
- r = a - b;
- ra = Abs(r);
-
- /* Overflow check. */
- if (ra < 0 || (!SAMESIGN(a, b) && !SAMESIGN(r, a)))
+ if (pg_sub_s64_overflow(a, b, &r) ||
+ r == PG_INT64_MIN)
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("money out of range")));
+ ra = Abs(r);
+
PG_RETURN_CASH(ra);
}
diff --git a/contrib/btree_gist/btree_inet.c b/contrib/btree_gist/btree_inet.c
index b5b593f77f..86c27ca955 100644
--- a/contrib/btree_gist/btree_inet.c
+++ b/contrib/btree_gist/btree_inet.c
@@ -105,7 +105,7 @@ gbt_inet_compress(PG_FUNCTION_ARGS)
r->upper = r->lower;
gistentryinit(*retval, PointerGetDatum(r),
entry->rel, entry->page,
- entry->offset, FALSE);
+ entry->offset, false);
}
else
retval = entry;
diff --git a/contrib/btree_gist/btree_int2.c b/contrib/btree_gist/btree_int2.c
index f343b8615f..7674e2d292 100644
--- a/contrib/btree_gist/btree_int2.c
+++ b/contrib/btree_gist/btree_int2.c
@@ -5,6 +5,7 @@
#include "btree_gist.h"
#include "btree_utils_num.h"
+#include "common/int.h"
typedef struct int16key
{
@@ -98,15 +99,14 @@ int2_dist(PG_FUNCTION_ARGS)
int16 r;
int16 ra;
- r = a - b;
- ra = Abs(r);
-
- /* Overflow check. */
- if (ra < 0 || (!SAMESIGN(a, b) && !SAMESIGN(r, a)))
+ if (pg_sub_s16_overflow(a, b, &r) ||
+ r == PG_INT16_MIN)
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("smallint out of range")));
+ ra = Abs(r);
+
PG_RETURN_INT16(ra);
}
diff --git a/contrib/btree_gist/btree_int4.c b/contrib/btree_gist/btree_int4.c
index 35bb442437..80005ab65d 100644
--- a/contrib/btree_gist/btree_int4.c
+++ b/contrib/btree_gist/btree_int4.c
@@ -5,6 +5,7 @@
#include "btree_gist.h"
#include "btree_utils_num.h"
+#include "common/int.h"
typedef struct int32key
{
@@ -99,15 +100,14 @@ int4_dist(PG_FUNCTION_ARGS)
int32 r;
int32 ra;
- r = a - b;
- ra = Abs(r);
-
- /* Overflow check. */
- if (ra < 0 || (!SAMESIGN(a, b) && !SAMESIGN(r, a)))
+ if (pg_sub_s32_overflow(a, b, &r) ||
+ r == PG_INT32_MIN)
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range")));
+ ra = Abs(r);
+
PG_RETURN_INT32(ra);
}
diff --git a/contrib/btree_gist/btree_int8.c b/contrib/btree_gist/btree_int8.c
index 91f2d032d1..b0fd3e1277 100644
--- a/contrib/btree_gist/btree_int8.c
+++ b/contrib/btree_gist/btree_int8.c
@@ -5,6 +5,7 @@
#include "btree_gist.h"
#include "btree_utils_num.h"
+#include "common/int.h"
typedef struct int64key
{
@@ -99,15 +100,14 @@ int8_dist(PG_FUNCTION_ARGS)
int64 r;
int64 ra;
- r = a - b;
- ra = Abs(r);
-
- /* Overflow check. */
- if (ra < 0 || (!SAMESIGN(a, b) && !SAMESIGN(r, a)))
+ if (pg_sub_s64_overflow(a, b, &r) ||
+ r == PG_INT64_MIN)
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("bigint out of range")));
+ ra = Abs(r);
+
PG_RETURN_INT64(ra);
}
diff --git a/contrib/btree_gist/btree_interval.c b/contrib/btree_gist/btree_interval.c
index 61ab478c42..3a527a75fa 100644
--- a/contrib/btree_gist/btree_interval.c
+++ b/contrib/btree_gist/btree_interval.c
@@ -169,7 +169,7 @@ gbt_intv_compress(PG_FUNCTION_ARGS)
}
gistentryinit(*retval, PointerGetDatum(r),
entry->rel, entry->page,
- entry->offset, FALSE);
+ entry->offset, false);
}
PG_RETURN_POINTER(retval);
@@ -201,7 +201,7 @@ gbt_intv_decompress(PG_FUNCTION_ARGS)
gistentryinit(*retval, PointerGetDatum(r),
entry->rel, entry->page,
- entry->offset, FALSE);
+ entry->offset, false);
}
PG_RETURN_POINTER(retval);
}
diff --git a/contrib/btree_gist/btree_numeric.c b/contrib/btree_gist/btree_numeric.c
index 43793d36a2..b72060cdb6 100644
--- a/contrib/btree_gist/btree_numeric.c
+++ b/contrib/btree_gist/btree_numeric.c
@@ -79,7 +79,7 @@ static const gbtree_vinfo tinfo =
{
gbt_t_numeric,
0,
- FALSE,
+ false,
gbt_numeric_gt,
gbt_numeric_ge,
gbt_numeric_eq,
diff --git a/contrib/btree_gist/btree_text.c b/contrib/btree_gist/btree_text.c
index 090c849470..8019d11281 100644
--- a/contrib/btree_gist/btree_text.c
+++ b/contrib/btree_gist/btree_text.c
@@ -80,7 +80,7 @@ static gbtree_vinfo tinfo =
{
gbt_t_text,
0,
- FALSE,
+ false,
gbt_textgt,
gbt_textge,
gbt_texteq,
@@ -128,7 +128,7 @@ gbt_bpchar_compress(PG_FUNCTION_ARGS)
gistentryinit(trim, d,
entry->rel, entry->page,
- entry->offset, TRUE);
+ entry->offset, true);
retval = gbt_var_compress(&trim, &tinfo);
}
else
@@ -171,7 +171,7 @@ Datum
gbt_bpchar_consistent(PG_FUNCTION_ARGS)
{
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- void *query = (void *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(1)));
+ void *query = (void *) DatumGetTextP(PG_GETARG_DATUM(1));
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
/* Oid subtype = PG_GETARG_OID(3); */
diff --git a/contrib/btree_gist/btree_time.c b/contrib/btree_gist/btree_time.c
index bb239d4986..90cf6554ea 100644
--- a/contrib/btree_gist/btree_time.c
+++ b/contrib/btree_gist/btree_time.c
@@ -183,7 +183,7 @@ gbt_timetz_compress(PG_FUNCTION_ARGS)
r->lower = r->upper = tmp;
gistentryinit(*retval, PointerGetDatum(r),
entry->rel, entry->page,
- entry->offset, FALSE);
+ entry->offset, false);
}
else
retval = entry;
diff --git a/contrib/btree_gist/btree_ts.c b/contrib/btree_gist/btree_ts.c
index 1582cff102..18740cad38 100644
--- a/contrib/btree_gist/btree_ts.c
+++ b/contrib/btree_gist/btree_ts.c
@@ -230,7 +230,7 @@ gbt_tstz_compress(PG_FUNCTION_ARGS)
r->lower = r->upper = gmt;
gistentryinit(*retval, PointerGetDatum(r),
entry->rel, entry->page,
- entry->offset, FALSE);
+ entry->offset, false);
}
else
retval = entry;
diff --git a/contrib/btree_gist/btree_utils_num.c b/contrib/btree_gist/btree_utils_num.c
index bae32c4064..29b0faf997 100644
--- a/contrib/btree_gist/btree_utils_num.c
+++ b/contrib/btree_gist/btree_utils_num.c
@@ -86,7 +86,7 @@ gbt_num_compress(GISTENTRY *entry, const gbtree_ninfo *tinfo)
memcpy((void *) &r[tinfo->size], leaf, tinfo->size);
retval = palloc(sizeof(GISTENTRY));
gistentryinit(*retval, PointerGetDatum(r), entry->rel, entry->page,
- entry->offset, FALSE);
+ entry->offset, false);
}
else
retval = entry;
@@ -150,7 +150,7 @@ gbt_num_fetch(GISTENTRY *entry, const gbtree_ninfo *tinfo)
retval = palloc(sizeof(GISTENTRY));
gistentryinit(*retval, datum, entry->rel, entry->page, entry->offset,
- FALSE);
+ false);
return retval;
}
@@ -184,10 +184,10 @@ gbt_num_union(GBT_NUMKEY *out, const GistEntryVector *entryvec, const gbtree_nin
c.lower = &cur[0];
c.upper = &cur[tinfo->size];
/* if out->lower > cur->lower, adopt cur as lower */
- if ((*tinfo->f_gt) (o.lower, c.lower, flinfo))
+ if (tinfo->f_gt(o.lower, c.lower, flinfo))
memcpy((void *) o.lower, (void *) c.lower, tinfo->size);
/* if out->upper < cur->upper, adopt cur as upper */
- if ((*tinfo->f_lt) (o.upper, c.upper, flinfo))
+ if (tinfo->f_lt(o.upper, c.upper, flinfo))
memcpy((void *) o.upper, (void *) c.upper, tinfo->size);
}
@@ -211,8 +211,8 @@ gbt_num_same(const GBT_NUMKEY *a, const GBT_NUMKEY *b, const gbtree_ninfo *tinfo
b2.lower = &(((GBT_NUMKEY *) b)[0]);
b2.upper = &(((GBT_NUMKEY *) b)[tinfo->size]);
- return ((*tinfo->f_eq) (b1.lower, b2.lower, flinfo) &&
- (*tinfo->f_eq) (b1.upper, b2.upper, flinfo));
+ return (tinfo->f_eq(b1.lower, b2.lower, flinfo) &&
+ tinfo->f_eq(b1.upper, b2.upper, flinfo));
}
@@ -236,9 +236,9 @@ gbt_num_bin_union(Datum *u, GBT_NUMKEY *e, const gbtree_ninfo *tinfo, FmgrInfo *
ur.lower = &(((GBT_NUMKEY *) DatumGetPointer(*u))[0]);
ur.upper = &(((GBT_NUMKEY *) DatumGetPointer(*u))[tinfo->size]);
- if ((*tinfo->f_gt) ((void *) ur.lower, (void *) rd.lower, flinfo))
+ if (tinfo->f_gt((void *) ur.lower, (void *) rd.lower, flinfo))
memcpy((void *) ur.lower, (void *) rd.lower, tinfo->size);
- if ((*tinfo->f_lt) ((void *) ur.upper, (void *) rd.upper, flinfo))
+ if (tinfo->f_lt((void *) ur.upper, (void *) rd.upper, flinfo))
memcpy((void *) ur.upper, (void *) rd.upper, tinfo->size);
}
}
@@ -264,39 +264,39 @@ gbt_num_consistent(const GBT_NUMKEY_R *key,
switch (*strategy)
{
case BTLessEqualStrategyNumber:
- retval = (*tinfo->f_ge) (query, key->lower, flinfo);
+ retval = tinfo->f_ge(query, key->lower, flinfo);
break;
case BTLessStrategyNumber:
if (is_leaf)
- retval = (*tinfo->f_gt) (query, key->lower, flinfo);
+ retval = tinfo->f_gt(query, key->lower, flinfo);
else
- retval = (*tinfo->f_ge) (query, key->lower, flinfo);
+ retval = tinfo->f_ge(query, key->lower, flinfo);
break;
case BTEqualStrategyNumber:
if (is_leaf)
- retval = (*tinfo->f_eq) (query, key->lower, flinfo);
+ retval = tinfo->f_eq(query, key->lower, flinfo);
else
- retval = ((*tinfo->f_le) (key->lower, query, flinfo) &&
- (*tinfo->f_le) (query, key->upper, flinfo));
+ retval = (tinfo->f_le(key->lower, query, flinfo) &&
+ tinfo->f_le(query, key->upper, flinfo));
break;
case BTGreaterStrategyNumber:
if (is_leaf)
- retval = (*tinfo->f_lt) (query, key->upper, flinfo);
+ retval = tinfo->f_lt(query, key->upper, flinfo);
else
- retval = (*tinfo->f_le) (query, key->upper, flinfo);
+ retval = tinfo->f_le(query, key->upper, flinfo);
break;
case BTGreaterEqualStrategyNumber:
- retval = (*tinfo->f_le) (query, key->upper, flinfo);
+ retval = tinfo->f_le(query, key->upper, flinfo);
break;
case BtreeGistNotEqualStrategyNumber:
- retval = (!((*tinfo->f_eq) (query, key->lower, flinfo) &&
- (*tinfo->f_eq) (query, key->upper, flinfo)));
+ retval = (!(tinfo->f_eq(query, key->lower, flinfo) &&
+ tinfo->f_eq(query, key->upper, flinfo)));
break;
default:
retval = false;
}
- return (retval);
+ return retval;
}
diff --git a/contrib/btree_gist/btree_utils_num.h b/contrib/btree_gist/btree_utils_num.h
index 17561fa9e4..d7945f856c 100644
--- a/contrib/btree_gist/btree_utils_num.h
+++ b/contrib/btree_gist/btree_utils_num.h
@@ -89,8 +89,6 @@ typedef struct
#define GET_FLOAT_DISTANCE(t, arg1, arg2) Abs( ((float8) *((const t *) (arg1))) - ((float8) *((const t *) (arg2))) )
-#define SAMESIGN(a,b) (((a) < 0) == ((b) < 0))
-
/*
* check to see if a float4/8 val has underflowed or overflowed
* borrowed from src/backend/utils/adt/float.c
diff --git a/contrib/btree_gist/btree_utils_var.c b/contrib/btree_gist/btree_utils_var.c
index 2c636ad2fa..670c879e77 100644
--- a/contrib/btree_gist/btree_utils_var.c
+++ b/contrib/btree_gist/btree_utils_var.c
@@ -37,7 +37,7 @@ Datum
gbt_var_decompress(PG_FUNCTION_ARGS)
{
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(PG_DETOAST_DATUM(entry->key));
+ GBT_VARKEY *key = (GBT_VARKEY *) PG_DETOAST_DATUM(entry->key);
if (key != (GBT_VARKEY *) DatumGetPointer(entry->key))
{
@@ -45,7 +45,7 @@ gbt_var_decompress(PG_FUNCTION_ARGS)
gistentryinit(*retval, PointerGetDatum(key),
entry->rel, entry->page,
- entry->offset, FALSE);
+ entry->offset, false);
PG_RETURN_POINTER(retval);
}
@@ -109,7 +109,7 @@ gbt_var_leaf2node(GBT_VARKEY *leaf, const gbtree_vinfo *tinfo, FmgrInfo *flinfo)
GBT_VARKEY *out = leaf;
if (tinfo->f_l2n)
- out = (*tinfo->f_l2n) (leaf, flinfo);
+ out = tinfo->f_l2n(leaf, flinfo);
return out;
}
@@ -159,7 +159,7 @@ gbt_var_node_cp_len(const GBT_VARKEY *node, const gbtree_vinfo *tinfo)
l--;
i++;
}
- return (ml); /* lower == upper */
+ return ml; /* lower == upper */
}
@@ -169,7 +169,7 @@ gbt_var_node_cp_len(const GBT_VARKEY *node, const gbtree_vinfo *tinfo)
static bool
gbt_bytea_pf_match(const bytea *pf, const bytea *query, const gbtree_vinfo *tinfo)
{
- bool out = FALSE;
+ bool out = false;
int32 qlen = VARSIZE(query) - VARHDRSZ;
int32 nlen = VARSIZE(pf) - VARHDRSZ;
@@ -255,13 +255,13 @@ gbt_var_bin_union(Datum *u, GBT_VARKEY *e, Oid collation,
nr.lower = ro.lower;
nr.upper = ro.upper;
- if ((*tinfo->f_cmp) (ro.lower, eo.lower, collation, flinfo) > 0)
+ if (tinfo->f_cmp(ro.lower, eo.lower, collation, flinfo) > 0)
{
nr.lower = eo.lower;
update = true;
}
- if ((*tinfo->f_cmp) (ro.upper, eo.upper, collation, flinfo) < 0)
+ if (tinfo->f_cmp(ro.upper, eo.upper, collation, flinfo) < 0)
{
nr.upper = eo.upper;
update = true;
@@ -294,12 +294,12 @@ gbt_var_compress(GISTENTRY *entry, const gbtree_vinfo *tinfo)
retval = palloc(sizeof(GISTENTRY));
gistentryinit(*retval, PointerGetDatum(r),
entry->rel, entry->page,
- entry->offset, TRUE);
+ entry->offset, true);
}
else
retval = entry;
- return (retval);
+ return retval;
}
@@ -307,14 +307,14 @@ Datum
gbt_var_fetch(PG_FUNCTION_ARGS)
{
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(PG_DETOAST_DATUM(entry->key));
+ GBT_VARKEY *key = (GBT_VARKEY *) PG_DETOAST_DATUM(entry->key);
GBT_VARKEY_R r = gbt_var_key_readable(key);
GISTENTRY *retval;
retval = palloc(sizeof(GISTENTRY));
gistentryinit(*retval, PointerGetDatum(r.lower),
entry->rel, entry->page,
- entry->offset, TRUE);
+ entry->offset, true);
PG_RETURN_POINTER(retval);
}
@@ -371,8 +371,8 @@ gbt_var_same(Datum d1, Datum d2, Oid collation,
r1 = gbt_var_key_readable(t1);
r2 = gbt_var_key_readable(t2);
- return ((*tinfo->f_cmp) (r1.lower, r2.lower, collation, flinfo) == 0 &&
- (*tinfo->f_cmp) (r1.upper, r2.upper, collation, flinfo) == 0);
+ return (tinfo->f_cmp(r1.lower, r2.lower, collation, flinfo) == 0 &&
+ tinfo->f_cmp(r1.upper, r2.upper, collation, flinfo) == 0);
}
@@ -400,9 +400,9 @@ gbt_var_penalty(float *res, const GISTENTRY *o, const GISTENTRY *n,
if ((VARSIZE(ok.lower) - VARHDRSZ) == 0 && (VARSIZE(ok.upper) - VARHDRSZ) == 0)
*res = 0.0;
- else if (!(((*tinfo->f_cmp) (nk.lower, ok.lower, collation, flinfo) >= 0 ||
+ else if (!((tinfo->f_cmp(nk.lower, ok.lower, collation, flinfo) >= 0 ||
gbt_bytea_pf_match(ok.lower, nk.lower, tinfo)) &&
- ((*tinfo->f_cmp) (nk.upper, ok.upper, collation, flinfo) <= 0 ||
+ (tinfo->f_cmp(nk.upper, ok.upper, collation, flinfo) <= 0 ||
gbt_bytea_pf_match(ok.upper, nk.upper, tinfo))))
{
Datum d = PointerGetDatum(0);
@@ -449,9 +449,9 @@ gbt_vsrt_cmp(const void *a, const void *b, void *arg)
const gbt_vsrt_arg *varg = (const gbt_vsrt_arg *) arg;
int res;
- res = (*varg->tinfo->f_cmp) (ar.lower, br.lower, varg->collation, varg->flinfo);
+ res = varg->tinfo->f_cmp(ar.lower, br.lower, varg->collation, varg->flinfo);
if (res == 0)
- return (*varg->tinfo->f_cmp) (ar.upper, br.upper, varg->collation, varg->flinfo);
+ return varg->tinfo->f_cmp(ar.upper, br.upper, varg->collation, varg->flinfo);
return res;
}
@@ -561,53 +561,53 @@ gbt_var_consistent(GBT_VARKEY_R *key,
const gbtree_vinfo *tinfo,
FmgrInfo *flinfo)
{
- bool retval = FALSE;
+ bool retval = false;
switch (strategy)
{
case BTLessEqualStrategyNumber:
if (is_leaf)
- retval = (*tinfo->f_ge) (query, key->lower, collation, flinfo);
+ retval = tinfo->f_ge(query, key->lower, collation, flinfo);
else
- retval = (*tinfo->f_cmp) (query, key->lower, collation, flinfo) >= 0
+ retval = tinfo->f_cmp(query, key->lower, collation, flinfo) >= 0
|| gbt_var_node_pf_match(key, query, tinfo);
break;
case BTLessStrategyNumber:
if (is_leaf)
- retval = (*tinfo->f_gt) (query, key->lower, collation, flinfo);
+ retval = tinfo->f_gt(query, key->lower, collation, flinfo);
else
- retval = (*tinfo->f_cmp) (query, key->lower, collation, flinfo) >= 0
+ retval = tinfo->f_cmp(query, key->lower, collation, flinfo) >= 0
|| gbt_var_node_pf_match(key, query, tinfo);
break;
case BTEqualStrategyNumber:
if (is_leaf)
- retval = (*tinfo->f_eq) (query, key->lower, collation, flinfo);
+ retval = tinfo->f_eq(query, key->lower, collation, flinfo);
else
retval =
- ((*tinfo->f_cmp) (key->lower, query, collation, flinfo) <= 0 &&
- (*tinfo->f_cmp) (query, key->upper, collation, flinfo) <= 0) ||
+ (tinfo->f_cmp(key->lower, query, collation, flinfo) <= 0 &&
+ tinfo->f_cmp(query, key->upper, collation, flinfo) <= 0) ||
gbt_var_node_pf_match(key, query, tinfo);
break;
case BTGreaterStrategyNumber:
if (is_leaf)
- retval = (*tinfo->f_lt) (query, key->upper, collation, flinfo);
+ retval = tinfo->f_lt(query, key->upper, collation, flinfo);
else
- retval = (*tinfo->f_cmp) (query, key->upper, collation, flinfo) <= 0
+ retval = tinfo->f_cmp(query, key->upper, collation, flinfo) <= 0
|| gbt_var_node_pf_match(key, query, tinfo);
break;
case BTGreaterEqualStrategyNumber:
if (is_leaf)
- retval = (*tinfo->f_le) (query, key->upper, collation, flinfo);
+ retval = tinfo->f_le(query, key->upper, collation, flinfo);
else
- retval = (*tinfo->f_cmp) (query, key->upper, collation, flinfo) <= 0
+ retval = tinfo->f_cmp(query, key->upper, collation, flinfo) <= 0
|| gbt_var_node_pf_match(key, query, tinfo);
break;
case BtreeGistNotEqualStrategyNumber:
- retval = !((*tinfo->f_eq) (query, key->lower, collation, flinfo) &&
- (*tinfo->f_eq) (query, key->upper, collation, flinfo));
+ retval = !(tinfo->f_eq(query, key->lower, collation, flinfo) &&
+ tinfo->f_eq(query, key->upper, collation, flinfo));
break;
default:
- retval = FALSE;
+ retval = false;
}
return retval;
diff --git a/contrib/btree_gist/btree_uuid.c b/contrib/btree_gist/btree_uuid.c
index ecf357d662..0b3e52fbff 100644
--- a/contrib/btree_gist/btree_uuid.c
+++ b/contrib/btree_gist/btree_uuid.c
@@ -114,7 +114,7 @@ gbt_uuid_compress(PG_FUNCTION_ARGS)
memcpy((void *) (r + UUID_LEN), (void *) key, UUID_LEN);
gistentryinit(*retval, PointerGetDatum(r),
entry->rel, entry->page,
- entry->offset, FALSE);
+ entry->offset, false);
}
else
retval = entry;
@@ -182,8 +182,8 @@ uuid_2_double(const pg_uuid_t *u)
* machine, byte-swap each half so we can use native uint64 arithmetic.
*/
#ifndef WORDS_BIGENDIAN
- uu[0] = BSWAP64(uu[0]);
- uu[1] = BSWAP64(uu[1]);
+ uu[0] = pg_bswap64(uu[0]);
+ uu[1] = pg_bswap64(uu[1]);
#endif
/*
diff --git a/contrib/chkpass/CMakeLists.txt b/contrib/chkpass/CMakeLists.txt
deleted file mode 100644
index 1265b65d2a..0000000000
--- a/contrib/chkpass/CMakeLists.txt
+++ /dev/null
@@ -1,22 +0,0 @@
-include_directories("${PROJECT_SOURCE_DIR}/src/include")
-
-set(extension_name chkpass)
-
-add_library(${extension_name} ${PLUGIN_TYPE} ${extension_name}.c)
-target_link_libraries(${extension_name} ${contrib_libs})
-if(CRYPT_LIB)
- target_link_libraries(${extension_name} ${CRYPT_LIB})
-endif()
-set_target_properties(${extension_name} PROPERTIES PREFIX "")
-add_dependencies(${extension_name} postgres)
-if (MSVC)
- gen_def(${extension_name})
-endif()
-if(NOT PGXS)
- CMAKE_SET_TARGET_FOLDER(${extension_name} contrib)
-endif()
-install(TARGETS ${extension_name}
- RUNTIME DESTINATION ${PGBINDIR}
- LIBRARY DESTINATION ${LIBDIR})
-install(FILES ${extension_name}.control ${extension_name}--1.0.sql ${extension_name}--unpackaged--1.0.sql
- DESTINATION ${PGSHAREDIR}/extension)
diff --git a/contrib/chkpass/Makefile b/contrib/chkpass/Makefile
deleted file mode 100644
index a2599ea239..0000000000
--- a/contrib/chkpass/Makefile
+++ /dev/null
@@ -1,21 +0,0 @@
-# contrib/chkpass/Makefile
-
-MODULE_big = chkpass
-OBJS = chkpass.o $(WIN32RES)
-
-EXTENSION = chkpass
-DATA = chkpass--1.0.sql chkpass--unpackaged--1.0.sql
-PGFILEDESC = "chkpass - encrypted password data type"
-
-SHLIB_LINK = $(filter -lcrypt, $(LIBS))
-
-ifdef USE_PGXS
-PG_CONFIG = pg_config
-PGXS := $(shell $(PG_CONFIG) --pgxs)
-include $(PGXS)
-else
-subdir = contrib/chkpass
-top_builddir = ../..
-include $(top_builddir)/src/Makefile.global
-include $(top_srcdir)/contrib/contrib-global.mk
-endif
diff --git a/contrib/chkpass/chkpass--1.0.sql b/contrib/chkpass/chkpass--1.0.sql
deleted file mode 100644
index 406a61924c..0000000000
--- a/contrib/chkpass/chkpass--1.0.sql
+++ /dev/null
@@ -1,70 +0,0 @@
-/* contrib/chkpass/chkpass--1.0.sql */
-
--- complain if script is sourced in psql, rather than via CREATE EXTENSION
-\echo Use "CREATE EXTENSION chkpass" to load this file. \quit
-
---
--- Input and output functions and the type itself:
---
-
-CREATE FUNCTION chkpass_in(cstring)
- RETURNS chkpass
- AS 'MODULE_PATHNAME'
- LANGUAGE C STRICT VOLATILE;
--- Note: chkpass_in actually is volatile, because of its use of random().
--- In hindsight that was a bad idea, but there's no way to change it without
--- breaking some usage patterns.
-
-CREATE FUNCTION chkpass_out(chkpass)
- RETURNS cstring
- AS 'MODULE_PATHNAME'
- LANGUAGE C STRICT IMMUTABLE;
-
-CREATE TYPE chkpass (
- internallength = 16,
- input = chkpass_in,
- output = chkpass_out
-);
-
-CREATE FUNCTION raw(chkpass)
- RETURNS text
- AS 'MODULE_PATHNAME', 'chkpass_rout'
- LANGUAGE C STRICT;
-
---
--- The various boolean tests:
---
-
-CREATE FUNCTION eq(chkpass, text)
- RETURNS bool
- AS 'MODULE_PATHNAME', 'chkpass_eq'
- LANGUAGE C STRICT;
-
-CREATE FUNCTION ne(chkpass, text)
- RETURNS bool
- AS 'MODULE_PATHNAME', 'chkpass_ne'
- LANGUAGE C STRICT;
-
---
--- Now the operators.
---
-
-CREATE OPERATOR = (
- leftarg = chkpass,
- rightarg = text,
- negator = <>,
- procedure = eq
-);
-
-CREATE OPERATOR <> (
- leftarg = chkpass,
- rightarg = text,
- negator = =,
- procedure = ne
-);
-
-COMMENT ON TYPE chkpass IS 'password type with checks';
-
---
--- eof
---
diff --git a/contrib/chkpass/chkpass--unpackaged--1.0.sql b/contrib/chkpass/chkpass--unpackaged--1.0.sql
deleted file mode 100644
index 8bdecddfa5..0000000000
--- a/contrib/chkpass/chkpass--unpackaged--1.0.sql
+++ /dev/null
@@ -1,13 +0,0 @@
-/* contrib/chkpass/chkpass--unpackaged--1.0.sql */
-
--- complain if script is sourced in psql, rather than via CREATE EXTENSION
-\echo Use "CREATE EXTENSION chkpass FROM unpackaged" to load this file. \quit
-
-ALTER EXTENSION chkpass ADD type chkpass;
-ALTER EXTENSION chkpass ADD function chkpass_in(cstring);
-ALTER EXTENSION chkpass ADD function chkpass_out(chkpass);
-ALTER EXTENSION chkpass ADD function raw(chkpass);
-ALTER EXTENSION chkpass ADD function eq(chkpass,text);
-ALTER EXTENSION chkpass ADD function ne(chkpass,text);
-ALTER EXTENSION chkpass ADD operator <>(chkpass,text);
-ALTER EXTENSION chkpass ADD operator =(chkpass,text);
diff --git a/contrib/chkpass/chkpass.c b/contrib/chkpass/chkpass.c
deleted file mode 100644
index 3803ccff9a..0000000000
--- a/contrib/chkpass/chkpass.c
+++ /dev/null
@@ -1,175 +0,0 @@
-/*
- * PostgreSQL type definitions for chkpass
- * Written by D'Arcy J.M. Cain
- * darcy@druid.net
- * http://www.druid.net/darcy/
- *
- * contrib/chkpass/chkpass.c
- * best viewed with tabs set to 4
- */
-
-#include "postgres.h"
-
-#include
-#include
-#ifdef HAVE_CRYPT_H
-#include
-#endif
-
-#include "fmgr.h"
-#include "utils/backend_random.h"
-#include "utils/builtins.h"
-
-PG_MODULE_MAGIC;
-
-/*
- * This type encrypts it's input unless the first character is a colon.
- * The output is the encrypted form with a leading colon. The output
- * format is designed to allow dump and reload operations to work as
- * expected without doing special tricks.
- */
-
-
-/*
- * This is the internal storage format for CHKPASSs.
- * 15 is all I need but add a little buffer
- */
-
-typedef struct chkpass
-{
- char password[16];
-} chkpass;
-
-
-/* This function checks that the password is a good one
- * It's just a placeholder for now */
-static int
-verify_pass(const char *str)
-{
- return 0;
-}
-
-/*
- * CHKPASS reader.
- */
-PG_FUNCTION_INFO_V1(chkpass_in);
-Datum
-chkpass_in(PG_FUNCTION_ARGS)
-{
- char *str = PG_GETARG_CSTRING(0);
- chkpass *result;
- char mysalt[4];
- char *crypt_output;
- static char salt_chars[] =
- "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
-
- /* special case to let us enter encrypted passwords */
- if (*str == ':')
- {
- result = (chkpass *) palloc0(sizeof(chkpass));
- strlcpy(result->password, str + 1, 13 + 1);
- PG_RETURN_POINTER(result);
- }
-
- if (verify_pass(str) != 0)
- ereport(ERROR,
- (errcode(ERRCODE_DATA_EXCEPTION),
- errmsg("password \"%s\" is weak", str)));
-
- result = (chkpass *) palloc0(sizeof(chkpass));
-
- if (!pg_backend_random(mysalt, 2))
- ereport(ERROR,
- (errmsg("could not generate random salt")));
-
- mysalt[0] = salt_chars[mysalt[0] & 0x3f];
- mysalt[1] = salt_chars[mysalt[1] & 0x3f];
- mysalt[2] = 0; /* technically the terminator is not necessary
- * but I like to play safe */
-
- crypt_output = crypt(str, mysalt);
- if (crypt_output == NULL)
- ereport(ERROR,
- (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("crypt() failed")));
-
- strlcpy(result->password, crypt_output, sizeof(result->password));
-
- PG_RETURN_POINTER(result);
-}
-
-/*
- * CHKPASS output function.
- * Just like any string but we know it is max 15 (13 plus colon and terminator.)
- */
-
-PG_FUNCTION_INFO_V1(chkpass_out);
-Datum
-chkpass_out(PG_FUNCTION_ARGS)
-{
- chkpass *password = (chkpass *) PG_GETARG_POINTER(0);
- char *result;
-
- result = (char *) palloc(16);
- result[0] = ':';
- strlcpy(result + 1, password->password, 15);
-
- PG_RETURN_CSTRING(result);
-}
-
-
-/*
- * special output function that doesn't output the colon
- */
-
-PG_FUNCTION_INFO_V1(chkpass_rout);
-Datum
-chkpass_rout(PG_FUNCTION_ARGS)
-{
- chkpass *password = (chkpass *) PG_GETARG_POINTER(0);
-
- PG_RETURN_TEXT_P(cstring_to_text(password->password));
-}
-
-
-/*
- * Boolean tests
- */
-
-PG_FUNCTION_INFO_V1(chkpass_eq);
-Datum
-chkpass_eq(PG_FUNCTION_ARGS)
-{
- chkpass *a1 = (chkpass *) PG_GETARG_POINTER(0);
- text *a2 = PG_GETARG_TEXT_PP(1);
- char str[9];
- char *crypt_output;
-
- text_to_cstring_buffer(a2, str, sizeof(str));
- crypt_output = crypt(str, a1->password);
- if (crypt_output == NULL)
- ereport(ERROR,
- (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("crypt() failed")));
-
- PG_RETURN_BOOL(strcmp(a1->password, crypt_output) == 0);
-}
-
-PG_FUNCTION_INFO_V1(chkpass_ne);
-Datum
-chkpass_ne(PG_FUNCTION_ARGS)
-{
- chkpass *a1 = (chkpass *) PG_GETARG_POINTER(0);
- text *a2 = PG_GETARG_TEXT_PP(1);
- char str[9];
- char *crypt_output;
-
- text_to_cstring_buffer(a2, str, sizeof(str));
- crypt_output = crypt(str, a1->password);
- if (crypt_output == NULL)
- ereport(ERROR,
- (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("crypt() failed")));
-
- PG_RETURN_BOOL(strcmp(a1->password, crypt_output) != 0);
-}
diff --git a/contrib/chkpass/chkpass.control b/contrib/chkpass/chkpass.control
deleted file mode 100644
index bd4b3d3d0d..0000000000
--- a/contrib/chkpass/chkpass.control
+++ /dev/null
@@ -1,5 +0,0 @@
-# chkpass extension
-comment = 'data type for auto-encrypted passwords'
-default_version = '1.0'
-module_pathname = '$libdir/chkpass'
-relocatable = true
diff --git a/contrib/citext/CMakeLists.txt b/contrib/citext/CMakeLists.txt
index 4d33eb6a72..e5fcfd87ec 100644
--- a/contrib/citext/CMakeLists.txt
+++ b/contrib/citext/CMakeLists.txt
@@ -18,6 +18,7 @@ install(TARGETS ${extension_name}
install(FILES
${extension_name}.control
${extension_name}--1.4.sql
+ ${extension_name}--1.4--1.5.sql
${extension_name}--1.3--1.4.sql
${extension_name}--1.2--1.3.sql
${extension_name}--1.1--1.2.sql
diff --git a/contrib/citext/Makefile b/contrib/citext/Makefile
index 563cd22dcc..e32a7de946 100644
--- a/contrib/citext/Makefile
+++ b/contrib/citext/Makefile
@@ -3,7 +3,8 @@
MODULES = citext
EXTENSION = citext
-DATA = citext--1.4.sql citext--1.3--1.4.sql \
+DATA = citext--1.4.sql citext--1.4--1.5.sql \
+ citext--1.3--1.4.sql \
citext--1.2--1.3.sql citext--1.1--1.2.sql \
citext--1.0--1.1.sql citext--unpackaged--1.0.sql
PGFILEDESC = "citext - case-insensitive character string data type"
diff --git a/contrib/citext/citext--1.4--1.5.sql b/contrib/citext/citext--1.4--1.5.sql
new file mode 100644
index 0000000000..5ae522b7da
--- /dev/null
+++ b/contrib/citext/citext--1.4--1.5.sql
@@ -0,0 +1,88 @@
+/* contrib/citext/citext--1.4--1.5.sql */
+
+-- complain if script is sourced in psql, rather than via ALTER EXTENSION
+\echo Use "ALTER EXTENSION citext UPDATE TO '1.5'" to load this file. \quit
+
+ALTER OPERATOR <= (citext, citext) SET (
+ RESTRICT = scalarlesel,
+ JOIN = scalarlejoinsel
+);
+
+ALTER OPERATOR >= (citext, citext) SET (
+ RESTRICT = scalargesel,
+ JOIN = scalargejoinsel
+);
+
+CREATE FUNCTION citext_pattern_lt( citext, citext )
+RETURNS bool
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION citext_pattern_le( citext, citext )
+RETURNS bool
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION citext_pattern_gt( citext, citext )
+RETURNS bool
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION citext_pattern_ge( citext, citext )
+RETURNS bool
+AS 'MODULE_PATHNAME'
+LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE OPERATOR ~<~ (
+ LEFTARG = CITEXT,
+ RIGHTARG = CITEXT,
+ NEGATOR = ~>=~,
+ COMMUTATOR = ~>~,
+ PROCEDURE = citext_pattern_lt,
+ RESTRICT = scalarltsel,
+ JOIN = scalarltjoinsel
+);
+
+CREATE OPERATOR ~<=~ (
+ LEFTARG = CITEXT,
+ RIGHTARG = CITEXT,
+ NEGATOR = ~>~,
+ COMMUTATOR = ~>=~,
+ PROCEDURE = citext_pattern_le,
+ RESTRICT = scalarltsel,
+ JOIN = scalarltjoinsel
+);
+
+CREATE OPERATOR ~>=~ (
+ LEFTARG = CITEXT,
+ RIGHTARG = CITEXT,
+ NEGATOR = ~<~,
+ COMMUTATOR = ~<=~,
+ PROCEDURE = citext_pattern_ge,
+ RESTRICT = scalargtsel,
+ JOIN = scalargtjoinsel
+);
+
+CREATE OPERATOR ~>~ (
+ LEFTARG = CITEXT,
+ RIGHTARG = CITEXT,
+ NEGATOR = ~<=~,
+ COMMUTATOR = ~<~,
+ PROCEDURE = citext_pattern_gt,
+ RESTRICT = scalargtsel,
+ JOIN = scalargtjoinsel
+);
+
+CREATE FUNCTION citext_pattern_cmp(citext, citext)
+RETURNS int4
+AS 'MODULE_PATHNAME'
+LANGUAGE C STRICT IMMUTABLE PARALLEL SAFE;
+
+CREATE OPERATOR CLASS citext_pattern_ops
+FOR TYPE CITEXT USING btree AS
+ OPERATOR 1 ~<~ (citext, citext),
+ OPERATOR 2 ~<=~ (citext, citext),
+ OPERATOR 3 = (citext, citext),
+ OPERATOR 4 ~>=~ (citext, citext),
+ OPERATOR 5 ~>~ (citext, citext),
+ FUNCTION 1 citext_pattern_cmp(citext, citext);
diff --git a/contrib/citext/citext.c b/contrib/citext/citext.c
index 04f604b15f..2c0e48e2bc 100644
--- a/contrib/citext/citext.c
+++ b/contrib/citext/citext.c
@@ -9,9 +9,7 @@
#include "utils/formatting.h"
#include "utils/varlena.h"
-#ifdef PG_MODULE_MAGIC
PG_MODULE_MAGIC;
-#endif
/*
* ====================
@@ -20,6 +18,7 @@ PG_MODULE_MAGIC;
*/
static int32 citextcmp(text *left, text *right, Oid collid);
+static int32 internal_citext_pattern_cmp(text *left, text *right, Oid collid);
/*
* =================
@@ -60,6 +59,41 @@ citextcmp(text *left, text *right, Oid collid)
return result;
}
+/*
+ * citext_pattern_cmp()
+ * Internal character-by-character comparison function for citext strings.
+ * Returns int32 negative, zero, or positive.
+ */
+static int32
+internal_citext_pattern_cmp(text *left, text *right, Oid collid)
+{
+ char *lcstr,
+ *rcstr;
+ int llen,
+ rlen;
+ int32 result;
+
+ lcstr = str_tolower(VARDATA_ANY(left), VARSIZE_ANY_EXHDR(left), DEFAULT_COLLATION_OID);
+ rcstr = str_tolower(VARDATA_ANY(right), VARSIZE_ANY_EXHDR(right), DEFAULT_COLLATION_OID);
+
+ llen = strlen(lcstr);
+ rlen = strlen(rcstr);
+
+ result = memcmp((void *) lcstr, (void *) rcstr, Min(llen, rlen));
+ if (result == 0)
+ {
+ if (llen < rlen)
+ result = -1;
+ else if (llen > rlen)
+ result = 1;
+ }
+
+ pfree(lcstr);
+ pfree(rcstr);
+
+ return result;
+}
+
/*
* ==================
* INDEXING FUNCTIONS
@@ -83,6 +117,23 @@ citext_cmp(PG_FUNCTION_ARGS)
PG_RETURN_INT32(result);
}
+PG_FUNCTION_INFO_V1(citext_pattern_cmp);
+
+Datum
+citext_pattern_cmp(PG_FUNCTION_ARGS)
+{
+ text *left = PG_GETARG_TEXT_PP(0);
+ text *right = PG_GETARG_TEXT_PP(1);
+ int32 result;
+
+ result = internal_citext_pattern_cmp(left, right, PG_GET_COLLATION());
+
+ PG_FREE_IF_COPY(left, 0);
+ PG_FREE_IF_COPY(right, 1);
+
+ PG_RETURN_INT32(result);
+}
+
PG_FUNCTION_INFO_V1(citext_hash);
Datum
@@ -236,6 +287,74 @@ citext_ge(PG_FUNCTION_ARGS)
PG_RETURN_BOOL(result);
}
+PG_FUNCTION_INFO_V1(citext_pattern_lt);
+
+Datum
+citext_pattern_lt(PG_FUNCTION_ARGS)
+{
+ text *left = PG_GETARG_TEXT_PP(0);
+ text *right = PG_GETARG_TEXT_PP(1);
+ bool result;
+
+ result = internal_citext_pattern_cmp(left, right, PG_GET_COLLATION()) < 0;
+
+ PG_FREE_IF_COPY(left, 0);
+ PG_FREE_IF_COPY(right, 1);
+
+ PG_RETURN_BOOL(result);
+}
+
+PG_FUNCTION_INFO_V1(citext_pattern_le);
+
+Datum
+citext_pattern_le(PG_FUNCTION_ARGS)
+{
+ text *left = PG_GETARG_TEXT_PP(0);
+ text *right = PG_GETARG_TEXT_PP(1);
+ bool result;
+
+ result = internal_citext_pattern_cmp(left, right, PG_GET_COLLATION()) <= 0;
+
+ PG_FREE_IF_COPY(left, 0);
+ PG_FREE_IF_COPY(right, 1);
+
+ PG_RETURN_BOOL(result);
+}
+
+PG_FUNCTION_INFO_V1(citext_pattern_gt);
+
+Datum
+citext_pattern_gt(PG_FUNCTION_ARGS)
+{
+ text *left = PG_GETARG_TEXT_PP(0);
+ text *right = PG_GETARG_TEXT_PP(1);
+ bool result;
+
+ result = internal_citext_pattern_cmp(left, right, PG_GET_COLLATION()) > 0;
+
+ PG_FREE_IF_COPY(left, 0);
+ PG_FREE_IF_COPY(right, 1);
+
+ PG_RETURN_BOOL(result);
+}
+
+PG_FUNCTION_INFO_V1(citext_pattern_ge);
+
+Datum
+citext_pattern_ge(PG_FUNCTION_ARGS)
+{
+ text *left = PG_GETARG_TEXT_PP(0);
+ text *right = PG_GETARG_TEXT_PP(1);
+ bool result;
+
+ result = internal_citext_pattern_cmp(left, right, PG_GET_COLLATION()) >= 0;
+
+ PG_FREE_IF_COPY(left, 0);
+ PG_FREE_IF_COPY(right, 1);
+
+ PG_RETURN_BOOL(result);
+}
+
/*
* ===================
* AGGREGATE FUNCTIONS
diff --git a/contrib/citext/citext.control b/contrib/citext/citext.control
index 17fce4e887..4cd6e09331 100644
--- a/contrib/citext/citext.control
+++ b/contrib/citext/citext.control
@@ -1,5 +1,5 @@
# citext extension
comment = 'data type for case-insensitive character strings'
-default_version = '1.4'
+default_version = '1.5'
module_pathname = '$libdir/citext'
relocatable = true
diff --git a/contrib/citext/expected/citext.out b/contrib/citext/expected/citext.out
index 9cc94f4c1b..95373182af 100644
--- a/contrib/citext/expected/citext.out
+++ b/contrib/citext/expected/citext.out
@@ -2351,3 +2351,355 @@ SELECT * FROM citext_matview ORDER BY id;
5 |
(5 rows)
+-- test citext_pattern_cmp() function explicitly.
+SELECT citext_pattern_cmp('aardvark'::citext, 'aardvark'::citext) AS zero;
+ zero
+------
+ 0
+(1 row)
+
+SELECT citext_pattern_cmp('aardvark'::citext, 'aardVark'::citext) AS zero;
+ zero
+------
+ 0
+(1 row)
+
+SELECT citext_pattern_cmp('AARDVARK'::citext, 'AARDVARK'::citext) AS zero;
+ zero
+------
+ 0
+(1 row)
+
+SELECT citext_pattern_cmp('B'::citext, 'a'::citext) > 0 AS true;
+ true
+------
+ t
+(1 row)
+
+SELECT citext_pattern_cmp('a'::citext, 'B'::citext) < 0 AS true;
+ true
+------
+ t
+(1 row)
+
+SELECT citext_pattern_cmp('A'::citext, 'b'::citext) < 0 AS true;
+ true
+------
+ t
+(1 row)
+
+SELECT citext_pattern_cmp('ABCD'::citext, 'abc'::citext) > 0 AS true;
+ true
+------
+ t
+(1 row)
+
+SELECT citext_pattern_cmp('ABC'::citext, 'abcd'::citext) < 0 AS true;
+ true
+------
+ t
+(1 row)
+
+-- test operator functions
+-- lt
+SELECT citext_pattern_lt('a'::citext, 'b'::citext) AS true;
+ true
+------
+ t
+(1 row)
+
+SELECT citext_pattern_lt('A'::citext, 'b'::citext) AS true;
+ true
+------
+ t
+(1 row)
+
+SELECT citext_pattern_lt('a'::citext, 'B'::citext) AS true;
+ true
+------
+ t
+(1 row)
+
+SELECT citext_pattern_lt('b'::citext, 'a'::citext) AS false;
+ false
+-------
+ f
+(1 row)
+
+SELECT citext_pattern_lt('B'::citext, 'a'::citext) AS false;
+ false
+-------
+ f
+(1 row)
+
+SELECT citext_pattern_lt('b'::citext, 'A'::citext) AS false;
+ false
+-------
+ f
+(1 row)
+
+-- le
+SELECT citext_pattern_le('a'::citext, 'a'::citext) AS true;
+ true
+------
+ t
+(1 row)
+
+SELECT citext_pattern_le('a'::citext, 'A'::citext) AS true;
+ true
+------
+ t
+(1 row)
+
+SELECT citext_pattern_le('A'::citext, 'a'::citext) AS true;
+ true
+------
+ t
+(1 row)
+
+SELECT citext_pattern_le('A'::citext, 'A'::citext) AS true;
+ true
+------
+ t
+(1 row)
+
+SELECT citext_pattern_le('a'::citext, 'B'::citext) AS true;
+ true
+------
+ t
+(1 row)
+
+SELECT citext_pattern_le('A'::citext, 'b'::citext) AS true;
+ true
+------
+ t
+(1 row)
+
+SELECT citext_pattern_le('a'::citext, 'B'::citext) AS true;
+ true
+------
+ t
+(1 row)
+
+SELECT citext_pattern_le('b'::citext, 'a'::citext) AS false;
+ false
+-------
+ f
+(1 row)
+
+SELECT citext_pattern_le('B'::citext, 'a'::citext) AS false;
+ false
+-------
+ f
+(1 row)
+
+SELECT citext_pattern_le('b'::citext, 'A'::citext) AS false;
+ false
+-------
+ f
+(1 row)
+
+-- gt
+SELECT citext_pattern_gt('a'::citext, 'b'::citext) AS false;
+ false
+-------
+ f
+(1 row)
+
+SELECT citext_pattern_gt('A'::citext, 'b'::citext) AS false;
+ false
+-------
+ f
+(1 row)
+
+SELECT citext_pattern_gt('a'::citext, 'B'::citext) AS false;
+ false
+-------
+ f
+(1 row)
+
+SELECT citext_pattern_gt('b'::citext, 'a'::citext) AS true;
+ true
+------
+ t
+(1 row)
+
+SELECT citext_pattern_gt('B'::citext, 'a'::citext) AS true;
+ true
+------
+ t
+(1 row)
+
+SELECT citext_pattern_gt('b'::citext, 'A'::citext) AS true;
+ true
+------
+ t
+(1 row)
+
+-- ge
+SELECT citext_pattern_ge('a'::citext, 'a'::citext) AS true;
+ true
+------
+ t
+(1 row)
+
+SELECT citext_pattern_ge('a'::citext, 'A'::citext) AS true;
+ true
+------
+ t
+(1 row)
+
+SELECT citext_pattern_ge('A'::citext, 'a'::citext) AS true;
+ true
+------
+ t
+(1 row)
+
+SELECT citext_pattern_ge('A'::citext, 'A'::citext) AS true;
+ true
+------
+ t
+(1 row)
+
+SELECT citext_pattern_ge('a'::citext, 'B'::citext) AS false;
+ false
+-------
+ f
+(1 row)
+
+SELECT citext_pattern_ge('A'::citext, 'b'::citext) AS false;
+ false
+-------
+ f
+(1 row)
+
+SELECT citext_pattern_ge('a'::citext, 'B'::citext) AS false;
+ false
+-------
+ f
+(1 row)
+
+SELECT citext_pattern_ge('b'::citext, 'a'::citext) AS true;
+ true
+------
+ t
+(1 row)
+
+SELECT citext_pattern_ge('B'::citext, 'a'::citext) AS true;
+ true
+------
+ t
+(1 row)
+
+SELECT citext_pattern_ge('b'::citext, 'A'::citext) AS true;
+ true
+------
+ t
+(1 row)
+
+-- Multi-byte tests below are diabled like the sanity tests above.
+-- Uncomment to run them.
+-- Test ~<~ and ~<=~
+SELECT 'a'::citext ~<~ 'B'::citext AS t;
+ t
+---
+ t
+(1 row)
+
+SELECT 'b'::citext ~<~ 'A'::citext AS f;
+ f
+---
+ f
+(1 row)
+
+-- SELECT 'à'::citext ~<~ 'À'::citext AS f;
+SELECT 'a'::citext ~<=~ 'B'::citext AS t;
+ t
+---
+ t
+(1 row)
+
+SELECT 'a'::citext ~<=~ 'A'::citext AS t;
+ t
+---
+ t
+(1 row)
+
+-- SELECT 'à'::citext ~<=~ 'À'::citext AS t;
+-- Test ~>~ and ~>=~
+SELECT 'B'::citext ~>~ 'a'::citext AS t;
+ t
+---
+ t
+(1 row)
+
+SELECT 'b'::citext ~>~ 'A'::citext AS t;
+ t
+---
+ t
+(1 row)
+
+-- SELECT 'à'::citext ~>~ 'À'::citext AS f;
+SELECT 'B'::citext ~>~ 'b'::citext AS f;
+ f
+---
+ f
+(1 row)
+
+SELECT 'B'::citext ~>=~ 'b'::citext AS t;
+ t
+---
+ t
+(1 row)
+
+-- SELECT 'à'::citext ~>=~ 'À'::citext AS t;
+-- Test implicit casting. citext casts to text, but not vice-versa.
+SELECT 'B'::citext ~<~ 'a'::text AS t; -- text wins.
+ t
+---
+ t
+(1 row)
+
+SELECT 'B'::citext ~<=~ 'a'::text AS t; -- text wins.
+ t
+---
+ t
+(1 row)
+
+SELECT 'a'::citext ~>~ 'B'::text AS t; -- text wins.
+ t
+---
+ t
+(1 row)
+
+SELECT 'a'::citext ~>=~ 'B'::text AS t; -- text wins.
+ t
+---
+ t
+(1 row)
+
+-- Test implicit casting. citext casts to varchar, but not vice-versa.
+SELECT 'B'::citext ~<~ 'a'::varchar AS t; -- varchar wins.
+ t
+---
+ t
+(1 row)
+
+SELECT 'B'::citext ~<=~ 'a'::varchar AS t; -- varchar wins.
+ t
+---
+ t
+(1 row)
+
+SELECT 'a'::citext ~>~ 'B'::varchar AS t; -- varchar wins.
+ t
+---
+ t
+(1 row)
+
+SELECT 'a'::citext ~>=~ 'B'::varchar AS t; -- varchar wins.
+ t
+---
+ t
+(1 row)
+
diff --git a/contrib/citext/expected/citext_1.out b/contrib/citext/expected/citext_1.out
index d1fb1e14e0..855ec3f10b 100644
--- a/contrib/citext/expected/citext_1.out
+++ b/contrib/citext/expected/citext_1.out
@@ -2351,3 +2351,355 @@ SELECT * FROM citext_matview ORDER BY id;
5 |
(5 rows)
+-- test citext_pattern_cmp() function explicitly.
+SELECT citext_pattern_cmp('aardvark'::citext, 'aardvark'::citext) AS zero;
+ zero
+------
+ 0
+(1 row)
+
+SELECT citext_pattern_cmp('aardvark'::citext, 'aardVark'::citext) AS zero;
+ zero
+------
+ 0
+(1 row)
+
+SELECT citext_pattern_cmp('AARDVARK'::citext, 'AARDVARK'::citext) AS zero;
+ zero
+------
+ 0
+(1 row)
+
+SELECT citext_pattern_cmp('B'::citext, 'a'::citext) > 0 AS true;
+ true
+------
+ t
+(1 row)
+
+SELECT citext_pattern_cmp('a'::citext, 'B'::citext) < 0 AS true;
+ true
+------
+ t
+(1 row)
+
+SELECT citext_pattern_cmp('A'::citext, 'b'::citext) < 0 AS true;
+ true
+------
+ t
+(1 row)
+
+SELECT citext_pattern_cmp('ABCD'::citext, 'abc'::citext) > 0 AS true;
+ true
+------
+ t
+(1 row)
+
+SELECT citext_pattern_cmp('ABC'::citext, 'abcd'::citext) < 0 AS true;
+ true
+------
+ t
+(1 row)
+
+-- test operator functions
+-- lt
+SELECT citext_pattern_lt('a'::citext, 'b'::citext) AS true;
+ true
+------
+ t
+(1 row)
+
+SELECT citext_pattern_lt('A'::citext, 'b'::citext) AS true;
+ true
+------
+ t
+(1 row)
+
+SELECT citext_pattern_lt('a'::citext, 'B'::citext) AS true;
+ true
+------
+ t
+(1 row)
+
+SELECT citext_pattern_lt('b'::citext, 'a'::citext) AS false;
+ false
+-------
+ f
+(1 row)
+
+SELECT citext_pattern_lt('B'::citext, 'a'::citext) AS false;
+ false
+-------
+ f
+(1 row)
+
+SELECT citext_pattern_lt('b'::citext, 'A'::citext) AS false;
+ false
+-------
+ f
+(1 row)
+
+-- le
+SELECT citext_pattern_le('a'::citext, 'a'::citext) AS true;
+ true
+------
+ t
+(1 row)
+
+SELECT citext_pattern_le('a'::citext, 'A'::citext) AS true;
+ true
+------
+ t
+(1 row)
+
+SELECT citext_pattern_le('A'::citext, 'a'::citext) AS true;
+ true
+------
+ t
+(1 row)
+
+SELECT citext_pattern_le('A'::citext, 'A'::citext) AS true;
+ true
+------
+ t
+(1 row)
+
+SELECT citext_pattern_le('a'::citext, 'B'::citext) AS true;
+ true
+------
+ t
+(1 row)
+
+SELECT citext_pattern_le('A'::citext, 'b'::citext) AS true;
+ true
+------
+ t
+(1 row)
+
+SELECT citext_pattern_le('a'::citext, 'B'::citext) AS true;
+ true
+------
+ t
+(1 row)
+
+SELECT citext_pattern_le('b'::citext, 'a'::citext) AS false;
+ false
+-------
+ f
+(1 row)
+
+SELECT citext_pattern_le('B'::citext, 'a'::citext) AS false;
+ false
+-------
+ f
+(1 row)
+
+SELECT citext_pattern_le('b'::citext, 'A'::citext) AS false;
+ false
+-------
+ f
+(1 row)
+
+-- gt
+SELECT citext_pattern_gt('a'::citext, 'b'::citext) AS false;
+ false
+-------
+ f
+(1 row)
+
+SELECT citext_pattern_gt('A'::citext, 'b'::citext) AS false;
+ false
+-------
+ f
+(1 row)
+
+SELECT citext_pattern_gt('a'::citext, 'B'::citext) AS false;
+ false
+-------
+ f
+(1 row)
+
+SELECT citext_pattern_gt('b'::citext, 'a'::citext) AS true;
+ true
+------
+ t
+(1 row)
+
+SELECT citext_pattern_gt('B'::citext, 'a'::citext) AS true;
+ true
+------
+ t
+(1 row)
+
+SELECT citext_pattern_gt('b'::citext, 'A'::citext) AS true;
+ true
+------
+ t
+(1 row)
+
+-- ge
+SELECT citext_pattern_ge('a'::citext, 'a'::citext) AS true;
+ true
+------
+ t
+(1 row)
+
+SELECT citext_pattern_ge('a'::citext, 'A'::citext) AS true;
+ true
+------
+ t
+(1 row)
+
+SELECT citext_pattern_ge('A'::citext, 'a'::citext) AS true;
+ true
+------
+ t
+(1 row)
+
+SELECT citext_pattern_ge('A'::citext, 'A'::citext) AS true;
+ true
+------
+ t
+(1 row)
+
+SELECT citext_pattern_ge('a'::citext, 'B'::citext) AS false;
+ false
+-------
+ f
+(1 row)
+
+SELECT citext_pattern_ge('A'::citext, 'b'::citext) AS false;
+ false
+-------
+ f
+(1 row)
+
+SELECT citext_pattern_ge('a'::citext, 'B'::citext) AS false;
+ false
+-------
+ f
+(1 row)
+
+SELECT citext_pattern_ge('b'::citext, 'a'::citext) AS true;
+ true
+------
+ t
+(1 row)
+
+SELECT citext_pattern_ge('B'::citext, 'a'::citext) AS true;
+ true
+------
+ t
+(1 row)
+
+SELECT citext_pattern_ge('b'::citext, 'A'::citext) AS true;
+ true
+------
+ t
+(1 row)
+
+-- Multi-byte tests below are diabled like the sanity tests above.
+-- Uncomment to run them.
+-- Test ~<~ and ~<=~
+SELECT 'a'::citext ~<~ 'B'::citext AS t;
+ t
+---
+ t
+(1 row)
+
+SELECT 'b'::citext ~<~ 'A'::citext AS f;
+ f
+---
+ f
+(1 row)
+
+-- SELECT 'à'::citext ~<~ 'À'::citext AS f;
+SELECT 'a'::citext ~<=~ 'B'::citext AS t;
+ t
+---
+ t
+(1 row)
+
+SELECT 'a'::citext ~<=~ 'A'::citext AS t;
+ t
+---
+ t
+(1 row)
+
+-- SELECT 'à'::citext ~<=~ 'À'::citext AS t;
+-- Test ~>~ and ~>=~
+SELECT 'B'::citext ~>~ 'a'::citext AS t;
+ t
+---
+ t
+(1 row)
+
+SELECT 'b'::citext ~>~ 'A'::citext AS t;
+ t
+---
+ t
+(1 row)
+
+-- SELECT 'à'::citext ~>~ 'À'::citext AS f;
+SELECT 'B'::citext ~>~ 'b'::citext AS f;
+ f
+---
+ f
+(1 row)
+
+SELECT 'B'::citext ~>=~ 'b'::citext AS t;
+ t
+---
+ t
+(1 row)
+
+-- SELECT 'à'::citext ~>=~ 'À'::citext AS t;
+-- Test implicit casting. citext casts to text, but not vice-versa.
+SELECT 'B'::citext ~<~ 'a'::text AS t; -- text wins.
+ t
+---
+ t
+(1 row)
+
+SELECT 'B'::citext ~<=~ 'a'::text AS t; -- text wins.
+ t
+---
+ t
+(1 row)
+
+SELECT 'a'::citext ~>~ 'B'::text AS t; -- text wins.
+ t
+---
+ t
+(1 row)
+
+SELECT 'a'::citext ~>=~ 'B'::text AS t; -- text wins.
+ t
+---
+ t
+(1 row)
+
+-- Test implicit casting. citext casts to varchar, but not vice-versa.
+SELECT 'B'::citext ~<~ 'a'::varchar AS t; -- varchar wins.
+ t
+---
+ t
+(1 row)
+
+SELECT 'B'::citext ~<=~ 'a'::varchar AS t; -- varchar wins.
+ t
+---
+ t
+(1 row)
+
+SELECT 'a'::citext ~>~ 'B'::varchar AS t; -- varchar wins.
+ t
+---
+ t
+(1 row)
+
+SELECT 'a'::citext ~>=~ 'B'::varchar AS t; -- varchar wins.
+ t
+---
+ t
+(1 row)
+
diff --git a/contrib/citext/sql/citext.sql b/contrib/citext/sql/citext.sql
index f70f9ebae9..2732be436d 100644
--- a/contrib/citext/sql/citext.sql
+++ b/contrib/citext/sql/citext.sql
@@ -752,3 +752,84 @@ SELECT *
WHERE t.id IS NULL OR m.id IS NULL;
REFRESH MATERIALIZED VIEW CONCURRENTLY citext_matview;
SELECT * FROM citext_matview ORDER BY id;
+
+-- test citext_pattern_cmp() function explicitly.
+SELECT citext_pattern_cmp('aardvark'::citext, 'aardvark'::citext) AS zero;
+SELECT citext_pattern_cmp('aardvark'::citext, 'aardVark'::citext) AS zero;
+SELECT citext_pattern_cmp('AARDVARK'::citext, 'AARDVARK'::citext) AS zero;
+SELECT citext_pattern_cmp('B'::citext, 'a'::citext) > 0 AS true;
+SELECT citext_pattern_cmp('a'::citext, 'B'::citext) < 0 AS true;
+SELECT citext_pattern_cmp('A'::citext, 'b'::citext) < 0 AS true;
+SELECT citext_pattern_cmp('ABCD'::citext, 'abc'::citext) > 0 AS true;
+SELECT citext_pattern_cmp('ABC'::citext, 'abcd'::citext) < 0 AS true;
+
+-- test operator functions
+-- lt
+SELECT citext_pattern_lt('a'::citext, 'b'::citext) AS true;
+SELECT citext_pattern_lt('A'::citext, 'b'::citext) AS true;
+SELECT citext_pattern_lt('a'::citext, 'B'::citext) AS true;
+SELECT citext_pattern_lt('b'::citext, 'a'::citext) AS false;
+SELECT citext_pattern_lt('B'::citext, 'a'::citext) AS false;
+SELECT citext_pattern_lt('b'::citext, 'A'::citext) AS false;
+-- le
+SELECT citext_pattern_le('a'::citext, 'a'::citext) AS true;
+SELECT citext_pattern_le('a'::citext, 'A'::citext) AS true;
+SELECT citext_pattern_le('A'::citext, 'a'::citext) AS true;
+SELECT citext_pattern_le('A'::citext, 'A'::citext) AS true;
+SELECT citext_pattern_le('a'::citext, 'B'::citext) AS true;
+SELECT citext_pattern_le('A'::citext, 'b'::citext) AS true;
+SELECT citext_pattern_le('a'::citext, 'B'::citext) AS true;
+SELECT citext_pattern_le('b'::citext, 'a'::citext) AS false;
+SELECT citext_pattern_le('B'::citext, 'a'::citext) AS false;
+SELECT citext_pattern_le('b'::citext, 'A'::citext) AS false;
+-- gt
+SELECT citext_pattern_gt('a'::citext, 'b'::citext) AS false;
+SELECT citext_pattern_gt('A'::citext, 'b'::citext) AS false;
+SELECT citext_pattern_gt('a'::citext, 'B'::citext) AS false;
+SELECT citext_pattern_gt('b'::citext, 'a'::citext) AS true;
+SELECT citext_pattern_gt('B'::citext, 'a'::citext) AS true;
+SELECT citext_pattern_gt('b'::citext, 'A'::citext) AS true;
+-- ge
+SELECT citext_pattern_ge('a'::citext, 'a'::citext) AS true;
+SELECT citext_pattern_ge('a'::citext, 'A'::citext) AS true;
+SELECT citext_pattern_ge('A'::citext, 'a'::citext) AS true;
+SELECT citext_pattern_ge('A'::citext, 'A'::citext) AS true;
+SELECT citext_pattern_ge('a'::citext, 'B'::citext) AS false;
+SELECT citext_pattern_ge('A'::citext, 'b'::citext) AS false;
+SELECT citext_pattern_ge('a'::citext, 'B'::citext) AS false;
+SELECT citext_pattern_ge('b'::citext, 'a'::citext) AS true;
+SELECT citext_pattern_ge('B'::citext, 'a'::citext) AS true;
+SELECT citext_pattern_ge('b'::citext, 'A'::citext) AS true;
+
+-- Multi-byte tests below are diabled like the sanity tests above.
+-- Uncomment to run them.
+
+-- Test ~<~ and ~<=~
+SELECT 'a'::citext ~<~ 'B'::citext AS t;
+SELECT 'b'::citext ~<~ 'A'::citext AS f;
+-- SELECT 'à'::citext ~<~ 'À'::citext AS f;
+SELECT 'a'::citext ~<=~ 'B'::citext AS t;
+SELECT 'a'::citext ~<=~ 'A'::citext AS t;
+-- SELECT 'à'::citext ~<=~ 'À'::citext AS t;
+
+-- Test ~>~ and ~>=~
+SELECT 'B'::citext ~>~ 'a'::citext AS t;
+SELECT 'b'::citext ~>~ 'A'::citext AS t;
+-- SELECT 'à'::citext ~>~ 'À'::citext AS f;
+SELECT 'B'::citext ~>~ 'b'::citext AS f;
+SELECT 'B'::citext ~>=~ 'b'::citext AS t;
+-- SELECT 'à'::citext ~>=~ 'À'::citext AS t;
+
+-- Test implicit casting. citext casts to text, but not vice-versa.
+SELECT 'B'::citext ~<~ 'a'::text AS t; -- text wins.
+SELECT 'B'::citext ~<=~ 'a'::text AS t; -- text wins.
+
+SELECT 'a'::citext ~>~ 'B'::text AS t; -- text wins.
+SELECT 'a'::citext ~>=~ 'B'::text AS t; -- text wins.
+
+-- Test implicit casting. citext casts to varchar, but not vice-versa.
+SELECT 'B'::citext ~<~ 'a'::varchar AS t; -- varchar wins.
+SELECT 'B'::citext ~<=~ 'a'::varchar AS t; -- varchar wins.
+
+SELECT 'a'::citext ~>~ 'B'::varchar AS t; -- varchar wins.
+SELECT 'a'::citext ~>=~ 'B'::varchar AS t; -- varchar wins.
diff --git a/contrib/cube/CMakeLists.txt b/contrib/cube/CMakeLists.txt
index b5d1a2b03a..c7cecd540e 100644
--- a/contrib/cube/CMakeLists.txt
+++ b/contrib/cube/CMakeLists.txt
@@ -25,6 +25,8 @@ install(TARGETS ${extension_name}
LIBRARY DESTINATION ${LIBDIR})
install(FILES
${extension_name}.control
+ ${extension_name}--1.3--1.4.sql
+ ${extension_name}--1.2--1.3.sql
${extension_name}--1.2.sql
${extension_name}--1.1--1.2.sql
${extension_name}--1.0--1.1.sql
diff --git a/contrib/cube/Makefile b/contrib/cube/Makefile
index be7a1bc1a0..accb7d28a3 100644
--- a/contrib/cube/Makefile
+++ b/contrib/cube/Makefile
@@ -4,7 +4,8 @@ MODULE_big = cube
OBJS= cube.o cubeparse.o $(WIN32RES)
EXTENSION = cube
-DATA = cube--1.2.sql cube--1.1--1.2.sql cube--1.0--1.1.sql \
+DATA = cube--1.2.sql cube--1.2--1.3.sql cube--1.3--1.4.sql \
+ cube--1.1--1.2.sql cube--1.0--1.1.sql \
cube--unpackaged--1.0.sql
PGFILEDESC = "cube - multidimensional cube data type"
diff --git a/contrib/cube/cube--1.2--1.3.sql b/contrib/cube/cube--1.2--1.3.sql
new file mode 100644
index 0000000000..a688f19f02
--- /dev/null
+++ b/contrib/cube/cube--1.2--1.3.sql
@@ -0,0 +1,12 @@
+/* contrib/cube/cube--1.2--1.3.sql */
+
+-- complain if script is sourced in psql, rather than via ALTER EXTENSION
+\echo Use "ALTER EXTENSION cube UPDATE TO '1.3'" to load this file. \quit
+
+ALTER OPERATOR <= (cube, cube) SET (
+ RESTRICT = scalarlesel, JOIN = scalarlejoinsel
+);
+
+ALTER OPERATOR >= (cube, cube) SET (
+ RESTRICT = scalargesel, JOIN = scalargejoinsel
+);
diff --git a/contrib/cube/cube--1.3--1.4.sql b/contrib/cube/cube--1.3--1.4.sql
new file mode 100644
index 0000000000..869820c0c8
--- /dev/null
+++ b/contrib/cube/cube--1.3--1.4.sql
@@ -0,0 +1,45 @@
+/* contrib/cube/cube--1.3--1.4.sql */
+
+-- complain if script is sourced in psql, rather than via ALTER EXTENSION
+\echo Use "ALTER EXTENSION cube UPDATE TO '1.4'" to load this file. \quit
+
+--
+-- Get rid of unnecessary compress and decompress support functions.
+--
+-- To be allowed to drop the opclass entry for a support function,
+-- we must change the entry's dependency type from 'internal' to 'auto',
+-- as though it were a loose member of the opfamily rather than being
+-- bound into a particular opclass. There's no SQL command for that,
+-- so fake it with a manual update on pg_depend.
+--
+UPDATE pg_catalog.pg_depend
+SET deptype = 'a'
+WHERE classid = 'pg_catalog.pg_amproc'::pg_catalog.regclass
+ AND objid =
+ (SELECT objid
+ FROM pg_catalog.pg_depend
+ WHERE classid = 'pg_catalog.pg_amproc'::pg_catalog.regclass
+ AND refclassid = 'pg_catalog.pg_proc'::pg_catalog.regclass
+ AND (refobjid = 'g_cube_compress(pg_catalog.internal)'::pg_catalog.regprocedure))
+ AND refclassid = 'pg_catalog.pg_opclass'::pg_catalog.regclass
+ AND deptype = 'i';
+
+ALTER OPERATOR FAMILY gist_cube_ops USING gist drop function 3 (cube);
+ALTER EXTENSION cube DROP function g_cube_compress(pg_catalog.internal);
+DROP FUNCTION g_cube_compress(pg_catalog.internal);
+
+UPDATE pg_catalog.pg_depend
+SET deptype = 'a'
+WHERE classid = 'pg_catalog.pg_amproc'::pg_catalog.regclass
+ AND objid =
+ (SELECT objid
+ FROM pg_catalog.pg_depend
+ WHERE classid = 'pg_catalog.pg_amproc'::pg_catalog.regclass
+ AND refclassid = 'pg_catalog.pg_proc'::pg_catalog.regclass
+ AND (refobjid = 'g_cube_decompress(pg_catalog.internal)'::pg_catalog.regprocedure))
+ AND refclassid = 'pg_catalog.pg_opclass'::pg_catalog.regclass
+ AND deptype = 'i';
+
+ALTER OPERATOR FAMILY gist_cube_ops USING gist drop function 4 (cube);
+ALTER EXTENSION cube DROP function g_cube_decompress(pg_catalog.internal);
+DROP FUNCTION g_cube_decompress(pg_catalog.internal);
diff --git a/contrib/cube/cube.c b/contrib/cube/cube.c
index 149558c763..d96ca1ec1f 100644
--- a/contrib/cube/cube.c
+++ b/contrib/cube/cube.c
@@ -126,7 +126,7 @@ cube_in(PG_FUNCTION_ARGS)
cube_scanner_finish();
- PG_RETURN_NDBOX(result);
+ PG_RETURN_NDBOX_P(result);
}
@@ -187,7 +187,7 @@ cube_a_f8_f8(PG_FUNCTION_ARGS)
else
SET_POINT_BIT(result);
- PG_RETURN_NDBOX(result);
+ PG_RETURN_NDBOX_P(result);
}
/*
@@ -221,13 +221,13 @@ cube_a_f8(PG_FUNCTION_ARGS)
for (i = 0; i < dim; i++)
result->x[i] = dur[i];
- PG_RETURN_NDBOX(result);
+ PG_RETURN_NDBOX_P(result);
}
Datum
cube_subset(PG_FUNCTION_ARGS)
{
- NDBOX *c = PG_GETARG_NDBOX(0);
+ NDBOX *c = PG_GETARG_NDBOX_P(0);
ArrayType *idx = PG_GETARG_ARRAYTYPE_P(1);
NDBOX *result;
int size,
@@ -263,13 +263,13 @@ cube_subset(PG_FUNCTION_ARGS)
}
PG_FREE_IF_COPY(c, 0);
- PG_RETURN_NDBOX(result);
+ PG_RETURN_NDBOX_P(result);
}
Datum
cube_out(PG_FUNCTION_ARGS)
{
- NDBOX *cube = PG_GETARG_NDBOX(0);
+ NDBOX *cube = PG_GETARG_NDBOX_P(0);
StringInfoData buf;
int dim = DIM(cube);
int i;
@@ -309,14 +309,14 @@ cube_out(PG_FUNCTION_ARGS)
/*
** The GiST Consistent method for boxes
** Should return false if for all data items x below entry,
-** the predicate x op query == FALSE, where op is the oper
+** the predicate x op query == false, where op is the oper
** corresponding to strategy in the pg_amop table.
*/
Datum
g_cube_consistent(PG_FUNCTION_ARGS)
{
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- NDBOX *query = PG_GETARG_NDBOX(1);
+ NDBOX *query = PG_GETARG_NDBOX_P(1);
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
/* Oid subtype = PG_GETARG_OID(3); */
@@ -331,10 +331,10 @@ g_cube_consistent(PG_FUNCTION_ARGS)
* g_cube_leaf_consistent
*/
if (GIST_LEAF(entry))
- res = g_cube_leaf_consistent(DatumGetNDBOX(entry->key),
+ res = g_cube_leaf_consistent(DatumGetNDBOXP(entry->key),
query, strategy);
else
- res = g_cube_internal_consistent(DatumGetNDBOX(entry->key),
+ res = g_cube_internal_consistent(DatumGetNDBOXP(entry->key),
query, strategy);
PG_FREE_IF_COPY(query, 1);
@@ -355,7 +355,7 @@ g_cube_union(PG_FUNCTION_ARGS)
NDBOX *tmp;
int i;
- tmp = DatumGetNDBOX(entryvec->vector[0].key);
+ tmp = DatumGetNDBOXP(entryvec->vector[0].key);
/*
* sizep = sizeof(NDBOX); -- NDBOX has variable size
@@ -365,7 +365,7 @@ g_cube_union(PG_FUNCTION_ARGS)
for (i = 1; i < entryvec->n; i++)
{
out = g_cube_binary_union(tmp,
- DatumGetNDBOX(entryvec->vector[i].key),
+ DatumGetNDBOXP(entryvec->vector[i].key),
sizep);
tmp = out;
}
@@ -388,15 +388,15 @@ Datum
g_cube_decompress(PG_FUNCTION_ARGS)
{
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- NDBOX *key = DatumGetNDBOX(PG_DETOAST_DATUM(entry->key));
+ NDBOX *key = DatumGetNDBOXP(entry->key);
- if (key != DatumGetNDBOX(entry->key))
+ if (key != DatumGetNDBOXP(entry->key))
{
GISTENTRY *retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
gistentryinit(*retval, PointerGetDatum(key),
entry->rel, entry->page,
- entry->offset, FALSE);
+ entry->offset, false);
PG_RETURN_POINTER(retval);
}
PG_RETURN_POINTER(entry);
@@ -417,10 +417,10 @@ g_cube_penalty(PG_FUNCTION_ARGS)
double tmp1,
tmp2;
- ud = cube_union_v0(DatumGetNDBOX(origentry->key),
- DatumGetNDBOX(newentry->key));
+ ud = cube_union_v0(DatumGetNDBOXP(origentry->key),
+ DatumGetNDBOXP(newentry->key));
rt_cube_size(ud, &tmp1);
- rt_cube_size(DatumGetNDBOX(origentry->key), &tmp2);
+ rt_cube_size(DatumGetNDBOXP(origentry->key), &tmp2);
*result = (float) (tmp1 - tmp2);
PG_RETURN_FLOAT8(*result);
@@ -473,17 +473,18 @@ g_cube_picksplit(PG_FUNCTION_ARGS)
for (i = FirstOffsetNumber; i < maxoff; i = OffsetNumberNext(i))
{
- datum_alpha = DatumGetNDBOX(entryvec->vector[i].key);
+ datum_alpha = DatumGetNDBOXP(entryvec->vector[i].key);
for (j = OffsetNumberNext(i); j <= maxoff; j = OffsetNumberNext(j))
{
- datum_beta = DatumGetNDBOX(entryvec->vector[j].key);
+ datum_beta = DatumGetNDBOXP(entryvec->vector[j].key);
/* compute the wasted space by unioning these guys */
/* size_waste = size_union - size_inter; */
union_d = cube_union_v0(datum_alpha, datum_beta);
rt_cube_size(union_d, &size_union);
- inter_d = DatumGetNDBOX(DirectFunctionCall2(cube_inter,
- entryvec->vector[i].key, entryvec->vector[j].key));
+ inter_d = DatumGetNDBOXP(DirectFunctionCall2(cube_inter,
+ entryvec->vector[i].key,
+ entryvec->vector[j].key));
rt_cube_size(inter_d, &size_inter);
size_waste = size_union - size_inter;
@@ -506,10 +507,10 @@ g_cube_picksplit(PG_FUNCTION_ARGS)
right = v->spl_right;
v->spl_nright = 0;
- datum_alpha = DatumGetNDBOX(entryvec->vector[seed_1].key);
+ datum_alpha = DatumGetNDBOXP(entryvec->vector[seed_1].key);
datum_l = cube_union_v0(datum_alpha, datum_alpha);
rt_cube_size(datum_l, &size_l);
- datum_beta = DatumGetNDBOX(entryvec->vector[seed_2].key);
+ datum_beta = DatumGetNDBOXP(entryvec->vector[seed_2].key);
datum_r = cube_union_v0(datum_beta, datum_beta);
rt_cube_size(datum_r, &size_r);
@@ -548,7 +549,7 @@ g_cube_picksplit(PG_FUNCTION_ARGS)
}
/* okay, which page needs least enlargement? */
- datum_alpha = DatumGetNDBOX(entryvec->vector[i].key);
+ datum_alpha = DatumGetNDBOXP(entryvec->vector[i].key);
union_dl = cube_union_v0(datum_l, datum_alpha);
union_dr = cube_union_v0(datum_r, datum_alpha);
rt_cube_size(union_dl, &size_alpha);
@@ -584,16 +585,16 @@ g_cube_picksplit(PG_FUNCTION_ARGS)
Datum
g_cube_same(PG_FUNCTION_ARGS)
{
- NDBOX *b1 = PG_GETARG_NDBOX(0);
- NDBOX *b2 = PG_GETARG_NDBOX(1);
+ NDBOX *b1 = PG_GETARG_NDBOX_P(0);
+ NDBOX *b2 = PG_GETARG_NDBOX_P(1);
bool *result = (bool *) PG_GETARG_POINTER(2);
if (cube_cmp_v0(b1, b2) == 0)
- *result = TRUE;
+ *result = true;
else
- *result = FALSE;
+ *result = false;
- PG_RETURN_NDBOX(result);
+ PG_RETURN_NDBOX_P(result);
}
/*
@@ -609,23 +610,23 @@ g_cube_leaf_consistent(NDBOX *key,
switch (strategy)
{
case RTOverlapStrategyNumber:
- retval = (bool) cube_overlap_v0(key, query);
+ retval = cube_overlap_v0(key, query);
break;
case RTSameStrategyNumber:
- retval = (bool) (cube_cmp_v0(key, query) == 0);
+ retval = (cube_cmp_v0(key, query) == 0);
break;
case RTContainsStrategyNumber:
case RTOldContainsStrategyNumber:
- retval = (bool) cube_contains_v0(key, query);
+ retval = cube_contains_v0(key, query);
break;
case RTContainedByStrategyNumber:
case RTOldContainedByStrategyNumber:
- retval = (bool) cube_contains_v0(query, key);
+ retval = cube_contains_v0(query, key);
break;
default:
- retval = FALSE;
+ retval = false;
}
- return (retval);
+ return retval;
}
bool
@@ -650,9 +651,9 @@ g_cube_internal_consistent(NDBOX *key,
retval = (bool) cube_overlap_v0(key, query);
break;
default:
- retval = FALSE;
+ retval = false;
}
- return (retval);
+ return retval;
}
NDBOX *
@@ -663,7 +664,7 @@ g_cube_binary_union(NDBOX *r1, NDBOX *r2, int *sizep)
retval = cube_union_v0(r1, r2);
*sizep = VARSIZE(retval);
- return (retval);
+ return retval;
}
@@ -729,29 +730,29 @@ cube_union_v0(NDBOX *a, NDBOX *b)
SET_POINT_BIT(result);
}
- return (result);
+ return result;
}
Datum
cube_union(PG_FUNCTION_ARGS)
{
- NDBOX *a = PG_GETARG_NDBOX(0);
- NDBOX *b = PG_GETARG_NDBOX(1);
+ NDBOX *a = PG_GETARG_NDBOX_P(0);
+ NDBOX *b = PG_GETARG_NDBOX_P(1);
NDBOX *res;
res = cube_union_v0(a, b);
PG_FREE_IF_COPY(a, 0);
PG_FREE_IF_COPY(b, 1);
- PG_RETURN_NDBOX(res);
+ PG_RETURN_NDBOX_P(res);
}
/* cube_inter */
Datum
cube_inter(PG_FUNCTION_ARGS)
{
- NDBOX *a = PG_GETARG_NDBOX(0);
- NDBOX *b = PG_GETARG_NDBOX(1);
+ NDBOX *a = PG_GETARG_NDBOX_P(0);
+ NDBOX *b = PG_GETARG_NDBOX_P(1);
NDBOX *result;
bool swapped = false;
int i;
@@ -823,14 +824,14 @@ cube_inter(PG_FUNCTION_ARGS)
/*
* Is it OK to return a non-null intersection for non-overlapping boxes?
*/
- PG_RETURN_NDBOX(result);
+ PG_RETURN_NDBOX_P(result);
}
/* cube_size */
Datum
cube_size(PG_FUNCTION_ARGS)
{
- NDBOX *a = PG_GETARG_NDBOX(0);
+ NDBOX *a = PG_GETARG_NDBOX_P(0);
double result;
rt_cube_size(a, &result);
@@ -948,8 +949,8 @@ cube_cmp_v0(NDBOX *a, NDBOX *b)
Datum
cube_cmp(PG_FUNCTION_ARGS)
{
- NDBOX *a = PG_GETARG_NDBOX(0),
- *b = PG_GETARG_NDBOX(1);
+ NDBOX *a = PG_GETARG_NDBOX_P(0),
+ *b = PG_GETARG_NDBOX_P(1);
int32 res;
res = cube_cmp_v0(a, b);
@@ -963,8 +964,8 @@ cube_cmp(PG_FUNCTION_ARGS)
Datum
cube_eq(PG_FUNCTION_ARGS)
{
- NDBOX *a = PG_GETARG_NDBOX(0),
- *b = PG_GETARG_NDBOX(1);
+ NDBOX *a = PG_GETARG_NDBOX_P(0),
+ *b = PG_GETARG_NDBOX_P(1);
int32 res;
res = cube_cmp_v0(a, b);
@@ -978,8 +979,8 @@ cube_eq(PG_FUNCTION_ARGS)
Datum
cube_ne(PG_FUNCTION_ARGS)
{
- NDBOX *a = PG_GETARG_NDBOX(0),
- *b = PG_GETARG_NDBOX(1);
+ NDBOX *a = PG_GETARG_NDBOX_P(0),
+ *b = PG_GETARG_NDBOX_P(1);
int32 res;
res = cube_cmp_v0(a, b);
@@ -993,8 +994,8 @@ cube_ne(PG_FUNCTION_ARGS)
Datum
cube_lt(PG_FUNCTION_ARGS)
{
- NDBOX *a = PG_GETARG_NDBOX(0),
- *b = PG_GETARG_NDBOX(1);
+ NDBOX *a = PG_GETARG_NDBOX_P(0),
+ *b = PG_GETARG_NDBOX_P(1);
int32 res;
res = cube_cmp_v0(a, b);
@@ -1008,8 +1009,8 @@ cube_lt(PG_FUNCTION_ARGS)
Datum
cube_gt(PG_FUNCTION_ARGS)
{
- NDBOX *a = PG_GETARG_NDBOX(0),
- *b = PG_GETARG_NDBOX(1);
+ NDBOX *a = PG_GETARG_NDBOX_P(0),
+ *b = PG_GETARG_NDBOX_P(1);
int32 res;
res = cube_cmp_v0(a, b);
@@ -1023,8 +1024,8 @@ cube_gt(PG_FUNCTION_ARGS)
Datum
cube_le(PG_FUNCTION_ARGS)
{
- NDBOX *a = PG_GETARG_NDBOX(0),
- *b = PG_GETARG_NDBOX(1);
+ NDBOX *a = PG_GETARG_NDBOX_P(0),
+ *b = PG_GETARG_NDBOX_P(1);
int32 res;
res = cube_cmp_v0(a, b);
@@ -1038,8 +1039,8 @@ cube_le(PG_FUNCTION_ARGS)
Datum
cube_ge(PG_FUNCTION_ARGS)
{
- NDBOX *a = PG_GETARG_NDBOX(0),
- *b = PG_GETARG_NDBOX(1);
+ NDBOX *a = PG_GETARG_NDBOX_P(0),
+ *b = PG_GETARG_NDBOX_P(1);
int32 res;
res = cube_cmp_v0(a, b);
@@ -1058,7 +1059,7 @@ cube_contains_v0(NDBOX *a, NDBOX *b)
int i;
if ((a == NULL) || (b == NULL))
- return (FALSE);
+ return false;
if (DIM(a) < DIM(b))
{
@@ -1070,9 +1071,9 @@ cube_contains_v0(NDBOX *a, NDBOX *b)
for (i = DIM(a); i < DIM(b); i++)
{
if (LL_COORD(b, i) != 0)
- return (FALSE);
+ return false;
if (UR_COORD(b, i) != 0)
- return (FALSE);
+ return false;
}
}
@@ -1081,20 +1082,20 @@ cube_contains_v0(NDBOX *a, NDBOX *b)
{
if (Min(LL_COORD(a, i), UR_COORD(a, i)) >
Min(LL_COORD(b, i), UR_COORD(b, i)))
- return (FALSE);
+ return false;
if (Max(LL_COORD(a, i), UR_COORD(a, i)) <
Max(LL_COORD(b, i), UR_COORD(b, i)))
- return (FALSE);
+ return false;
}
- return (TRUE);
+ return true;
}
Datum
cube_contains(PG_FUNCTION_ARGS)
{
- NDBOX *a = PG_GETARG_NDBOX(0),
- *b = PG_GETARG_NDBOX(1);
+ NDBOX *a = PG_GETARG_NDBOX_P(0),
+ *b = PG_GETARG_NDBOX_P(1);
bool res;
res = cube_contains_v0(a, b);
@@ -1109,8 +1110,8 @@ cube_contains(PG_FUNCTION_ARGS)
Datum
cube_contained(PG_FUNCTION_ARGS)
{
- NDBOX *a = PG_GETARG_NDBOX(0),
- *b = PG_GETARG_NDBOX(1);
+ NDBOX *a = PG_GETARG_NDBOX_P(0),
+ *b = PG_GETARG_NDBOX_P(1);
bool res;
res = cube_contains_v0(b, a);
@@ -1128,7 +1129,7 @@ cube_overlap_v0(NDBOX *a, NDBOX *b)
int i;
if ((a == NULL) || (b == NULL))
- return (FALSE);
+ return false;
/* swap the box pointers if needed */
if (DIM(a) < DIM(b))
@@ -1143,29 +1144,29 @@ cube_overlap_v0(NDBOX *a, NDBOX *b)
for (i = 0; i < DIM(b); i++)
{
if (Min(LL_COORD(a, i), UR_COORD(a, i)) > Max(LL_COORD(b, i), UR_COORD(b, i)))
- return (FALSE);
+ return false;
if (Max(LL_COORD(a, i), UR_COORD(a, i)) < Min(LL_COORD(b, i), UR_COORD(b, i)))
- return (FALSE);
+ return false;
}
/* compare to zero those dimensions in (a) absent in (b) */
for (i = DIM(b); i < DIM(a); i++)
{
if (Min(LL_COORD(a, i), UR_COORD(a, i)) > 0)
- return (FALSE);
+ return false;
if (Max(LL_COORD(a, i), UR_COORD(a, i)) < 0)
- return (FALSE);
+ return false;
}
- return (TRUE);
+ return true;
}
Datum
cube_overlap(PG_FUNCTION_ARGS)
{
- NDBOX *a = PG_GETARG_NDBOX(0),
- *b = PG_GETARG_NDBOX(1);
+ NDBOX *a = PG_GETARG_NDBOX_P(0),
+ *b = PG_GETARG_NDBOX_P(1);
bool res;
res = cube_overlap_v0(a, b);
@@ -1184,8 +1185,8 @@ cube_overlap(PG_FUNCTION_ARGS)
Datum
cube_distance(PG_FUNCTION_ARGS)
{
- NDBOX *a = PG_GETARG_NDBOX(0),
- *b = PG_GETARG_NDBOX(1);
+ NDBOX *a = PG_GETARG_NDBOX_P(0),
+ *b = PG_GETARG_NDBOX_P(1);
bool swapped = false;
double d,
distance;
@@ -1233,8 +1234,8 @@ cube_distance(PG_FUNCTION_ARGS)
Datum
distance_taxicab(PG_FUNCTION_ARGS)
{
- NDBOX *a = PG_GETARG_NDBOX(0),
- *b = PG_GETARG_NDBOX(1);
+ NDBOX *a = PG_GETARG_NDBOX_P(0),
+ *b = PG_GETARG_NDBOX_P(1);
bool swapped = false;
double distance;
int i;
@@ -1277,8 +1278,8 @@ distance_taxicab(PG_FUNCTION_ARGS)
Datum
distance_chebyshev(PG_FUNCTION_ARGS)
{
- NDBOX *a = PG_GETARG_NDBOX(0),
- *b = PG_GETARG_NDBOX(1);
+ NDBOX *a = PG_GETARG_NDBOX_P(0),
+ *b = PG_GETARG_NDBOX_P(1);
bool swapped = false;
double d,
distance;
@@ -1331,24 +1332,81 @@ g_cube_distance(PG_FUNCTION_ARGS)
{
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
- NDBOX *cube = DatumGetNDBOX(entry->key);
+ NDBOX *cube = DatumGetNDBOXP(entry->key);
double retval;
if (strategy == CubeKNNDistanceCoord)
{
+ /*
+ * Handle ordering by ~> operator. See comments of cube_coord_llur()
+ * for details
+ */
int coord = PG_GETARG_INT32(1);
+ bool isLeaf = GistPageIsLeaf(entry->page);
+ bool inverse = false;
- if (DIM(cube) == 0)
- retval = 0.0;
- else if (IS_POINT(cube))
- retval = cube->x[(coord - 1) % DIM(cube)];
+ /* 0 is the only unsupported coordinate value */
+ if (coord == 0)
+ ereport(ERROR,
+ (errcode(ERRCODE_ARRAY_ELEMENT_ERROR),
+ errmsg("zero cube index is not defined")));
+
+ /* Return inversed value for negative coordinate */
+ if (coord < 0)
+ {
+ coord = -coord;
+ inverse = true;
+ }
+
+ if (coord <= 2 * DIM(cube))
+ {
+ /* dimension index */
+ int index = (coord - 1) / 2;
+ /* whether this is upper bound (lower bound otherwise) */
+ bool upper = ((coord - 1) % 2 == 1);
+
+ if (IS_POINT(cube))
+ {
+ retval = cube->x[index];
+ }
+ else
+ {
+ if (isLeaf)
+ {
+ /* For leaf just return required upper/lower bound */
+ if (upper)
+ retval = Max(cube->x[index], cube->x[index + DIM(cube)]);
+ else
+ retval = Min(cube->x[index], cube->x[index + DIM(cube)]);
+ }
+ else
+ {
+ /*
+ * For non-leaf we should always return lower bound,
+ * because even upper bound of a child in the subtree can
+ * be as small as our lower bound. For inversed case we
+ * return upper bound because it becomes lower bound for
+ * inversed value.
+ */
+ if (!inverse)
+ retval = Min(cube->x[index], cube->x[index + DIM(cube)]);
+ else
+ retval = Max(cube->x[index], cube->x[index + DIM(cube)]);
+ }
+ }
+ }
else
- retval = Min(cube->x[(coord - 1) % DIM(cube)],
- cube->x[(coord - 1) % DIM(cube) + DIM(cube)]);
+ {
+ retval = 0.0;
+ }
+
+ /* Inverse return value if needed */
+ if (inverse)
+ retval = -retval;
}
else
{
- NDBOX *query = PG_GETARG_NDBOX(1);
+ NDBOX *query = PG_GETARG_NDBOX_P(1);
switch (strategy)
{
@@ -1385,14 +1443,14 @@ distance_1D(double a1, double a2, double b1, double b2)
return (Min(a1, a2) - Max(b1, b2));
/* the rest are all sorts of intersections */
- return (0.0);
+ return 0.0;
}
/* Test if a box is also a point */
Datum
cube_is_point(PG_FUNCTION_ARGS)
{
- NDBOX *cube = PG_GETARG_NDBOX(0);
+ NDBOX *cube = PG_GETARG_NDBOX_P(0);
bool result;
result = cube_is_point_internal(cube);
@@ -1427,7 +1485,7 @@ cube_is_point_internal(NDBOX *cube)
Datum
cube_dim(PG_FUNCTION_ARGS)
{
- NDBOX *c = PG_GETARG_NDBOX(0);
+ NDBOX *c = PG_GETARG_NDBOX_P(0);
int dim = DIM(c);
PG_FREE_IF_COPY(c, 0);
@@ -1438,7 +1496,7 @@ cube_dim(PG_FUNCTION_ARGS)
Datum
cube_ll_coord(PG_FUNCTION_ARGS)
{
- NDBOX *c = PG_GETARG_NDBOX(0);
+ NDBOX *c = PG_GETARG_NDBOX_P(0);
int n = PG_GETARG_INT32(1);
double result;
@@ -1455,7 +1513,7 @@ cube_ll_coord(PG_FUNCTION_ARGS)
Datum
cube_ur_coord(PG_FUNCTION_ARGS)
{
- NDBOX *c = PG_GETARG_NDBOX(0);
+ NDBOX *c = PG_GETARG_NDBOX_P(0);
int n = PG_GETARG_INT32(1);
double result;
@@ -1476,7 +1534,7 @@ cube_ur_coord(PG_FUNCTION_ARGS)
Datum
cube_coord(PG_FUNCTION_ARGS)
{
- NDBOX *cube = PG_GETARG_NDBOX(0);
+ NDBOX *cube = PG_GETARG_NDBOX_P(0);
int coord = PG_GETARG_INT32(1);
if (coord <= 0 || coord > 2 * DIM(cube))
@@ -1491,50 +1549,91 @@ cube_coord(PG_FUNCTION_ARGS)
}
-/*
- * This function works like cube_coord(),
- * but rearranges coordinates of corners to get cube representation
- * in the form of (lower left, upper right).
- * For historical reasons that extension allows us to create cubes in form
- * ((2,1),(1,2)) and instead of normalizing such cube to ((1,1),(2,2)) it
- * stores cube in original way. But to get cubes ordered by one of dimensions
- * directly from the index without extra sort step we need some
- * representation-independent coordinate getter. This function implements it.
+/*----
+ * This function works like cube_coord(), but rearranges coordinates in the
+ * way suitable to support coordinate ordering using KNN-GiST. For historical
+ * reasons this extension allows us to create cubes in form ((2,1),(1,2)) and
+ * instead of normalizing such cube to ((1,1),(2,2)) it stores cube in original
+ * way. But in order to get cubes ordered by one of dimensions from the index
+ * without explicit sort step we need this representation-independent coordinate
+ * getter. Moreover, indexed dataset may contain cubes of different dimensions
+ * number. Accordingly, this coordinate getter should be able to return
+ * lower/upper bound for particular dimension independently on number of cube
+ * dimensions. Also, KNN-GiST supports only ascending sorting. In order to
+ * support descending sorting, this function returns inverse of value when
+ * negative coordinate is given.
+ *
+ * Long story short, this function uses following meaning of coordinates:
+ * # (2 * N - 1) -- lower bound of Nth dimension,
+ * # (2 * N) -- upper bound of Nth dimension,
+ * # - (2 * N - 1) -- negative of lower bound of Nth dimension,
+ * # - (2 * N) -- negative of upper bound of Nth dimension.
+ *
+ * When given coordinate exceeds number of cube dimensions, then 0 returned
+ * (reproducing logic of GiST indexing of variable-length cubes).
*/
Datum
cube_coord_llur(PG_FUNCTION_ARGS)
{
- NDBOX *cube = PG_GETARG_NDBOX(0);
+ NDBOX *cube = PG_GETARG_NDBOX_P(0);
int coord = PG_GETARG_INT32(1);
+ bool inverse = false;
+ float8 result;
- if (coord <= 0 || coord > 2 * DIM(cube))
+ /* 0 is the only unsupported coordinate value */
+ if (coord == 0)
ereport(ERROR,
(errcode(ERRCODE_ARRAY_ELEMENT_ERROR),
- errmsg("cube index %d is out of bounds", coord)));
+ errmsg("zero cube index is not defined")));
+
+ /* Return inversed value for negative coordinate */
+ if (coord < 0)
+ {
+ coord = -coord;
+ inverse = true;
+ }
- if (coord <= DIM(cube))
+ if (coord <= 2 * DIM(cube))
{
+ /* dimension index */
+ int index = (coord - 1) / 2;
+ /* whether this is upper bound (lower bound otherwise) */
+ bool upper = ((coord - 1) % 2 == 1);
+
if (IS_POINT(cube))
- PG_RETURN_FLOAT8(cube->x[coord - 1]);
+ {
+ result = cube->x[index];
+ }
else
- PG_RETURN_FLOAT8(Min(cube->x[coord - 1],
- cube->x[coord - 1 + DIM(cube)]));
+ {
+ if (upper)
+ result = Max(cube->x[index], cube->x[index + DIM(cube)]);
+ else
+ result = Min(cube->x[index], cube->x[index + DIM(cube)]);
+ }
}
else
{
- if (IS_POINT(cube))
- PG_RETURN_FLOAT8(cube->x[(coord - 1) % DIM(cube)]);
- else
- PG_RETURN_FLOAT8(Max(cube->x[coord - 1],
- cube->x[coord - 1 - DIM(cube)]));
+ /*
+ * Return zero if coordinate is out of bound. That reproduces logic of
+ * how cubes with low dimension number are expanded during GiST
+ * indexing.
+ */
+ result = 0.0;
}
+
+ /* Inverse value if needed */
+ if (inverse)
+ result = -result;
+
+ PG_RETURN_FLOAT8(result);
}
/* Increase or decrease box size by a radius in at least n dimensions. */
Datum
cube_enlarge(PG_FUNCTION_ARGS)
{
- NDBOX *a = PG_GETARG_NDBOX(0);
+ NDBOX *a = PG_GETARG_NDBOX_P(0);
double r = PG_GETARG_FLOAT8(1);
int32 n = PG_GETARG_INT32(2);
NDBOX *result;
@@ -1592,7 +1691,7 @@ cube_enlarge(PG_FUNCTION_ARGS)
}
PG_FREE_IF_COPY(a, 0);
- PG_RETURN_NDBOX(result);
+ PG_RETURN_NDBOX_P(result);
}
/* Create a one dimensional box with identical upper and lower coordinates */
@@ -1610,7 +1709,7 @@ cube_f8(PG_FUNCTION_ARGS)
SET_POINT_BIT(result);
result->x[0] = x;
- PG_RETURN_NDBOX(result);
+ PG_RETURN_NDBOX_P(result);
}
/* Create a one dimensional box */
@@ -1641,7 +1740,7 @@ cube_f8_f8(PG_FUNCTION_ARGS)
result->x[1] = x1;
}
- PG_RETURN_NDBOX(result);
+ PG_RETURN_NDBOX_P(result);
}
/* Add a dimension to an existing cube with the same values for the new
@@ -1649,7 +1748,7 @@ cube_f8_f8(PG_FUNCTION_ARGS)
Datum
cube_c_f8(PG_FUNCTION_ARGS)
{
- NDBOX *cube = PG_GETARG_NDBOX(0);
+ NDBOX *cube = PG_GETARG_NDBOX_P(0);
double x = PG_GETARG_FLOAT8(1);
NDBOX *result;
int size;
@@ -1682,14 +1781,14 @@ cube_c_f8(PG_FUNCTION_ARGS)
}
PG_FREE_IF_COPY(cube, 0);
- PG_RETURN_NDBOX(result);
+ PG_RETURN_NDBOX_P(result);
}
/* Add a dimension to an existing cube */
Datum
cube_c_f8_f8(PG_FUNCTION_ARGS)
{
- NDBOX *cube = PG_GETARG_NDBOX(0);
+ NDBOX *cube = PG_GETARG_NDBOX_P(0);
double x1 = PG_GETARG_FLOAT8(1);
double x2 = PG_GETARG_FLOAT8(2);
NDBOX *result;
@@ -1723,5 +1822,5 @@ cube_c_f8_f8(PG_FUNCTION_ARGS)
}
PG_FREE_IF_COPY(cube, 0);
- PG_RETURN_NDBOX(result);
+ PG_RETURN_NDBOX_P(result);
}
diff --git a/contrib/cube/cube.control b/contrib/cube/cube.control
index b03cfa0a58..f39a838e3f 100644
--- a/contrib/cube/cube.control
+++ b/contrib/cube/cube.control
@@ -1,5 +1,5 @@
# cube extension
comment = 'data type for multidimensional cubes'
-default_version = '1.2'
+default_version = '1.4'
module_pathname = '$libdir/cube'
relocatable = true
diff --git a/contrib/cube/cubedata.h b/contrib/cube/cubedata.h
index 6e6ddfd3d7..dbe7d4f742 100644
--- a/contrib/cube/cubedata.h
+++ b/contrib/cube/cubedata.h
@@ -49,9 +49,9 @@ typedef struct NDBOX
#define CUBE_SIZE(_dim) (offsetof(NDBOX, x) + sizeof(double)*(_dim)*2)
/* fmgr interface macros */
-#define DatumGetNDBOX(x) ((NDBOX *) PG_DETOAST_DATUM(x))
-#define PG_GETARG_NDBOX(x) DatumGetNDBOX(PG_GETARG_DATUM(x))
-#define PG_RETURN_NDBOX(x) PG_RETURN_POINTER(x)
+#define DatumGetNDBOXP(x) ((NDBOX *) PG_DETOAST_DATUM(x))
+#define PG_GETARG_NDBOX_P(x) DatumGetNDBOXP(PG_GETARG_DATUM(x))
+#define PG_RETURN_NDBOX_P(x) PG_RETURN_POINTER(x)
/* GiST operator strategy numbers */
#define CubeKNNDistanceCoord 15 /* ~> */
diff --git a/contrib/cube/cubescan.l b/contrib/cube/cubescan.l
index dada917820..bd400e3684 100644
--- a/contrib/cube/cubescan.l
+++ b/contrib/cube/cubescan.l
@@ -4,6 +4,8 @@
* contrib/cube/cubescan.l
*/
+/* LCOV_EXCL_START */
+
/* No reason to constrain amount of data slurped */
#define YY_READ_BUF_SIZE 16777216
@@ -56,6 +58,8 @@ NaN [nN][aA][nN]
%%
+/* LCOV_EXCL_STOP */
+
/* result is not used, but Bison expects this signature */
void
yyerror(NDBOX **result, const char *message)
diff --git a/contrib/cube/expected/cube.out b/contrib/cube/expected/cube.out
index 328b3b5f5d..6378db3004 100644
--- a/contrib/cube/expected/cube.out
+++ b/contrib/cube/expected/cube.out
@@ -1532,37 +1532,41 @@ SELECT cube(array[40,50,60], array[10,20,30])~>1;
SELECT cube(array[10,20,30], array[40,50,60])~>2;
?column?
----------
- 20
+ 40
(1 row)
SELECT cube(array[40,50,60], array[10,20,30])~>2;
?column?
----------
- 20
+ 40
(1 row)
SELECT cube(array[10,20,30], array[40,50,60])~>3;
?column?
----------
- 30
+ 20
(1 row)
SELECT cube(array[40,50,60], array[10,20,30])~>3;
?column?
----------
- 30
+ 20
(1 row)
SELECT cube(array[40,50,60], array[10,20,30])~>0;
-ERROR: cube index 0 is out of bounds
+ERROR: zero cube index is not defined
SELECT cube(array[40,50,60], array[10,20,30])~>4;
?column?
----------
- 40
+ 50
(1 row)
SELECT cube(array[40,50,60], array[10,20,30])~>(-1);
-ERROR: cube index -1 is out of bounds
+ ?column?
+----------
+ -10
+(1 row)
+
-- Load some example data and build the index
--
CREATE TABLE test_cube (c cube);
@@ -1589,159 +1593,414 @@ SELECT * FROM test_cube WHERE c && '(3000,1000),(0,0)' GROUP BY c ORDER BY c;
(2424, 160),(2424, 81)
(5 rows)
--- kNN with index
+-- Test index-only scans
+SET enable_bitmapscan = false;
+EXPLAIN (COSTS OFF)
+SELECT c FROM test_cube WHERE c <@ '(3000,1000),(0,0)' ORDER BY c;
+ QUERY PLAN
+--------------------------------------------------------
+ Sort
+ Sort Key: c
+ -> Index Only Scan using test_cube_ix on test_cube
+ Index Cond: (c <@ '(3000, 1000),(0, 0)'::cube)
+(4 rows)
+
+SELECT c FROM test_cube WHERE c <@ '(3000,1000),(0,0)' ORDER BY c;
+ c
+-------------------------
+ (337, 455),(240, 359)
+ (759, 187),(662, 163)
+ (1444, 403),(1346, 344)
+ (2424, 160),(2424, 81)
+(4 rows)
+
+RESET enable_bitmapscan;
+-- Test kNN
+INSERT INTO test_cube VALUES ('(1,1)'), ('(100000)'), ('(0, 100000)'); -- Some corner cases
+SET enable_seqscan = false;
+-- Test different metrics
SELECT *, c <-> '(100, 100),(500, 500)'::cube as dist FROM test_cube ORDER BY c <-> '(100, 100),(500, 500)'::cube LIMIT 5;
c | dist
-------------------------+------------------
(337, 455),(240, 359) | 0
+ (1, 1) | 140.007142674936
(759, 187),(662, 163) | 162
(948, 1201),(907, 1156) | 772.000647668122
(1444, 403),(1346, 344) | 846
- (369, 1457),(278, 1409) | 909
(5 rows)
SELECT *, c <=> '(100, 100),(500, 500)'::cube as dist FROM test_cube ORDER BY c <=> '(100, 100),(500, 500)'::cube LIMIT 5;
c | dist
-------------------------+------
(337, 455),(240, 359) | 0
+ (1, 1) | 99
(759, 187),(662, 163) | 162
(948, 1201),(907, 1156) | 656
(1444, 403),(1346, 344) | 846
+(5 rows)
+
+SELECT *, c <#> '(100, 100),(500, 500)'::cube as dist FROM test_cube ORDER BY c <#> '(100, 100),(500, 500)'::cube LIMIT 5;
+ c | dist
+-------------------------+------
+ (337, 455),(240, 359) | 0
+ (759, 187),(662, 163) | 162
+ (1, 1) | 198
+ (1444, 403),(1346, 344) | 846
(369, 1457),(278, 1409) | 909
(5 rows)
+-- Test sorting by coordinates
+SELECT c~>1, c FROM test_cube ORDER BY c~>1 LIMIT 15; -- ascending by left bound
+ ?column? | c
+----------+---------------------------
+ 0 | (0, 100000)
+ 1 | (1, 1)
+ 3 | (54, 38679),(3, 38602)
+ 15 | (83, 10271),(15, 10265)
+ 64 | (122, 46832),(64, 46762)
+ 92 | (167, 17214),(92, 17184)
+ 107 | (161, 24465),(107, 24374)
+ 120 | (162, 26040),(120, 25963)
+ 138 | (154, 4019),(138, 3990)
+ 175 | (259, 1850),(175, 1820)
+ 179 | (207, 40886),(179, 40879)
+ 204 | (288, 49588),(204, 49571)
+ 226 | (270, 32616),(226, 32607)
+ 235 | (318, 31489),(235, 31404)
+ 240 | (337, 455),(240, 359)
+(15 rows)
+
+SELECT c~>2, c FROM test_cube ORDER BY c~>2 LIMIT 15; -- ascending by right bound
+ ?column? | c
+----------+---------------------------
+ 0 | (0, 100000)
+ 1 | (1, 1)
+ 54 | (54, 38679),(3, 38602)
+ 83 | (83, 10271),(15, 10265)
+ 122 | (122, 46832),(64, 46762)
+ 154 | (154, 4019),(138, 3990)
+ 161 | (161, 24465),(107, 24374)
+ 162 | (162, 26040),(120, 25963)
+ 167 | (167, 17214),(92, 17184)
+ 207 | (207, 40886),(179, 40879)
+ 259 | (259, 1850),(175, 1820)
+ 270 | (270, 29508),(264, 29440)
+ 270 | (270, 32616),(226, 32607)
+ 288 | (288, 49588),(204, 49571)
+ 318 | (318, 31489),(235, 31404)
+(15 rows)
+
+SELECT c~>3, c FROM test_cube ORDER BY c~>3 LIMIT 15; -- ascending by lower bound
+ ?column? | c
+----------+---------------------------
+ 0 | (100000)
+ 1 | (1, 1)
+ 6 | (30333, 50),(30273, 6)
+ 43 | (43301, 75),(43227, 43)
+ 51 | (19650, 142),(19630, 51)
+ 81 | (2424, 160),(2424, 81)
+ 108 | (3449, 171),(3354, 108)
+ 109 | (18037, 155),(17941, 109)
+ 114 | (28511, 208),(28479, 114)
+ 118 | (19946, 217),(19941, 118)
+ 139 | (16906, 191),(16816, 139)
+ 163 | (759, 187),(662, 163)
+ 181 | (22684, 266),(22656, 181)
+ 213 | (24423, 255),(24360, 213)
+ 222 | (45989, 249),(45910, 222)
+(15 rows)
+
+SELECT c~>4, c FROM test_cube ORDER BY c~>4 LIMIT 15; -- ascending by upper bound
+ ?column? | c
+----------+---------------------------
+ 0 | (100000)
+ 1 | (1, 1)
+ 50 | (30333, 50),(30273, 6)
+ 75 | (43301, 75),(43227, 43)
+ 142 | (19650, 142),(19630, 51)
+ 155 | (18037, 155),(17941, 109)
+ 160 | (2424, 160),(2424, 81)
+ 171 | (3449, 171),(3354, 108)
+ 187 | (759, 187),(662, 163)
+ 191 | (16906, 191),(16816, 139)
+ 208 | (28511, 208),(28479, 114)
+ 217 | (19946, 217),(19941, 118)
+ 249 | (45989, 249),(45910, 222)
+ 255 | (24423, 255),(24360, 213)
+ 266 | (22684, 266),(22656, 181)
+(15 rows)
+
+SELECT c~>(-1), c FROM test_cube ORDER BY c~>(-1) LIMIT 15; -- descending by left bound
+ ?column? | c
+----------+-------------------------------
+ -100000 | (100000)
+ -49951 | (50027, 49230),(49951, 49214)
+ -49937 | (49980, 35004),(49937, 34963)
+ -49927 | (49985, 6436),(49927, 6338)
+ -49908 | (49999, 27218),(49908, 27176)
+ -49905 | (49954, 1340),(49905, 1294)
+ -49902 | (49944, 25163),(49902, 25153)
+ -49898 | (49981, 34876),(49898, 34786)
+ -49897 | (49957, 43390),(49897, 43384)
+ -49848 | (49853, 18504),(49848, 18503)
+ -49818 | (49902, 41752),(49818, 41746)
+ -49810 | (49907, 30225),(49810, 30158)
+ -49808 | (49843, 5175),(49808, 5145)
+ -49805 | (49887, 24274),(49805, 24184)
+ -49798 | (49847, 7128),(49798, 7067)
+(15 rows)
+
+SELECT c~>(-2), c FROM test_cube ORDER BY c~>(-2) LIMIT 15; -- descending by right bound
+ ?column? | c
+----------+-------------------------------
+ -100000 | (100000)
+ -50027 | (50027, 49230),(49951, 49214)
+ -49999 | (49999, 27218),(49908, 27176)
+ -49985 | (49985, 6436),(49927, 6338)
+ -49981 | (49981, 34876),(49898, 34786)
+ -49980 | (49980, 35004),(49937, 34963)
+ -49957 | (49957, 43390),(49897, 43384)
+ -49954 | (49954, 1340),(49905, 1294)
+ -49944 | (49944, 25163),(49902, 25153)
+ -49907 | (49907, 30225),(49810, 30158)
+ -49902 | (49902, 41752),(49818, 41746)
+ -49887 | (49887, 24274),(49805, 24184)
+ -49853 | (49853, 18504),(49848, 18503)
+ -49847 | (49847, 7128),(49798, 7067)
+ -49843 | (49843, 5175),(49808, 5145)
+(15 rows)
+
+SELECT c~>(-3), c FROM test_cube ORDER BY c~>(-3) LIMIT 15; -- descending by lower bound
+ ?column? | c
+----------+-------------------------------
+ -100000 | (0, 100000)
+ -49992 | (30746, 50040),(30727, 49992)
+ -49987 | (36311, 50073),(36258, 49987)
+ -49934 | (3531, 49962),(3463, 49934)
+ -49915 | (17954, 49975),(17865, 49915)
+ -49914 | (2168, 50012),(2108, 49914)
+ -49913 | (31287, 49923),(31236, 49913)
+ -49885 | (21551, 49983),(21492, 49885)
+ -49878 | (43925, 49912),(43888, 49878)
+ -49849 | (19128, 49932),(19112, 49849)
+ -49844 | (38266, 49852),(38233, 49844)
+ -49836 | (14913, 49873),(14849, 49836)
+ -49834 | (37595, 49849),(37581, 49834)
+ -49830 | (46151, 49848),(46058, 49830)
+ -49818 | (29261, 49910),(29247, 49818)
+(15 rows)
+
+SELECT c~>(-4), c FROM test_cube ORDER BY c~>(-4) LIMIT 15; -- descending by upper bound
+ ?column? | c
+----------+-------------------------------
+ -100000 | (0, 100000)
+ -50073 | (36311, 50073),(36258, 49987)
+ -50040 | (30746, 50040),(30727, 49992)
+ -50012 | (2168, 50012),(2108, 49914)
+ -49983 | (21551, 49983),(21492, 49885)
+ -49975 | (17954, 49975),(17865, 49915)
+ -49962 | (3531, 49962),(3463, 49934)
+ -49932 | (19128, 49932),(19112, 49849)
+ -49923 | (31287, 49923),(31236, 49913)
+ -49912 | (43925, 49912),(43888, 49878)
+ -49910 | (29261, 49910),(29247, 49818)
+ -49873 | (14913, 49873),(14849, 49836)
+ -49858 | (20007, 49858),(19921, 49778)
+ -49852 | (38266, 49852),(38233, 49844)
+ -49849 | (37595, 49849),(37581, 49834)
+(15 rows)
+
+-- Same queries with sequential scan (should give the same results as above)
+RESET enable_seqscan;
+SET enable_indexscan = OFF;
+SELECT *, c <-> '(100, 100),(500, 500)'::cube as dist FROM test_cube ORDER BY c <-> '(100, 100),(500, 500)'::cube LIMIT 5;
+ c | dist
+-------------------------+------------------
+ (337, 455),(240, 359) | 0
+ (1, 1) | 140.007142674936
+ (759, 187),(662, 163) | 162
+ (948, 1201),(907, 1156) | 772.000647668122
+ (1444, 403),(1346, 344) | 846
+(5 rows)
+
+SELECT *, c <=> '(100, 100),(500, 500)'::cube as dist FROM test_cube ORDER BY c <=> '(100, 100),(500, 500)'::cube LIMIT 5;
+ c | dist
+-------------------------+------
+ (337, 455),(240, 359) | 0
+ (1, 1) | 99
+ (759, 187),(662, 163) | 162
+ (948, 1201),(907, 1156) | 656
+ (1444, 403),(1346, 344) | 846
+(5 rows)
+
SELECT *, c <#> '(100, 100),(500, 500)'::cube as dist FROM test_cube ORDER BY c <#> '(100, 100),(500, 500)'::cube LIMIT 5;
c | dist
-------------------------+------
(337, 455),(240, 359) | 0
(759, 187),(662, 163) | 162
+ (1, 1) | 198
(1444, 403),(1346, 344) | 846
(369, 1457),(278, 1409) | 909
- (948, 1201),(907, 1156) | 1063
(5 rows)
--- kNN-based sorting
-SELECT * FROM test_cube ORDER BY c~>1 LIMIT 15; -- ascending by 1st coordinate of lower left corner
- c
----------------------------
- (54, 38679),(3, 38602)
- (83, 10271),(15, 10265)
- (122, 46832),(64, 46762)
- (167, 17214),(92, 17184)
- (161, 24465),(107, 24374)
- (162, 26040),(120, 25963)
- (154, 4019),(138, 3990)
- (259, 1850),(175, 1820)
- (207, 40886),(179, 40879)
- (288, 49588),(204, 49571)
- (270, 32616),(226, 32607)
- (318, 31489),(235, 31404)
- (337, 455),(240, 359)
- (270, 29508),(264, 29440)
- (369, 1457),(278, 1409)
+SELECT c~>1, c FROM test_cube ORDER BY c~>1 LIMIT 15; -- ascending by left bound
+ ?column? | c
+----------+---------------------------
+ 0 | (0, 100000)
+ 1 | (1, 1)
+ 3 | (54, 38679),(3, 38602)
+ 15 | (83, 10271),(15, 10265)
+ 64 | (122, 46832),(64, 46762)
+ 92 | (167, 17214),(92, 17184)
+ 107 | (161, 24465),(107, 24374)
+ 120 | (162, 26040),(120, 25963)
+ 138 | (154, 4019),(138, 3990)
+ 175 | (259, 1850),(175, 1820)
+ 179 | (207, 40886),(179, 40879)
+ 204 | (288, 49588),(204, 49571)
+ 226 | (270, 32616),(226, 32607)
+ 235 | (318, 31489),(235, 31404)
+ 240 | (337, 455),(240, 359)
(15 rows)
-SELECT * FROM test_cube ORDER BY c~>4 LIMIT 15; -- ascending by 2nd coordinate or upper right corner
- c
----------------------------
- (30333, 50),(30273, 6)
- (43301, 75),(43227, 43)
- (19650, 142),(19630, 51)
- (2424, 160),(2424, 81)
- (3449, 171),(3354, 108)
- (18037, 155),(17941, 109)
- (28511, 208),(28479, 114)
- (19946, 217),(19941, 118)
- (16906, 191),(16816, 139)
- (759, 187),(662, 163)
- (22684, 266),(22656, 181)
- (24423, 255),(24360, 213)
- (45989, 249),(45910, 222)
- (11399, 377),(11360, 294)
- (12162, 389),(12103, 309)
+SELECT c~>2, c FROM test_cube ORDER BY c~>2 LIMIT 15; -- ascending by right bound
+ ?column? | c
+----------+---------------------------
+ 0 | (0, 100000)
+ 1 | (1, 1)
+ 54 | (54, 38679),(3, 38602)
+ 83 | (83, 10271),(15, 10265)
+ 122 | (122, 46832),(64, 46762)
+ 154 | (154, 4019),(138, 3990)
+ 161 | (161, 24465),(107, 24374)
+ 162 | (162, 26040),(120, 25963)
+ 167 | (167, 17214),(92, 17184)
+ 207 | (207, 40886),(179, 40879)
+ 259 | (259, 1850),(175, 1820)
+ 270 | (270, 29508),(264, 29440)
+ 270 | (270, 32616),(226, 32607)
+ 288 | (288, 49588),(204, 49571)
+ 318 | (318, 31489),(235, 31404)
(15 rows)
-SELECT * FROM test_cube ORDER BY c~>1 DESC LIMIT 15; -- descending by 1st coordinate of lower left corner
- c
--------------------------------
- (50027, 49230),(49951, 49214)
- (49980, 35004),(49937, 34963)
- (49985, 6436),(49927, 6338)
- (49999, 27218),(49908, 27176)
- (49954, 1340),(49905, 1294)
- (49944, 25163),(49902, 25153)
- (49981, 34876),(49898, 34786)
- (49957, 43390),(49897, 43384)
- (49853, 18504),(49848, 18503)
- (49902, 41752),(49818, 41746)
- (49907, 30225),(49810, 30158)
- (49843, 5175),(49808, 5145)
- (49887, 24274),(49805, 24184)
- (49847, 7128),(49798, 7067)
- (49820, 7990),(49771, 7967)
+SELECT c~>3, c FROM test_cube ORDER BY c~>3 LIMIT 15; -- ascending by lower bound
+ ?column? | c
+----------+---------------------------
+ 0 | (100000)
+ 1 | (1, 1)
+ 6 | (30333, 50),(30273, 6)
+ 43 | (43301, 75),(43227, 43)
+ 51 | (19650, 142),(19630, 51)
+ 81 | (2424, 160),(2424, 81)
+ 108 | (3449, 171),(3354, 108)
+ 109 | (18037, 155),(17941, 109)
+ 114 | (28511, 208),(28479, 114)
+ 118 | (19946, 217),(19941, 118)
+ 139 | (16906, 191),(16816, 139)
+ 163 | (759, 187),(662, 163)
+ 181 | (22684, 266),(22656, 181)
+ 213 | (24423, 255),(24360, 213)
+ 222 | (45989, 249),(45910, 222)
(15 rows)
-SELECT * FROM test_cube ORDER BY c~>4 DESC LIMIT 15; -- descending by 2nd coordinate or upper right corner
- c
--------------------------------
- (36311, 50073),(36258, 49987)
- (30746, 50040),(30727, 49992)
- (2168, 50012),(2108, 49914)
- (21551, 49983),(21492, 49885)
- (17954, 49975),(17865, 49915)
- (3531, 49962),(3463, 49934)
- (19128, 49932),(19112, 49849)
- (31287, 49923),(31236, 49913)
- (43925, 49912),(43888, 49878)
- (29261, 49910),(29247, 49818)
- (14913, 49873),(14849, 49836)
- (20007, 49858),(19921, 49778)
- (38266, 49852),(38233, 49844)
- (37595, 49849),(37581, 49834)
- (46151, 49848),(46058, 49830)
+SELECT c~>4, c FROM test_cube ORDER BY c~>4 LIMIT 15; -- ascending by upper bound
+ ?column? | c
+----------+---------------------------
+ 0 | (100000)
+ 1 | (1, 1)
+ 50 | (30333, 50),(30273, 6)
+ 75 | (43301, 75),(43227, 43)
+ 142 | (19650, 142),(19630, 51)
+ 155 | (18037, 155),(17941, 109)
+ 160 | (2424, 160),(2424, 81)
+ 171 | (3449, 171),(3354, 108)
+ 187 | (759, 187),(662, 163)
+ 191 | (16906, 191),(16816, 139)
+ 208 | (28511, 208),(28479, 114)
+ 217 | (19946, 217),(19941, 118)
+ 249 | (45989, 249),(45910, 222)
+ 255 | (24423, 255),(24360, 213)
+ 266 | (22684, 266),(22656, 181)
(15 rows)
--- same thing for index with points
-CREATE TABLE test_point(c cube);
-INSERT INTO test_point(SELECT cube(array[c->1,c->2,c->3,c->4]) FROM test_cube);
-CREATE INDEX ON test_point USING gist(c);
-SELECT * FROM test_point ORDER BY c~>1, c~>2 LIMIT 15; -- ascending by 1st then by 2nd coordinate
- c
---------------------------
- (54, 38679, 3, 38602)
- (83, 10271, 15, 10265)
- (122, 46832, 64, 46762)
- (154, 4019, 138, 3990)
- (161, 24465, 107, 24374)
- (162, 26040, 120, 25963)
- (167, 17214, 92, 17184)
- (207, 40886, 179, 40879)
- (259, 1850, 175, 1820)
- (270, 29508, 264, 29440)
- (270, 32616, 226, 32607)
- (288, 49588, 204, 49571)
- (318, 31489, 235, 31404)
- (326, 18837, 285, 18817)
- (337, 455, 240, 359)
+SELECT c~>(-1), c FROM test_cube ORDER BY c~>(-1) LIMIT 15; -- descending by left bound
+ ?column? | c
+----------+-------------------------------
+ -100000 | (100000)
+ -49951 | (50027, 49230),(49951, 49214)
+ -49937 | (49980, 35004),(49937, 34963)
+ -49927 | (49985, 6436),(49927, 6338)
+ -49908 | (49999, 27218),(49908, 27176)
+ -49905 | (49954, 1340),(49905, 1294)
+ -49902 | (49944, 25163),(49902, 25153)
+ -49898 | (49981, 34876),(49898, 34786)
+ -49897 | (49957, 43390),(49897, 43384)
+ -49848 | (49853, 18504),(49848, 18503)
+ -49818 | (49902, 41752),(49818, 41746)
+ -49810 | (49907, 30225),(49810, 30158)
+ -49808 | (49843, 5175),(49808, 5145)
+ -49805 | (49887, 24274),(49805, 24184)
+ -49798 | (49847, 7128),(49798, 7067)
+(15 rows)
+
+SELECT c~>(-2), c FROM test_cube ORDER BY c~>(-2) LIMIT 15; -- descending by right bound
+ ?column? | c
+----------+-------------------------------
+ -100000 | (100000)
+ -50027 | (50027, 49230),(49951, 49214)
+ -49999 | (49999, 27218),(49908, 27176)
+ -49985 | (49985, 6436),(49927, 6338)
+ -49981 | (49981, 34876),(49898, 34786)
+ -49980 | (49980, 35004),(49937, 34963)
+ -49957 | (49957, 43390),(49897, 43384)
+ -49954 | (49954, 1340),(49905, 1294)
+ -49944 | (49944, 25163),(49902, 25153)
+ -49907 | (49907, 30225),(49810, 30158)
+ -49902 | (49902, 41752),(49818, 41746)
+ -49887 | (49887, 24274),(49805, 24184)
+ -49853 | (49853, 18504),(49848, 18503)
+ -49847 | (49847, 7128),(49798, 7067)
+ -49843 | (49843, 5175),(49808, 5145)
+(15 rows)
+
+SELECT c~>(-3), c FROM test_cube ORDER BY c~>(-3) LIMIT 15; -- descending by lower bound
+ ?column? | c
+----------+-------------------------------
+ -100000 | (0, 100000)
+ -49992 | (30746, 50040),(30727, 49992)
+ -49987 | (36311, 50073),(36258, 49987)
+ -49934 | (3531, 49962),(3463, 49934)
+ -49915 | (17954, 49975),(17865, 49915)
+ -49914 | (2168, 50012),(2108, 49914)
+ -49913 | (31287, 49923),(31236, 49913)
+ -49885 | (21551, 49983),(21492, 49885)
+ -49878 | (43925, 49912),(43888, 49878)
+ -49849 | (19128, 49932),(19112, 49849)
+ -49844 | (38266, 49852),(38233, 49844)
+ -49836 | (14913, 49873),(14849, 49836)
+ -49834 | (37595, 49849),(37581, 49834)
+ -49830 | (46151, 49848),(46058, 49830)
+ -49818 | (29261, 49910),(29247, 49818)
(15 rows)
-SELECT * FROM test_point ORDER BY c~>4 DESC LIMIT 15; -- descending by 1st coordinate
- c
-------------------------------
- (30746, 50040, 30727, 49992)
- (36311, 50073, 36258, 49987)
- (3531, 49962, 3463, 49934)
- (17954, 49975, 17865, 49915)
- (2168, 50012, 2108, 49914)
- (31287, 49923, 31236, 49913)
- (21551, 49983, 21492, 49885)
- (43925, 49912, 43888, 49878)
- (19128, 49932, 19112, 49849)
- (38266, 49852, 38233, 49844)
- (14913, 49873, 14849, 49836)
- (37595, 49849, 37581, 49834)
- (46151, 49848, 46058, 49830)
- (29261, 49910, 29247, 49818)
- (19233, 49824, 19185, 49794)
+SELECT c~>(-4), c FROM test_cube ORDER BY c~>(-4) LIMIT 15; -- descending by upper bound
+ ?column? | c
+----------+-------------------------------
+ -100000 | (0, 100000)
+ -50073 | (36311, 50073),(36258, 49987)
+ -50040 | (30746, 50040),(30727, 49992)
+ -50012 | (2168, 50012),(2108, 49914)
+ -49983 | (21551, 49983),(21492, 49885)
+ -49975 | (17954, 49975),(17865, 49915)
+ -49962 | (3531, 49962),(3463, 49934)
+ -49932 | (19128, 49932),(19112, 49849)
+ -49923 | (31287, 49923),(31236, 49913)
+ -49912 | (43925, 49912),(43888, 49878)
+ -49910 | (29261, 49910),(29247, 49818)
+ -49873 | (14913, 49873),(14849, 49836)
+ -49858 | (20007, 49858),(19921, 49778)
+ -49852 | (38266, 49852),(38233, 49844)
+ -49849 | (37595, 49849),(37581, 49834)
(15 rows)
+RESET enable_indexscan;
diff --git a/contrib/cube/expected/cube_2.out b/contrib/cube/expected/cube_2.out
index 1aa5cf2f98..75fe405c49 100644
--- a/contrib/cube/expected/cube_2.out
+++ b/contrib/cube/expected/cube_2.out
@@ -1532,37 +1532,41 @@ SELECT cube(array[40,50,60], array[10,20,30])~>1;
SELECT cube(array[10,20,30], array[40,50,60])~>2;
?column?
----------
- 20
+ 40
(1 row)
SELECT cube(array[40,50,60], array[10,20,30])~>2;
?column?
----------
- 20
+ 40
(1 row)
SELECT cube(array[10,20,30], array[40,50,60])~>3;
?column?
----------
- 30
+ 20
(1 row)
SELECT cube(array[40,50,60], array[10,20,30])~>3;
?column?
----------
- 30
+ 20
(1 row)
SELECT cube(array[40,50,60], array[10,20,30])~>0;
-ERROR: cube index 0 is out of bounds
+ERROR: zero cube index is not defined
SELECT cube(array[40,50,60], array[10,20,30])~>4;
?column?
----------
- 40
+ 50
(1 row)
SELECT cube(array[40,50,60], array[10,20,30])~>(-1);
-ERROR: cube index -1 is out of bounds
+ ?column?
+----------
+ -10
+(1 row)
+
-- Load some example data and build the index
--
CREATE TABLE test_cube (c cube);
@@ -1589,159 +1593,414 @@ SELECT * FROM test_cube WHERE c && '(3000,1000),(0,0)' GROUP BY c ORDER BY c;
(2424, 160),(2424, 81)
(5 rows)
--- kNN with index
+-- Test index-only scans
+SET enable_bitmapscan = false;
+EXPLAIN (COSTS OFF)
+SELECT c FROM test_cube WHERE c <@ '(3000,1000),(0,0)' ORDER BY c;
+ QUERY PLAN
+--------------------------------------------------------
+ Sort
+ Sort Key: c
+ -> Index Only Scan using test_cube_ix on test_cube
+ Index Cond: (c <@ '(3000, 1000),(0, 0)'::cube)
+(4 rows)
+
+SELECT c FROM test_cube WHERE c <@ '(3000,1000),(0,0)' ORDER BY c;
+ c
+-------------------------
+ (337, 455),(240, 359)
+ (759, 187),(662, 163)
+ (1444, 403),(1346, 344)
+ (2424, 160),(2424, 81)
+(4 rows)
+
+RESET enable_bitmapscan;
+-- Test kNN
+INSERT INTO test_cube VALUES ('(1,1)'), ('(100000)'), ('(0, 100000)'); -- Some corner cases
+SET enable_seqscan = false;
+-- Test different metrics
SELECT *, c <-> '(100, 100),(500, 500)'::cube as dist FROM test_cube ORDER BY c <-> '(100, 100),(500, 500)'::cube LIMIT 5;
c | dist
-------------------------+------------------
(337, 455),(240, 359) | 0
+ (1, 1) | 140.007142674936
(759, 187),(662, 163) | 162
(948, 1201),(907, 1156) | 772.000647668122
(1444, 403),(1346, 344) | 846
- (369, 1457),(278, 1409) | 909
(5 rows)
SELECT *, c <=> '(100, 100),(500, 500)'::cube as dist FROM test_cube ORDER BY c <=> '(100, 100),(500, 500)'::cube LIMIT 5;
c | dist
-------------------------+------
(337, 455),(240, 359) | 0
+ (1, 1) | 99
(759, 187),(662, 163) | 162
(948, 1201),(907, 1156) | 656
(1444, 403),(1346, 344) | 846
+(5 rows)
+
+SELECT *, c <#> '(100, 100),(500, 500)'::cube as dist FROM test_cube ORDER BY c <#> '(100, 100),(500, 500)'::cube LIMIT 5;
+ c | dist
+-------------------------+------
+ (337, 455),(240, 359) | 0
+ (759, 187),(662, 163) | 162
+ (1, 1) | 198
+ (1444, 403),(1346, 344) | 846
(369, 1457),(278, 1409) | 909
(5 rows)
+-- Test sorting by coordinates
+SELECT c~>1, c FROM test_cube ORDER BY c~>1 LIMIT 15; -- ascending by left bound
+ ?column? | c
+----------+---------------------------
+ 0 | (0, 100000)
+ 1 | (1, 1)
+ 3 | (54, 38679),(3, 38602)
+ 15 | (83, 10271),(15, 10265)
+ 64 | (122, 46832),(64, 46762)
+ 92 | (167, 17214),(92, 17184)
+ 107 | (161, 24465),(107, 24374)
+ 120 | (162, 26040),(120, 25963)
+ 138 | (154, 4019),(138, 3990)
+ 175 | (259, 1850),(175, 1820)
+ 179 | (207, 40886),(179, 40879)
+ 204 | (288, 49588),(204, 49571)
+ 226 | (270, 32616),(226, 32607)
+ 235 | (318, 31489),(235, 31404)
+ 240 | (337, 455),(240, 359)
+(15 rows)
+
+SELECT c~>2, c FROM test_cube ORDER BY c~>2 LIMIT 15; -- ascending by right bound
+ ?column? | c
+----------+---------------------------
+ 0 | (0, 100000)
+ 1 | (1, 1)
+ 54 | (54, 38679),(3, 38602)
+ 83 | (83, 10271),(15, 10265)
+ 122 | (122, 46832),(64, 46762)
+ 154 | (154, 4019),(138, 3990)
+ 161 | (161, 24465),(107, 24374)
+ 162 | (162, 26040),(120, 25963)
+ 167 | (167, 17214),(92, 17184)
+ 207 | (207, 40886),(179, 40879)
+ 259 | (259, 1850),(175, 1820)
+ 270 | (270, 29508),(264, 29440)
+ 270 | (270, 32616),(226, 32607)
+ 288 | (288, 49588),(204, 49571)
+ 318 | (318, 31489),(235, 31404)
+(15 rows)
+
+SELECT c~>3, c FROM test_cube ORDER BY c~>3 LIMIT 15; -- ascending by lower bound
+ ?column? | c
+----------+---------------------------
+ 0 | (100000)
+ 1 | (1, 1)
+ 6 | (30333, 50),(30273, 6)
+ 43 | (43301, 75),(43227, 43)
+ 51 | (19650, 142),(19630, 51)
+ 81 | (2424, 160),(2424, 81)
+ 108 | (3449, 171),(3354, 108)
+ 109 | (18037, 155),(17941, 109)
+ 114 | (28511, 208),(28479, 114)
+ 118 | (19946, 217),(19941, 118)
+ 139 | (16906, 191),(16816, 139)
+ 163 | (759, 187),(662, 163)
+ 181 | (22684, 266),(22656, 181)
+ 213 | (24423, 255),(24360, 213)
+ 222 | (45989, 249),(45910, 222)
+(15 rows)
+
+SELECT c~>4, c FROM test_cube ORDER BY c~>4 LIMIT 15; -- ascending by upper bound
+ ?column? | c
+----------+---------------------------
+ 0 | (100000)
+ 1 | (1, 1)
+ 50 | (30333, 50),(30273, 6)
+ 75 | (43301, 75),(43227, 43)
+ 142 | (19650, 142),(19630, 51)
+ 155 | (18037, 155),(17941, 109)
+ 160 | (2424, 160),(2424, 81)
+ 171 | (3449, 171),(3354, 108)
+ 187 | (759, 187),(662, 163)
+ 191 | (16906, 191),(16816, 139)
+ 208 | (28511, 208),(28479, 114)
+ 217 | (19946, 217),(19941, 118)
+ 249 | (45989, 249),(45910, 222)
+ 255 | (24423, 255),(24360, 213)
+ 266 | (22684, 266),(22656, 181)
+(15 rows)
+
+SELECT c~>(-1), c FROM test_cube ORDER BY c~>(-1) LIMIT 15; -- descending by left bound
+ ?column? | c
+----------+-------------------------------
+ -100000 | (100000)
+ -49951 | (50027, 49230),(49951, 49214)
+ -49937 | (49980, 35004),(49937, 34963)
+ -49927 | (49985, 6436),(49927, 6338)
+ -49908 | (49999, 27218),(49908, 27176)
+ -49905 | (49954, 1340),(49905, 1294)
+ -49902 | (49944, 25163),(49902, 25153)
+ -49898 | (49981, 34876),(49898, 34786)
+ -49897 | (49957, 43390),(49897, 43384)
+ -49848 | (49853, 18504),(49848, 18503)
+ -49818 | (49902, 41752),(49818, 41746)
+ -49810 | (49907, 30225),(49810, 30158)
+ -49808 | (49843, 5175),(49808, 5145)
+ -49805 | (49887, 24274),(49805, 24184)
+ -49798 | (49847, 7128),(49798, 7067)
+(15 rows)
+
+SELECT c~>(-2), c FROM test_cube ORDER BY c~>(-2) LIMIT 15; -- descending by right bound
+ ?column? | c
+----------+-------------------------------
+ -100000 | (100000)
+ -50027 | (50027, 49230),(49951, 49214)
+ -49999 | (49999, 27218),(49908, 27176)
+ -49985 | (49985, 6436),(49927, 6338)
+ -49981 | (49981, 34876),(49898, 34786)
+ -49980 | (49980, 35004),(49937, 34963)
+ -49957 | (49957, 43390),(49897, 43384)
+ -49954 | (49954, 1340),(49905, 1294)
+ -49944 | (49944, 25163),(49902, 25153)
+ -49907 | (49907, 30225),(49810, 30158)
+ -49902 | (49902, 41752),(49818, 41746)
+ -49887 | (49887, 24274),(49805, 24184)
+ -49853 | (49853, 18504),(49848, 18503)
+ -49847 | (49847, 7128),(49798, 7067)
+ -49843 | (49843, 5175),(49808, 5145)
+(15 rows)
+
+SELECT c~>(-3), c FROM test_cube ORDER BY c~>(-3) LIMIT 15; -- descending by lower bound
+ ?column? | c
+----------+-------------------------------
+ -100000 | (0, 100000)
+ -49992 | (30746, 50040),(30727, 49992)
+ -49987 | (36311, 50073),(36258, 49987)
+ -49934 | (3531, 49962),(3463, 49934)
+ -49915 | (17954, 49975),(17865, 49915)
+ -49914 | (2168, 50012),(2108, 49914)
+ -49913 | (31287, 49923),(31236, 49913)
+ -49885 | (21551, 49983),(21492, 49885)
+ -49878 | (43925, 49912),(43888, 49878)
+ -49849 | (19128, 49932),(19112, 49849)
+ -49844 | (38266, 49852),(38233, 49844)
+ -49836 | (14913, 49873),(14849, 49836)
+ -49834 | (37595, 49849),(37581, 49834)
+ -49830 | (46151, 49848),(46058, 49830)
+ -49818 | (29261, 49910),(29247, 49818)
+(15 rows)
+
+SELECT c~>(-4), c FROM test_cube ORDER BY c~>(-4) LIMIT 15; -- descending by upper bound
+ ?column? | c
+----------+-------------------------------
+ -100000 | (0, 100000)
+ -50073 | (36311, 50073),(36258, 49987)
+ -50040 | (30746, 50040),(30727, 49992)
+ -50012 | (2168, 50012),(2108, 49914)
+ -49983 | (21551, 49983),(21492, 49885)
+ -49975 | (17954, 49975),(17865, 49915)
+ -49962 | (3531, 49962),(3463, 49934)
+ -49932 | (19128, 49932),(19112, 49849)
+ -49923 | (31287, 49923),(31236, 49913)
+ -49912 | (43925, 49912),(43888, 49878)
+ -49910 | (29261, 49910),(29247, 49818)
+ -49873 | (14913, 49873),(14849, 49836)
+ -49858 | (20007, 49858),(19921, 49778)
+ -49852 | (38266, 49852),(38233, 49844)
+ -49849 | (37595, 49849),(37581, 49834)
+(15 rows)
+
+-- Same queries with sequential scan (should give the same results as above)
+RESET enable_seqscan;
+SET enable_indexscan = OFF;
+SELECT *, c <-> '(100, 100),(500, 500)'::cube as dist FROM test_cube ORDER BY c <-> '(100, 100),(500, 500)'::cube LIMIT 5;
+ c | dist
+-------------------------+------------------
+ (337, 455),(240, 359) | 0
+ (1, 1) | 140.007142674936
+ (759, 187),(662, 163) | 162
+ (948, 1201),(907, 1156) | 772.000647668122
+ (1444, 403),(1346, 344) | 846
+(5 rows)
+
+SELECT *, c <=> '(100, 100),(500, 500)'::cube as dist FROM test_cube ORDER BY c <=> '(100, 100),(500, 500)'::cube LIMIT 5;
+ c | dist
+-------------------------+------
+ (337, 455),(240, 359) | 0
+ (1, 1) | 99
+ (759, 187),(662, 163) | 162
+ (948, 1201),(907, 1156) | 656
+ (1444, 403),(1346, 344) | 846
+(5 rows)
+
SELECT *, c <#> '(100, 100),(500, 500)'::cube as dist FROM test_cube ORDER BY c <#> '(100, 100),(500, 500)'::cube LIMIT 5;
c | dist
-------------------------+------
(337, 455),(240, 359) | 0
(759, 187),(662, 163) | 162
+ (1, 1) | 198
(1444, 403),(1346, 344) | 846
(369, 1457),(278, 1409) | 909
- (948, 1201),(907, 1156) | 1063
(5 rows)
--- kNN-based sorting
-SELECT * FROM test_cube ORDER BY c~>1 LIMIT 15; -- ascending by 1st coordinate of lower left corner
- c
----------------------------
- (54, 38679),(3, 38602)
- (83, 10271),(15, 10265)
- (122, 46832),(64, 46762)
- (167, 17214),(92, 17184)
- (161, 24465),(107, 24374)
- (162, 26040),(120, 25963)
- (154, 4019),(138, 3990)
- (259, 1850),(175, 1820)
- (207, 40886),(179, 40879)
- (288, 49588),(204, 49571)
- (270, 32616),(226, 32607)
- (318, 31489),(235, 31404)
- (337, 455),(240, 359)
- (270, 29508),(264, 29440)
- (369, 1457),(278, 1409)
+SELECT c~>1, c FROM test_cube ORDER BY c~>1 LIMIT 15; -- ascending by left bound
+ ?column? | c
+----------+---------------------------
+ 0 | (0, 100000)
+ 1 | (1, 1)
+ 3 | (54, 38679),(3, 38602)
+ 15 | (83, 10271),(15, 10265)
+ 64 | (122, 46832),(64, 46762)
+ 92 | (167, 17214),(92, 17184)
+ 107 | (161, 24465),(107, 24374)
+ 120 | (162, 26040),(120, 25963)
+ 138 | (154, 4019),(138, 3990)
+ 175 | (259, 1850),(175, 1820)
+ 179 | (207, 40886),(179, 40879)
+ 204 | (288, 49588),(204, 49571)
+ 226 | (270, 32616),(226, 32607)
+ 235 | (318, 31489),(235, 31404)
+ 240 | (337, 455),(240, 359)
(15 rows)
-SELECT * FROM test_cube ORDER BY c~>4 LIMIT 15; -- ascending by 2nd coordinate or upper right corner
- c
----------------------------
- (30333, 50),(30273, 6)
- (43301, 75),(43227, 43)
- (19650, 142),(19630, 51)
- (2424, 160),(2424, 81)
- (3449, 171),(3354, 108)
- (18037, 155),(17941, 109)
- (28511, 208),(28479, 114)
- (19946, 217),(19941, 118)
- (16906, 191),(16816, 139)
- (759, 187),(662, 163)
- (22684, 266),(22656, 181)
- (24423, 255),(24360, 213)
- (45989, 249),(45910, 222)
- (11399, 377),(11360, 294)
- (12162, 389),(12103, 309)
+SELECT c~>2, c FROM test_cube ORDER BY c~>2 LIMIT 15; -- ascending by right bound
+ ?column? | c
+----------+---------------------------
+ 0 | (0, 100000)
+ 1 | (1, 1)
+ 54 | (54, 38679),(3, 38602)
+ 83 | (83, 10271),(15, 10265)
+ 122 | (122, 46832),(64, 46762)
+ 154 | (154, 4019),(138, 3990)
+ 161 | (161, 24465),(107, 24374)
+ 162 | (162, 26040),(120, 25963)
+ 167 | (167, 17214),(92, 17184)
+ 207 | (207, 40886),(179, 40879)
+ 259 | (259, 1850),(175, 1820)
+ 270 | (270, 29508),(264, 29440)
+ 270 | (270, 32616),(226, 32607)
+ 288 | (288, 49588),(204, 49571)
+ 318 | (318, 31489),(235, 31404)
(15 rows)
-SELECT * FROM test_cube ORDER BY c~>1 DESC LIMIT 15; -- descending by 1st coordinate of lower left corner
- c
--------------------------------
- (50027, 49230),(49951, 49214)
- (49980, 35004),(49937, 34963)
- (49985, 6436),(49927, 6338)
- (49999, 27218),(49908, 27176)
- (49954, 1340),(49905, 1294)
- (49944, 25163),(49902, 25153)
- (49981, 34876),(49898, 34786)
- (49957, 43390),(49897, 43384)
- (49853, 18504),(49848, 18503)
- (49902, 41752),(49818, 41746)
- (49907, 30225),(49810, 30158)
- (49843, 5175),(49808, 5145)
- (49887, 24274),(49805, 24184)
- (49847, 7128),(49798, 7067)
- (49820, 7990),(49771, 7967)
+SELECT c~>3, c FROM test_cube ORDER BY c~>3 LIMIT 15; -- ascending by lower bound
+ ?column? | c
+----------+---------------------------
+ 0 | (100000)
+ 1 | (1, 1)
+ 6 | (30333, 50),(30273, 6)
+ 43 | (43301, 75),(43227, 43)
+ 51 | (19650, 142),(19630, 51)
+ 81 | (2424, 160),(2424, 81)
+ 108 | (3449, 171),(3354, 108)
+ 109 | (18037, 155),(17941, 109)
+ 114 | (28511, 208),(28479, 114)
+ 118 | (19946, 217),(19941, 118)
+ 139 | (16906, 191),(16816, 139)
+ 163 | (759, 187),(662, 163)
+ 181 | (22684, 266),(22656, 181)
+ 213 | (24423, 255),(24360, 213)
+ 222 | (45989, 249),(45910, 222)
(15 rows)
-SELECT * FROM test_cube ORDER BY c~>4 DESC LIMIT 15; -- descending by 2nd coordinate or upper right corner
- c
--------------------------------
- (36311, 50073),(36258, 49987)
- (30746, 50040),(30727, 49992)
- (2168, 50012),(2108, 49914)
- (21551, 49983),(21492, 49885)
- (17954, 49975),(17865, 49915)
- (3531, 49962),(3463, 49934)
- (19128, 49932),(19112, 49849)
- (31287, 49923),(31236, 49913)
- (43925, 49912),(43888, 49878)
- (29261, 49910),(29247, 49818)
- (14913, 49873),(14849, 49836)
- (20007, 49858),(19921, 49778)
- (38266, 49852),(38233, 49844)
- (37595, 49849),(37581, 49834)
- (46151, 49848),(46058, 49830)
+SELECT c~>4, c FROM test_cube ORDER BY c~>4 LIMIT 15; -- ascending by upper bound
+ ?column? | c
+----------+---------------------------
+ 0 | (100000)
+ 1 | (1, 1)
+ 50 | (30333, 50),(30273, 6)
+ 75 | (43301, 75),(43227, 43)
+ 142 | (19650, 142),(19630, 51)
+ 155 | (18037, 155),(17941, 109)
+ 160 | (2424, 160),(2424, 81)
+ 171 | (3449, 171),(3354, 108)
+ 187 | (759, 187),(662, 163)
+ 191 | (16906, 191),(16816, 139)
+ 208 | (28511, 208),(28479, 114)
+ 217 | (19946, 217),(19941, 118)
+ 249 | (45989, 249),(45910, 222)
+ 255 | (24423, 255),(24360, 213)
+ 266 | (22684, 266),(22656, 181)
(15 rows)
--- same thing for index with points
-CREATE TABLE test_point(c cube);
-INSERT INTO test_point(SELECT cube(array[c->1,c->2,c->3,c->4]) FROM test_cube);
-CREATE INDEX ON test_point USING gist(c);
-SELECT * FROM test_point ORDER BY c~>1, c~>2 LIMIT 15; -- ascending by 1st then by 2nd coordinate
- c
---------------------------
- (54, 38679, 3, 38602)
- (83, 10271, 15, 10265)
- (122, 46832, 64, 46762)
- (154, 4019, 138, 3990)
- (161, 24465, 107, 24374)
- (162, 26040, 120, 25963)
- (167, 17214, 92, 17184)
- (207, 40886, 179, 40879)
- (259, 1850, 175, 1820)
- (270, 29508, 264, 29440)
- (270, 32616, 226, 32607)
- (288, 49588, 204, 49571)
- (318, 31489, 235, 31404)
- (326, 18837, 285, 18817)
- (337, 455, 240, 359)
+SELECT c~>(-1), c FROM test_cube ORDER BY c~>(-1) LIMIT 15; -- descending by left bound
+ ?column? | c
+----------+-------------------------------
+ -100000 | (100000)
+ -49951 | (50027, 49230),(49951, 49214)
+ -49937 | (49980, 35004),(49937, 34963)
+ -49927 | (49985, 6436),(49927, 6338)
+ -49908 | (49999, 27218),(49908, 27176)
+ -49905 | (49954, 1340),(49905, 1294)
+ -49902 | (49944, 25163),(49902, 25153)
+ -49898 | (49981, 34876),(49898, 34786)
+ -49897 | (49957, 43390),(49897, 43384)
+ -49848 | (49853, 18504),(49848, 18503)
+ -49818 | (49902, 41752),(49818, 41746)
+ -49810 | (49907, 30225),(49810, 30158)
+ -49808 | (49843, 5175),(49808, 5145)
+ -49805 | (49887, 24274),(49805, 24184)
+ -49798 | (49847, 7128),(49798, 7067)
+(15 rows)
+
+SELECT c~>(-2), c FROM test_cube ORDER BY c~>(-2) LIMIT 15; -- descending by right bound
+ ?column? | c
+----------+-------------------------------
+ -100000 | (100000)
+ -50027 | (50027, 49230),(49951, 49214)
+ -49999 | (49999, 27218),(49908, 27176)
+ -49985 | (49985, 6436),(49927, 6338)
+ -49981 | (49981, 34876),(49898, 34786)
+ -49980 | (49980, 35004),(49937, 34963)
+ -49957 | (49957, 43390),(49897, 43384)
+ -49954 | (49954, 1340),(49905, 1294)
+ -49944 | (49944, 25163),(49902, 25153)
+ -49907 | (49907, 30225),(49810, 30158)
+ -49902 | (49902, 41752),(49818, 41746)
+ -49887 | (49887, 24274),(49805, 24184)
+ -49853 | (49853, 18504),(49848, 18503)
+ -49847 | (49847, 7128),(49798, 7067)
+ -49843 | (49843, 5175),(49808, 5145)
+(15 rows)
+
+SELECT c~>(-3), c FROM test_cube ORDER BY c~>(-3) LIMIT 15; -- descending by lower bound
+ ?column? | c
+----------+-------------------------------
+ -100000 | (0, 100000)
+ -49992 | (30746, 50040),(30727, 49992)
+ -49987 | (36311, 50073),(36258, 49987)
+ -49934 | (3531, 49962),(3463, 49934)
+ -49915 | (17954, 49975),(17865, 49915)
+ -49914 | (2168, 50012),(2108, 49914)
+ -49913 | (31287, 49923),(31236, 49913)
+ -49885 | (21551, 49983),(21492, 49885)
+ -49878 | (43925, 49912),(43888, 49878)
+ -49849 | (19128, 49932),(19112, 49849)
+ -49844 | (38266, 49852),(38233, 49844)
+ -49836 | (14913, 49873),(14849, 49836)
+ -49834 | (37595, 49849),(37581, 49834)
+ -49830 | (46151, 49848),(46058, 49830)
+ -49818 | (29261, 49910),(29247, 49818)
(15 rows)
-SELECT * FROM test_point ORDER BY c~>4 DESC LIMIT 15; -- descending by 1st coordinate
- c
-------------------------------
- (30746, 50040, 30727, 49992)
- (36311, 50073, 36258, 49987)
- (3531, 49962, 3463, 49934)
- (17954, 49975, 17865, 49915)
- (2168, 50012, 2108, 49914)
- (31287, 49923, 31236, 49913)
- (21551, 49983, 21492, 49885)
- (43925, 49912, 43888, 49878)
- (19128, 49932, 19112, 49849)
- (38266, 49852, 38233, 49844)
- (14913, 49873, 14849, 49836)
- (37595, 49849, 37581, 49834)
- (46151, 49848, 46058, 49830)
- (29261, 49910, 29247, 49818)
- (19233, 49824, 19185, 49794)
+SELECT c~>(-4), c FROM test_cube ORDER BY c~>(-4) LIMIT 15; -- descending by upper bound
+ ?column? | c
+----------+-------------------------------
+ -100000 | (0, 100000)
+ -50073 | (36311, 50073),(36258, 49987)
+ -50040 | (30746, 50040),(30727, 49992)
+ -50012 | (2168, 50012),(2108, 49914)
+ -49983 | (21551, 49983),(21492, 49885)
+ -49975 | (17954, 49975),(17865, 49915)
+ -49962 | (3531, 49962),(3463, 49934)
+ -49932 | (19128, 49932),(19112, 49849)
+ -49923 | (31287, 49923),(31236, 49913)
+ -49912 | (43925, 49912),(43888, 49878)
+ -49910 | (29261, 49910),(29247, 49818)
+ -49873 | (14913, 49873),(14849, 49836)
+ -49858 | (20007, 49858),(19921, 49778)
+ -49852 | (38266, 49852),(38233, 49844)
+ -49849 | (37595, 49849),(37581, 49834)
(15 rows)
+RESET enable_indexscan;
diff --git a/contrib/cube/sql/cube.sql b/contrib/cube/sql/cube.sql
index 58ea3ad811..f599e7f7c0 100644
--- a/contrib/cube/sql/cube.sql
+++ b/contrib/cube/sql/cube.sql
@@ -382,20 +382,44 @@ SELECT * FROM test_cube WHERE c && '(3000,1000),(0,0)' ORDER BY c;
-- Test sorting
SELECT * FROM test_cube WHERE c && '(3000,1000),(0,0)' GROUP BY c ORDER BY c;
--- kNN with index
+-- Test index-only scans
+SET enable_bitmapscan = false;
+EXPLAIN (COSTS OFF)
+SELECT c FROM test_cube WHERE c <@ '(3000,1000),(0,0)' ORDER BY c;
+SELECT c FROM test_cube WHERE c <@ '(3000,1000),(0,0)' ORDER BY c;
+RESET enable_bitmapscan;
+
+-- Test kNN
+INSERT INTO test_cube VALUES ('(1,1)'), ('(100000)'), ('(0, 100000)'); -- Some corner cases
+SET enable_seqscan = false;
+
+-- Test different metrics
SELECT *, c <-> '(100, 100),(500, 500)'::cube as dist FROM test_cube ORDER BY c <-> '(100, 100),(500, 500)'::cube LIMIT 5;
SELECT *, c <=> '(100, 100),(500, 500)'::cube as dist FROM test_cube ORDER BY c <=> '(100, 100),(500, 500)'::cube LIMIT 5;
SELECT *, c <#> '(100, 100),(500, 500)'::cube as dist FROM test_cube ORDER BY c <#> '(100, 100),(500, 500)'::cube LIMIT 5;
--- kNN-based sorting
-SELECT * FROM test_cube ORDER BY c~>1 LIMIT 15; -- ascending by 1st coordinate of lower left corner
-SELECT * FROM test_cube ORDER BY c~>4 LIMIT 15; -- ascending by 2nd coordinate or upper right corner
-SELECT * FROM test_cube ORDER BY c~>1 DESC LIMIT 15; -- descending by 1st coordinate of lower left corner
-SELECT * FROM test_cube ORDER BY c~>4 DESC LIMIT 15; -- descending by 2nd coordinate or upper right corner
-
--- same thing for index with points
-CREATE TABLE test_point(c cube);
-INSERT INTO test_point(SELECT cube(array[c->1,c->2,c->3,c->4]) FROM test_cube);
-CREATE INDEX ON test_point USING gist(c);
-SELECT * FROM test_point ORDER BY c~>1, c~>2 LIMIT 15; -- ascending by 1st then by 2nd coordinate
-SELECT * FROM test_point ORDER BY c~>4 DESC LIMIT 15; -- descending by 1st coordinate
+-- Test sorting by coordinates
+SELECT c~>1, c FROM test_cube ORDER BY c~>1 LIMIT 15; -- ascending by left bound
+SELECT c~>2, c FROM test_cube ORDER BY c~>2 LIMIT 15; -- ascending by right bound
+SELECT c~>3, c FROM test_cube ORDER BY c~>3 LIMIT 15; -- ascending by lower bound
+SELECT c~>4, c FROM test_cube ORDER BY c~>4 LIMIT 15; -- ascending by upper bound
+SELECT c~>(-1), c FROM test_cube ORDER BY c~>(-1) LIMIT 15; -- descending by left bound
+SELECT c~>(-2), c FROM test_cube ORDER BY c~>(-2) LIMIT 15; -- descending by right bound
+SELECT c~>(-3), c FROM test_cube ORDER BY c~>(-3) LIMIT 15; -- descending by lower bound
+SELECT c~>(-4), c FROM test_cube ORDER BY c~>(-4) LIMIT 15; -- descending by upper bound
+
+-- Same queries with sequential scan (should give the same results as above)
+RESET enable_seqscan;
+SET enable_indexscan = OFF;
+SELECT *, c <-> '(100, 100),(500, 500)'::cube as dist FROM test_cube ORDER BY c <-> '(100, 100),(500, 500)'::cube LIMIT 5;
+SELECT *, c <=> '(100, 100),(500, 500)'::cube as dist FROM test_cube ORDER BY c <=> '(100, 100),(500, 500)'::cube LIMIT 5;
+SELECT *, c <#> '(100, 100),(500, 500)'::cube as dist FROM test_cube ORDER BY c <#> '(100, 100),(500, 500)'::cube LIMIT 5;
+SELECT c~>1, c FROM test_cube ORDER BY c~>1 LIMIT 15; -- ascending by left bound
+SELECT c~>2, c FROM test_cube ORDER BY c~>2 LIMIT 15; -- ascending by right bound
+SELECT c~>3, c FROM test_cube ORDER BY c~>3 LIMIT 15; -- ascending by lower bound
+SELECT c~>4, c FROM test_cube ORDER BY c~>4 LIMIT 15; -- ascending by upper bound
+SELECT c~>(-1), c FROM test_cube ORDER BY c~>(-1) LIMIT 15; -- descending by left bound
+SELECT c~>(-2), c FROM test_cube ORDER BY c~>(-2) LIMIT 15; -- descending by right bound
+SELECT c~>(-3), c FROM test_cube ORDER BY c~>(-3) LIMIT 15; -- descending by lower bound
+SELECT c~>(-4), c FROM test_cube ORDER BY c~>(-4) LIMIT 15; -- descending by upper bound
+RESET enable_indexscan;
diff --git a/contrib/dblink/dblink.c b/contrib/dblink/dblink.c
index 81136b131c..ae7e24ad08 100644
--- a/contrib/dblink/dblink.c
+++ b/contrib/dblink/dblink.c
@@ -9,7 +9,7 @@
* Shridhar Daithankar
*
* contrib/dblink/dblink.c
- * Copyright (c) 2001-2017, PostgreSQL Global Development Group
+ * Copyright (c) 2001-2018, PostgreSQL Global Development Group
* ALL RIGHTS RESERVED;
*
* Permission to use, copy, modify, and distribute this software and its
@@ -243,7 +243,7 @@ dblink_init(void)
pconn = (remoteConn *) MemoryContextAlloc(TopMemoryContext, sizeof(remoteConn));
pconn->conn = NULL;
pconn->openCursorCount = 0;
- pconn->newXactForCursor = FALSE;
+ pconn->newXactForCursor = false;
}
}
@@ -423,7 +423,7 @@ dblink_open(PG_FUNCTION_ARGS)
if (PQresultStatus(res) != PGRES_COMMAND_OK)
dblink_res_internalerror(conn, res, "begin error");
PQclear(res);
- rconn->newXactForCursor = TRUE;
+ rconn->newXactForCursor = true;
/*
* Since transaction state was IDLE, we force cursor count to
@@ -523,7 +523,7 @@ dblink_close(PG_FUNCTION_ARGS)
/* if count is zero, commit the transaction */
if (rconn->openCursorCount == 0)
{
- rconn->newXactForCursor = FALSE;
+ rconn->newXactForCursor = false;
res = PQexec(conn, "COMMIT");
if (PQresultStatus(res) != PGRES_COMMAND_OK)
@@ -2172,14 +2172,16 @@ get_sql_insert(Relation rel, int *pkattnums, int pknumatts, char **src_pkattvals
needComma = false;
for (i = 0; i < natts; i++)
{
- if (tupdesc->attrs[i]->attisdropped)
+ Form_pg_attribute att = TupleDescAttr(tupdesc, i);
+
+ if (att->attisdropped)
continue;
if (needComma)
appendStringInfoChar(&buf, ',');
appendStringInfoString(&buf,
- quote_ident_cstr(NameStr(tupdesc->attrs[i]->attname)));
+ quote_ident_cstr(NameStr(att->attname)));
needComma = true;
}
@@ -2191,7 +2193,7 @@ get_sql_insert(Relation rel, int *pkattnums, int pknumatts, char **src_pkattvals
needComma = false;
for (i = 0; i < natts; i++)
{
- if (tupdesc->attrs[i]->attisdropped)
+ if (TupleDescAttr(tupdesc, i)->attisdropped)
continue;
if (needComma)
@@ -2215,7 +2217,7 @@ get_sql_insert(Relation rel, int *pkattnums, int pknumatts, char **src_pkattvals
}
appendStringInfoChar(&buf, ')');
- return (buf.data);
+ return buf.data;
}
static char *
@@ -2237,12 +2239,13 @@ get_sql_delete(Relation rel, int *pkattnums, int pknumatts, char **tgt_pkattvals
for (i = 0; i < pknumatts; i++)
{
int pkattnum = pkattnums[i];
+ Form_pg_attribute attr = TupleDescAttr(tupdesc, pkattnum);
if (i > 0)
appendStringInfoString(&buf, " AND ");
appendStringInfoString(&buf,
- quote_ident_cstr(NameStr(tupdesc->attrs[pkattnum]->attname)));
+ quote_ident_cstr(NameStr(attr->attname)));
if (tgt_pkattvals[i] != NULL)
appendStringInfo(&buf, " = %s",
@@ -2251,7 +2254,7 @@ get_sql_delete(Relation rel, int *pkattnums, int pknumatts, char **tgt_pkattvals
appendStringInfoString(&buf, " IS NULL");
}
- return (buf.data);
+ return buf.data;
}
static char *
@@ -2289,14 +2292,16 @@ get_sql_update(Relation rel, int *pkattnums, int pknumatts, char **src_pkattvals
needComma = false;
for (i = 0; i < natts; i++)
{
- if (tupdesc->attrs[i]->attisdropped)
+ Form_pg_attribute attr = TupleDescAttr(tupdesc, i);
+
+ if (attr->attisdropped)
continue;
if (needComma)
appendStringInfoString(&buf, ", ");
appendStringInfo(&buf, "%s = ",
- quote_ident_cstr(NameStr(tupdesc->attrs[i]->attname)));
+ quote_ident_cstr(NameStr(attr->attname)));
key = get_attnum_pk_pos(pkattnums, pknumatts, i);
@@ -2320,12 +2325,13 @@ get_sql_update(Relation rel, int *pkattnums, int pknumatts, char **src_pkattvals
for (i = 0; i < pknumatts; i++)
{
int pkattnum = pkattnums[i];
+ Form_pg_attribute attr = TupleDescAttr(tupdesc, pkattnum);
if (i > 0)
appendStringInfoString(&buf, " AND ");
appendStringInfoString(&buf,
- quote_ident_cstr(NameStr(tupdesc->attrs[pkattnum]->attname)));
+ quote_ident_cstr(NameStr(attr->attname)));
val = tgt_pkattvals[i];
@@ -2335,7 +2341,7 @@ get_sql_update(Relation rel, int *pkattnums, int pknumatts, char **src_pkattvals
appendStringInfoString(&buf, " IS NULL");
}
- return (buf.data);
+ return buf.data;
}
/*
@@ -2409,14 +2415,16 @@ get_tuple_of_interest(Relation rel, int *pkattnums, int pknumatts, char **src_pk
for (i = 0; i < natts; i++)
{
+ Form_pg_attribute attr = TupleDescAttr(tupdesc, i);
+
if (i > 0)
appendStringInfoString(&buf, ", ");
- if (tupdesc->attrs[i]->attisdropped)
+ if (attr->attisdropped)
appendStringInfoString(&buf, "NULL");
else
appendStringInfoString(&buf,
- quote_ident_cstr(NameStr(tupdesc->attrs[i]->attname)));
+ quote_ident_cstr(NameStr(attr->attname)));
}
appendStringInfo(&buf, " FROM %s WHERE ", relname);
@@ -2424,12 +2432,13 @@ get_tuple_of_interest(Relation rel, int *pkattnums, int pknumatts, char **src_pk
for (i = 0; i < pknumatts; i++)
{
int pkattnum = pkattnums[i];
+ Form_pg_attribute attr = TupleDescAttr(tupdesc, pkattnum);
if (i > 0)
appendStringInfoString(&buf, " AND ");
appendStringInfoString(&buf,
- quote_ident_cstr(NameStr(tupdesc->attrs[pkattnum]->attname)));
+ quote_ident_cstr(NameStr(attr->attname)));
if (src_pkattvals[i] != NULL)
appendStringInfo(&buf, " = %s",
@@ -2495,7 +2504,7 @@ get_rel_from_relname(text *relname_text, LOCKMODE lockmode, AclMode aclmode)
aclresult = pg_class_aclcheck(RelationGetRelid(rel), GetUserId(),
aclmode);
if (aclresult != ACLCHECK_OK)
- aclcheck_error(aclresult, ACL_KIND_CLASS,
+ aclcheck_error(aclresult, get_relkind_objtype(rel->rd_rel->relkind),
RelationGetRelationName(rel));
return rel;
@@ -2540,9 +2549,9 @@ getConnectionByName(const char *name)
key, HASH_FIND, NULL);
if (hentry)
- return (hentry->rconn);
+ return hentry->rconn;
- return (NULL);
+ return NULL;
}
static HTAB *
@@ -2780,7 +2789,7 @@ get_connect_string(const char *servername)
/* Check permissions, user must have usage on the server. */
aclresult = pg_foreign_server_aclcheck(serverid, userid, ACL_USAGE);
if (aclresult != ACLCHECK_OK)
- aclcheck_error(aclresult, ACL_KIND_FOREIGN_SERVER, foreign_server->servername);
+ aclcheck_error(aclresult, OBJECT_FOREIGN_SERVER, foreign_server->servername);
foreach(cell, fdw->options)
{
@@ -2894,7 +2903,7 @@ validate_pkattnums(Relation rel,
for (j = 0; j < natts; j++)
{
/* dropped columns don't count */
- if (tupdesc->attrs[j]->attisdropped)
+ if (TupleDescAttr(tupdesc, j)->attisdropped)
continue;
if (++lnum == pkattnum)
diff --git a/contrib/dict_int/dict_int.c b/contrib/dict_int/dict_int.c
index 55427c4bc7..56ede37089 100644
--- a/contrib/dict_int/dict_int.c
+++ b/contrib/dict_int/dict_int.c
@@ -3,7 +3,7 @@
* dict_int.c
* Text search dictionary for integers
*
- * Copyright (c) 2007-2017, PostgreSQL Global Development Group
+ * Copyright (c) 2007-2018, PostgreSQL Global Development Group
*
* IDENTIFICATION
* contrib/dict_int/dict_int.c
@@ -42,11 +42,11 @@ dintdict_init(PG_FUNCTION_ARGS)
{
DefElem *defel = (DefElem *) lfirst(l);
- if (pg_strcasecmp(defel->defname, "MAXLEN") == 0)
+ if (strcmp(defel->defname, "maxlen") == 0)
{
d->maxlen = atoi(defGetString(defel));
}
- else if (pg_strcasecmp(defel->defname, "REJECTLONG") == 0)
+ else if (strcmp(defel->defname, "rejectlong") == 0)
{
d->rejectlong = defGetBoolean(defel);
}
diff --git a/contrib/dict_xsyn/dict_xsyn.c b/contrib/dict_xsyn/dict_xsyn.c
index fcf541ee0f..a79ece240c 100644
--- a/contrib/dict_xsyn/dict_xsyn.c
+++ b/contrib/dict_xsyn/dict_xsyn.c
@@ -3,7 +3,7 @@
* dict_xsyn.c
* Extended synonym dictionary
*
- * Copyright (c) 2007-2017, PostgreSQL Global Development Group
+ * Copyright (c) 2007-2018, PostgreSQL Global Development Group
*
* IDENTIFICATION
* contrib/dict_xsyn/dict_xsyn.c
@@ -70,7 +70,7 @@ compare_syn(const void *a, const void *b)
}
static void
-read_dictionary(DictSyn *d, char *filename)
+read_dictionary(DictSyn *d, const char *filename)
{
char *real_filename = get_tsearch_config_filename(filename, "rules");
tsearch_readline_state trst;
@@ -157,23 +157,23 @@ dxsyn_init(PG_FUNCTION_ARGS)
{
DefElem *defel = (DefElem *) lfirst(l);
- if (pg_strcasecmp(defel->defname, "MATCHORIG") == 0)
+ if (strcmp(defel->defname, "matchorig") == 0)
{
d->matchorig = defGetBoolean(defel);
}
- else if (pg_strcasecmp(defel->defname, "KEEPORIG") == 0)
+ else if (strcmp(defel->defname, "keeporig") == 0)
{
d->keeporig = defGetBoolean(defel);
}
- else if (pg_strcasecmp(defel->defname, "MATCHSYNONYMS") == 0)
+ else if (strcmp(defel->defname, "matchsynonyms") == 0)
{
d->matchsynonyms = defGetBoolean(defel);
}
- else if (pg_strcasecmp(defel->defname, "KEEPSYNONYMS") == 0)
+ else if (strcmp(defel->defname, "keepsynonyms") == 0)
{
d->keepsynonyms = defGetBoolean(defel);
}
- else if (pg_strcasecmp(defel->defname, "RULES") == 0)
+ else if (strcmp(defel->defname, "rules") == 0)
{
/* we can't read the rules before parsing all options! */
filename = defGetString(defel);
diff --git a/contrib/file_fdw/data/list1.csv b/contrib/file_fdw/data/list1.csv
new file mode 100644
index 0000000000..203f3b2324
--- /dev/null
+++ b/contrib/file_fdw/data/list1.csv
@@ -0,0 +1,2 @@
+1,foo
+1,bar
diff --git a/contrib/file_fdw/data/list2.bad b/contrib/file_fdw/data/list2.bad
new file mode 100644
index 0000000000..00af47f5ef
--- /dev/null
+++ b/contrib/file_fdw/data/list2.bad
@@ -0,0 +1,2 @@
+2,baz
+1,qux
diff --git a/contrib/file_fdw/data/list2.csv b/contrib/file_fdw/data/list2.csv
new file mode 100644
index 0000000000..2fb133d004
--- /dev/null
+++ b/contrib/file_fdw/data/list2.csv
@@ -0,0 +1,2 @@
+2,baz
+2,qux
diff --git a/contrib/file_fdw/file_fdw.c b/contrib/file_fdw/file_fdw.c
index 2396bd442f..cf0a3629bc 100644
--- a/contrib/file_fdw/file_fdw.c
+++ b/contrib/file_fdw/file_fdw.c
@@ -3,7 +3,7 @@
* file_fdw.c
* foreign-data wrapper for server-side flat files (or programs).
*
- * Copyright (c) 2010-2017, PostgreSQL Global Development Group
+ * Copyright (c) 2010-2018, PostgreSQL Global Development Group
*
* IDENTIFICATION
* contrib/file_fdw/file_fdw.c
@@ -430,7 +430,7 @@ get_file_fdw_attribute_options(Oid relid)
/* Retrieve FDW options for all user-defined attributes. */
for (attnum = 1; attnum <= natts; attnum++)
{
- Form_pg_attribute attr = tupleDesc->attrs[attnum - 1];
+ Form_pg_attribute attr = TupleDescAttr(tupleDesc, attnum - 1);
List *options;
ListCell *lc;
@@ -824,7 +824,7 @@ fileIsForeignScanParallelSafe(PlannerInfo *root, RelOptInfo *rel,
*
* Check to see if it's useful to convert only a subset of the file's columns
* to binary. If so, construct a list of the column names to be converted,
- * return that at *columns, and return TRUE. (Note that it's possible to
+ * return that at *columns, and return true. (Note that it's possible to
* determine that no columns need be converted, for instance with a COUNT(*)
* query. So we can't use returning a NIL list to indicate failure.)
*/
@@ -898,7 +898,7 @@ check_selective_binary_conversion(RelOptInfo *baserel,
/* Get user attributes. */
if (attnum > 0)
{
- Form_pg_attribute attr = tupleDesc->attrs[attnum - 1];
+ Form_pg_attribute attr = TupleDescAttr(tupleDesc, attnum - 1);
char *attname = NameStr(attr->attname);
/* Skip dropped attributes (probably shouldn't see any here). */
@@ -912,7 +912,7 @@ check_selective_binary_conversion(RelOptInfo *baserel,
numattrs = 0;
for (i = 0; i < tupleDesc->natts; i++)
{
- Form_pg_attribute attr = tupleDesc->attrs[i];
+ Form_pg_attribute attr = TupleDescAttr(tupleDesc, i);
if (attr->attisdropped)
continue;
diff --git a/contrib/file_fdw/input/file_fdw.source b/contrib/file_fdw/input/file_fdw.source
index 685561fc2a..88cb5f294c 100644
--- a/contrib/file_fdw/input/file_fdw.source
+++ b/contrib/file_fdw/input/file_fdw.source
@@ -162,6 +162,28 @@ SELECT tableoid::regclass, * FROM agg FOR UPDATE;
ALTER FOREIGN TABLE agg_csv NO INHERIT agg;
DROP TABLE agg;
+-- declarative partitioning tests
+SET ROLE regress_file_fdw_superuser;
+CREATE TABLE pt (a int, b text) partition by list (a);
+CREATE FOREIGN TABLE p1 partition of pt for values in (1) SERVER file_server
+OPTIONS (format 'csv', filename '@abs_srcdir@/data/list1.csv', delimiter ',');
+CREATE TABLE p2 partition of pt for values in (2);
+SELECT tableoid::regclass, * FROM pt;
+SELECT tableoid::regclass, * FROM p1;
+SELECT tableoid::regclass, * FROM p2;
+COPY pt FROM '@abs_srcdir@/data/list2.bad' with (format 'csv', delimiter ','); -- ERROR
+COPY pt FROM '@abs_srcdir@/data/list2.csv' with (format 'csv', delimiter ',');
+SELECT tableoid::regclass, * FROM pt;
+SELECT tableoid::regclass, * FROM p1;
+SELECT tableoid::regclass, * FROM p2;
+INSERT INTO pt VALUES (1, 'xyzzy'); -- ERROR
+INSERT INTO pt VALUES (2, 'xyzzy');
+UPDATE pt set a = 1 where a = 2; -- ERROR
+SELECT tableoid::regclass, * FROM pt;
+SELECT tableoid::regclass, * FROM p1;
+SELECT tableoid::regclass, * FROM p2;
+DROP TABLE pt;
+
-- privilege tests
SET ROLE regress_file_fdw_superuser;
SELECT * FROM agg_text ORDER BY a;
diff --git a/contrib/file_fdw/output/file_fdw.source b/contrib/file_fdw/output/file_fdw.source
index 01e2690a82..b92392fd25 100644
--- a/contrib/file_fdw/output/file_fdw.source
+++ b/contrib/file_fdw/output/file_fdw.source
@@ -289,6 +289,89 @@ SELECT tableoid::regclass, * FROM agg FOR UPDATE;
ALTER FOREIGN TABLE agg_csv NO INHERIT agg;
DROP TABLE agg;
+-- declarative partitioning tests
+SET ROLE regress_file_fdw_superuser;
+CREATE TABLE pt (a int, b text) partition by list (a);
+CREATE FOREIGN TABLE p1 partition of pt for values in (1) SERVER file_server
+OPTIONS (format 'csv', filename '@abs_srcdir@/data/list1.csv', delimiter ',');
+CREATE TABLE p2 partition of pt for values in (2);
+SELECT tableoid::regclass, * FROM pt;
+ tableoid | a | b
+----------+---+-----
+ p1 | 1 | foo
+ p1 | 1 | bar
+(2 rows)
+
+SELECT tableoid::regclass, * FROM p1;
+ tableoid | a | b
+----------+---+-----
+ p1 | 1 | foo
+ p1 | 1 | bar
+(2 rows)
+
+SELECT tableoid::regclass, * FROM p2;
+ tableoid | a | b
+----------+---+---
+(0 rows)
+
+COPY pt FROM '@abs_srcdir@/data/list2.bad' with (format 'csv', delimiter ','); -- ERROR
+ERROR: cannot route inserted tuples to a foreign table
+CONTEXT: COPY pt, line 2: "1,qux"
+COPY pt FROM '@abs_srcdir@/data/list2.csv' with (format 'csv', delimiter ',');
+SELECT tableoid::regclass, * FROM pt;
+ tableoid | a | b
+----------+---+-----
+ p1 | 1 | foo
+ p1 | 1 | bar
+ p2 | 2 | baz
+ p2 | 2 | qux
+(4 rows)
+
+SELECT tableoid::regclass, * FROM p1;
+ tableoid | a | b
+----------+---+-----
+ p1 | 1 | foo
+ p1 | 1 | bar
+(2 rows)
+
+SELECT tableoid::regclass, * FROM p2;
+ tableoid | a | b
+----------+---+-----
+ p2 | 2 | baz
+ p2 | 2 | qux
+(2 rows)
+
+INSERT INTO pt VALUES (1, 'xyzzy'); -- ERROR
+ERROR: cannot route inserted tuples to a foreign table
+INSERT INTO pt VALUES (2, 'xyzzy');
+UPDATE pt set a = 1 where a = 2; -- ERROR
+ERROR: cannot route inserted tuples to a foreign table
+SELECT tableoid::regclass, * FROM pt;
+ tableoid | a | b
+----------+---+-------
+ p1 | 1 | foo
+ p1 | 1 | bar
+ p2 | 2 | baz
+ p2 | 2 | qux
+ p2 | 2 | xyzzy
+(5 rows)
+
+SELECT tableoid::regclass, * FROM p1;
+ tableoid | a | b
+----------+---+-----
+ p1 | 1 | foo
+ p1 | 1 | bar
+(2 rows)
+
+SELECT tableoid::regclass, * FROM p2;
+ tableoid | a | b
+----------+---+-------
+ p2 | 2 | baz
+ p2 | 2 | qux
+ p2 | 2 | xyzzy
+(3 rows)
+
+DROP TABLE pt;
-- privilege tests
SET ROLE regress_file_fdw_superuser;
SELECT * FROM agg_text ORDER BY a;
@@ -312,7 +395,7 @@ SELECT * FROM agg_text ORDER BY a;
SET ROLE regress_no_priv_user;
SELECT * FROM agg_text ORDER BY a; -- ERROR
-ERROR: permission denied for relation agg_text
+ERROR: permission denied for foreign table agg_text
SET ROLE regress_file_fdw_user;
\t on
EXPLAIN (VERBOSE, COSTS FALSE) SELECT * FROM agg_text WHERE a > 0;
diff --git a/contrib/fuzzystrmatch/.gitignore b/contrib/fuzzystrmatch/.gitignore
new file mode 100644
index 0000000000..5dcb3ff972
--- /dev/null
+++ b/contrib/fuzzystrmatch/.gitignore
@@ -0,0 +1,4 @@
+# Generated subdirectories
+/log/
+/results/
+/tmp_check/
diff --git a/contrib/fuzzystrmatch/Makefile b/contrib/fuzzystrmatch/Makefile
index 51e215a919..bd6f5e50d1 100644
--- a/contrib/fuzzystrmatch/Makefile
+++ b/contrib/fuzzystrmatch/Makefile
@@ -8,6 +8,8 @@ DATA = fuzzystrmatch--1.1.sql fuzzystrmatch--1.0--1.1.sql \
fuzzystrmatch--unpackaged--1.0.sql
PGFILEDESC = "fuzzystrmatch - similarities and distance between strings"
+REGRESS = fuzzystrmatch
+
ifdef USE_PGXS
PG_CONFIG = pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
diff --git a/contrib/fuzzystrmatch/dmetaphone.c b/contrib/fuzzystrmatch/dmetaphone.c
index 918ee0d90e..16e4c66167 100644
--- a/contrib/fuzzystrmatch/dmetaphone.c
+++ b/contrib/fuzzystrmatch/dmetaphone.c
@@ -232,7 +232,7 @@ metastring;
*/
static metastring *
-NewMetaString(char *init_str)
+NewMetaString(const char *init_str)
{
metastring *s;
char empty_string[] = "";
@@ -375,7 +375,7 @@ StringAt(metastring *s, int start, int length,...)
static void
-MetaphAdd(metastring *s, char *new_str)
+MetaphAdd(metastring *s, const char *new_str)
{
int add_length;
diff --git a/contrib/fuzzystrmatch/expected/fuzzystrmatch.out b/contrib/fuzzystrmatch/expected/fuzzystrmatch.out
new file mode 100644
index 0000000000..493c95cdfa
--- /dev/null
+++ b/contrib/fuzzystrmatch/expected/fuzzystrmatch.out
@@ -0,0 +1,67 @@
+CREATE EXTENSION fuzzystrmatch;
+SELECT soundex('hello world!');
+ soundex
+---------
+ H464
+(1 row)
+
+SELECT soundex('Anne'), soundex('Ann'), difference('Anne', 'Ann');
+ soundex | soundex | difference
+---------+---------+------------
+ A500 | A500 | 4
+(1 row)
+
+SELECT soundex('Anne'), soundex('Andrew'), difference('Anne', 'Andrew');
+ soundex | soundex | difference
+---------+---------+------------
+ A500 | A536 | 2
+(1 row)
+
+SELECT soundex('Anne'), soundex('Margaret'), difference('Anne', 'Margaret');
+ soundex | soundex | difference
+---------+---------+------------
+ A500 | M626 | 0
+(1 row)
+
+SELECT levenshtein('GUMBO', 'GAMBOL');
+ levenshtein
+-------------
+ 2
+(1 row)
+
+SELECT levenshtein('GUMBO', 'GAMBOL', 2, 1, 1);
+ levenshtein
+-------------
+ 3
+(1 row)
+
+SELECT levenshtein_less_equal('extensive', 'exhaustive', 2);
+ levenshtein_less_equal
+------------------------
+ 3
+(1 row)
+
+SELECT levenshtein_less_equal('extensive', 'exhaustive', 4);
+ levenshtein_less_equal
+------------------------
+ 4
+(1 row)
+
+SELECT metaphone('GUMBO', 4);
+ metaphone
+-----------
+ KM
+(1 row)
+
+SELECT dmetaphone('gumbo');
+ dmetaphone
+------------
+ KMP
+(1 row)
+
+SELECT dmetaphone_alt('gumbo');
+ dmetaphone_alt
+----------------
+ KMP
+(1 row)
+
diff --git a/contrib/fuzzystrmatch/fuzzystrmatch.c b/contrib/fuzzystrmatch/fuzzystrmatch.c
index ce58a6a7fc..05774658dc 100644
--- a/contrib/fuzzystrmatch/fuzzystrmatch.c
+++ b/contrib/fuzzystrmatch/fuzzystrmatch.c
@@ -6,7 +6,7 @@
* Joe Conway
*
* contrib/fuzzystrmatch/fuzzystrmatch.c
- * Copyright (c) 2001-2017, PostgreSQL Global Development Group
+ * Copyright (c) 2001-2018, PostgreSQL Global Development Group
* ALL RIGHTS RESERVED;
*
* metaphone()
@@ -87,25 +87,13 @@ soundex_code(char letter)
phoned_word -- The final phonized word. (We'll allocate the
memory.)
Output
- error -- A simple error flag, returns TRUE or FALSE
+ error -- A simple error flag, returns true or false
NOTES: ALL non-alpha characters are ignored, this includes whitespace,
although non-alpha characters will break up phonemes.
****************************************************************************/
-/**************************************************************************
- my constants -- constants I like
-
- Probably redundant.
-
-***************************************************************************/
-
-#define META_ERROR FALSE
-#define META_SUCCESS TRUE
-#define META_FAILURE FALSE
-
-
/* I add modifications to the traditional metaphone algorithm that you
might find in books. Define this if you want metaphone to behave
traditionally */
@@ -116,7 +104,7 @@ soundex_code(char letter)
#define TH '0'
static char Lookahead(char *word, int how_far);
-static int _metaphone(char *word, int max_phonemes, char **phoned_word);
+static void _metaphone(char *word, int max_phonemes, char **phoned_word);
/* Metachar.h ... little bits about characters for metaphone */
@@ -272,7 +260,6 @@ metaphone(PG_FUNCTION_ARGS)
size_t str_i_len = strlen(str_i);
int reqlen;
char *metaph;
- int retval;
/* return an empty string if we receive one */
if (!(str_i_len > 0))
@@ -296,17 +283,8 @@ metaphone(PG_FUNCTION_ARGS)
(errcode(ERRCODE_ZERO_LENGTH_CHARACTER_STRING),
errmsg("output cannot be empty string")));
-
- retval = _metaphone(str_i, reqlen, &metaph);
- if (retval == META_SUCCESS)
- PG_RETURN_TEXT_P(cstring_to_text(metaph));
- else
- {
- /* internal error */
- elog(ERROR, "metaphone: failure");
- /* keep the compiler quiet */
- PG_RETURN_NULL();
- }
+ _metaphone(str_i, reqlen, &metaph);
+ PG_RETURN_TEXT_P(cstring_to_text(metaph));
}
@@ -362,7 +340,7 @@ Lookahead(char *word, int how_far)
#define Isbreak(c) (!isalpha((unsigned char) (c)))
-static int
+static void
_metaphone(char *word, /* IN */
int max_phonemes,
char **phoned_word) /* OUT */
@@ -404,7 +382,7 @@ _metaphone(char *word, /* IN */
if (Curr_Letter == '\0')
{
End_Phoned_Word;
- return META_SUCCESS; /* For testing */
+ return;
}
}
@@ -721,7 +699,7 @@ _metaphone(char *word, /* IN */
End_Phoned_Word;
- return (META_SUCCESS);
+ return;
} /* END metaphone */
diff --git a/contrib/fuzzystrmatch/sql/fuzzystrmatch.sql b/contrib/fuzzystrmatch/sql/fuzzystrmatch.sql
new file mode 100644
index 0000000000..f05dc28ffb
--- /dev/null
+++ b/contrib/fuzzystrmatch/sql/fuzzystrmatch.sql
@@ -0,0 +1,21 @@
+CREATE EXTENSION fuzzystrmatch;
+
+
+SELECT soundex('hello world!');
+
+SELECT soundex('Anne'), soundex('Ann'), difference('Anne', 'Ann');
+SELECT soundex('Anne'), soundex('Andrew'), difference('Anne', 'Andrew');
+SELECT soundex('Anne'), soundex('Margaret'), difference('Anne', 'Margaret');
+
+
+SELECT levenshtein('GUMBO', 'GAMBOL');
+SELECT levenshtein('GUMBO', 'GAMBOL', 2, 1, 1);
+SELECT levenshtein_less_equal('extensive', 'exhaustive', 2);
+SELECT levenshtein_less_equal('extensive', 'exhaustive', 4);
+
+
+SELECT metaphone('GUMBO', 4);
+
+
+SELECT dmetaphone('gumbo');
+SELECT dmetaphone_alt('gumbo');
diff --git a/contrib/hstore/CMakeLists.txt b/contrib/hstore/CMakeLists.txt
index b75ff4d3ad..797cfb6a2a 100644
--- a/contrib/hstore/CMakeLists.txt
+++ b/contrib/hstore/CMakeLists.txt
@@ -31,6 +31,7 @@ install(FILES
${extension_name}--1.1--1.2.sql
${extension_name}--1.2--1.3.sql
${extension_name}--1.3--1.4.sql
+ ${extension_name}--1.4--1.5.sql
${extension_name}--unpackaged--1.0.sql
DESTINATION ${PGSHAREDIR}/extension)
diff --git a/contrib/hstore/Makefile b/contrib/hstore/Makefile
index 311cc099e5..ab7fef3979 100644
--- a/contrib/hstore/Makefile
+++ b/contrib/hstore/Makefile
@@ -5,7 +5,8 @@ OBJS = hstore_io.o hstore_op.o hstore_gist.o hstore_gin.o hstore_compat.o \
$(WIN32RES)
EXTENSION = hstore
-DATA = hstore--1.4.sql hstore--1.3--1.4.sql hstore--1.2--1.3.sql \
+DATA = hstore--1.4.sql hstore--1.4--1.5.sql \
+ hstore--1.3--1.4.sql hstore--1.2--1.3.sql \
hstore--1.1--1.2.sql hstore--1.0--1.1.sql \
hstore--unpackaged--1.0.sql
PGFILEDESC = "hstore - key/value pair data type"
diff --git a/contrib/hstore/hstore--1.4--1.5.sql b/contrib/hstore/hstore--1.4--1.5.sql
new file mode 100644
index 0000000000..92c1832dce
--- /dev/null
+++ b/contrib/hstore/hstore--1.4--1.5.sql
@@ -0,0 +1,14 @@
+/* contrib/hstore/hstore--1.4--1.5.sql */
+
+-- complain if script is sourced in psql, rather than via ALTER EXTENSION
+\echo Use "ALTER EXTENSION hstore UPDATE TO '1.5'" to load this file. \quit
+
+ALTER OPERATOR #<=# (hstore, hstore) SET (
+ RESTRICT = scalarlesel,
+ JOIN = scalarlejoinsel
+);
+
+ALTER OPERATOR #>=# (hstore, hstore) SET (
+ RESTRICT = scalargesel,
+ JOIN = scalargejoinsel
+);
diff --git a/contrib/hstore/hstore.control b/contrib/hstore/hstore.control
index f99a937acc..8a719475b8 100644
--- a/contrib/hstore/hstore.control
+++ b/contrib/hstore/hstore.control
@@ -1,5 +1,5 @@
# hstore extension
comment = 'data type for storing sets of (key, value) pairs'
-default_version = '1.4'
+default_version = '1.5'
module_pathname = '$libdir/hstore'
relocatable = true
diff --git a/contrib/hstore/hstore.h b/contrib/hstore/hstore.h
index c4862a82e1..bf4a565ed9 100644
--- a/contrib/hstore/hstore.h
+++ b/contrib/hstore/hstore.h
@@ -151,7 +151,7 @@ extern HStore *hstoreUpgrade(Datum orig);
#define DatumGetHStoreP(d) hstoreUpgrade(d)
-#define PG_GETARG_HS(x) DatumGetHStoreP(PG_GETARG_DATUM(x))
+#define PG_GETARG_HSTORE_P(x) DatumGetHStoreP(PG_GETARG_DATUM(x))
/*
diff --git a/contrib/hstore/hstore_gin.c b/contrib/hstore/hstore_gin.c
index d98fb38458..4c3a422643 100644
--- a/contrib/hstore/hstore_gin.c
+++ b/contrib/hstore/hstore_gin.c
@@ -43,7 +43,7 @@ makeitem(char *str, int len, char flag)
Datum
gin_extract_hstore(PG_FUNCTION_ARGS)
{
- HStore *hs = PG_GETARG_HS(0);
+ HStore *hs = PG_GETARG_HSTORE_P(0);
int32 *nentries = (int32 *) PG_GETARG_POINTER(1);
Datum *entries = NULL;
HEntry *hsent = ARRPTR(hs);
@@ -155,7 +155,7 @@ gin_consistent_hstore(PG_FUNCTION_ARGS)
bool *check = (bool *) PG_GETARG_POINTER(0);
StrategyNumber strategy = PG_GETARG_UINT16(1);
- /* HStore *query = PG_GETARG_HS(2); */
+ /* HStore *query = PG_GETARG_HSTORE_P(2); */
int32 nkeys = PG_GETARG_INT32(3);
/* Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4); */
diff --git a/contrib/hstore/hstore_gist.c b/contrib/hstore/hstore_gist.c
index f8f5934e40..6d24d2f468 100644
--- a/contrib/hstore/hstore_gist.c
+++ b/contrib/hstore/hstore_gist.c
@@ -144,7 +144,7 @@ ghstore_compress(PG_FUNCTION_ARGS)
gistentryinit(*retval, PointerGetDatum(res),
entry->rel, entry->page,
entry->offset,
- FALSE);
+ false);
}
else if (!ISALLTRUE(DatumGetPointer(entry->key)))
{
@@ -166,7 +166,7 @@ ghstore_compress(PG_FUNCTION_ARGS)
gistentryinit(*retval, PointerGetDatum(res),
entry->rel, entry->page,
entry->offset,
- FALSE);
+ false);
}
PG_RETURN_POINTER(retval);
@@ -518,7 +518,7 @@ ghstore_consistent(PG_FUNCTION_ARGS)
if (strategy == HStoreContainsStrategyNumber ||
strategy == HStoreOldContainsStrategyNumber)
{
- HStore *query = PG_GETARG_HS(1);
+ HStore *query = PG_GETARG_HSTORE_P(1);
HEntry *qe = ARRPTR(query);
char *qv = STRPTR(query);
int count = HS_COUNT(query);
@@ -570,7 +570,7 @@ ghstore_consistent(PG_FUNCTION_ARGS)
continue;
crc = crc32_sz(VARDATA(key_datums[i]), VARSIZE(key_datums[i]) - VARHDRSZ);
if (!(GETBIT(sign, HASHVAL(crc))))
- res = FALSE;
+ res = false;
}
}
else if (strategy == HStoreExistsAnyStrategyNumber)
@@ -585,7 +585,7 @@ ghstore_consistent(PG_FUNCTION_ARGS)
TEXTOID, -1, false, 'i',
&key_datums, &key_nulls, &key_count);
- res = FALSE;
+ res = false;
for (i = 0; !res && i < key_count; ++i)
{
@@ -595,7 +595,7 @@ ghstore_consistent(PG_FUNCTION_ARGS)
continue;
crc = crc32_sz(VARDATA(key_datums[i]), VARSIZE(key_datums[i]) - VARHDRSZ);
if (GETBIT(sign, HASHVAL(crc)))
- res = TRUE;
+ res = true;
}
}
else
diff --git a/contrib/hstore/hstore_io.c b/contrib/hstore/hstore_io.c
index e03005c923..7a741a779c 100644
--- a/contrib/hstore/hstore_io.c
+++ b/contrib/hstore/hstore_io.c
@@ -340,7 +340,8 @@ hstoreUniquePairs(Pairs *a, int32 l, int32 *buflen)
{
*buflen += res->keylen + ((res->isnull) ? 0 : res->vallen);
res++;
- memcpy(res, ptr, sizeof(Pairs));
+ if (res != ptr)
+ memcpy(res, ptr, sizeof(Pairs));
}
ptr++;
@@ -752,6 +753,8 @@ typedef struct RecordIOData
{
Oid record_type;
int32 record_typmod;
+ /* this field is used only if target type is domain over composite: */
+ void *domain_info; /* opaque cache for domain checks */
int ncolumns;
ColumnIOData columns[FLEXIBLE_ARRAY_MEMBER];
} RecordIOData;
@@ -780,9 +783,11 @@ hstore_from_record(PG_FUNCTION_ARGS)
Oid argtype = get_fn_expr_argtype(fcinfo->flinfo, 0);
/*
- * have no tuple to look at, so the only source of type info is the
- * argtype. The lookup_rowtype_tupdesc call below will error out if we
- * don't have a known composite type oid here.
+ * We have no tuple to look at, so the only source of type info is the
+ * argtype --- which might be domain over composite, but we don't care
+ * here, since we have no need to be concerned about domain
+ * constraints. The lookup_rowtype_tupdesc_domain call below will
+ * error out if we don't have a known composite type oid here.
*/
tupType = argtype;
tupTypmod = -1;
@@ -793,12 +798,15 @@ hstore_from_record(PG_FUNCTION_ARGS)
{
rec = PG_GETARG_HEAPTUPLEHEADER(0);
- /* Extract type info from the tuple itself */
+ /*
+ * Extract type info from the tuple itself -- this will work even for
+ * anonymous record types.
+ */
tupType = HeapTupleHeaderGetTypeId(rec);
tupTypmod = HeapTupleHeaderGetTypMod(rec);
}
- tupdesc = lookup_rowtype_tupdesc(tupType, tupTypmod);
+ tupdesc = lookup_rowtype_tupdesc_domain(tupType, tupTypmod, false);
ncolumns = tupdesc->natts;
/*
@@ -855,15 +863,16 @@ hstore_from_record(PG_FUNCTION_ARGS)
for (i = 0, j = 0; i < ncolumns; ++i)
{
ColumnIOData *column_info = &my_extra->columns[i];
- Oid column_type = tupdesc->attrs[i]->atttypid;
+ Form_pg_attribute att = TupleDescAttr(tupdesc, i);
+ Oid column_type = att->atttypid;
char *value;
/* Ignore dropped columns in datatype */
- if (tupdesc->attrs[i]->attisdropped)
+ if (att->attisdropped)
continue;
- pairs[j].key = NameStr(tupdesc->attrs[i]->attname);
- pairs[j].keylen = hstoreCheckKeyLen(strlen(NameStr(tupdesc->attrs[i]->attname)));
+ pairs[j].key = NameStr(att->attname);
+ pairs[j].keylen = hstoreCheckKeyLen(strlen(NameStr(att->attname)));
if (!nulls || nulls[i])
{
@@ -942,9 +951,9 @@ hstore_populate_record(PG_FUNCTION_ARGS)
rec = NULL;
/*
- * have no tuple to look at, so the only source of type info is the
- * argtype. The lookup_rowtype_tupdesc call below will error out if we
- * don't have a known composite type oid here.
+ * We have no tuple to look at, so the only source of type info is the
+ * argtype. The lookup_rowtype_tupdesc_domain call below will error
+ * out if we don't have a known composite type oid here.
*/
tupType = argtype;
tupTypmod = -1;
@@ -956,12 +965,15 @@ hstore_populate_record(PG_FUNCTION_ARGS)
if (PG_ARGISNULL(1))
PG_RETURN_POINTER(rec);
- /* Extract type info from the tuple itself */
+ /*
+ * Extract type info from the tuple itself -- this will work even for
+ * anonymous record types.
+ */
tupType = HeapTupleHeaderGetTypeId(rec);
tupTypmod = HeapTupleHeaderGetTypMod(rec);
}
- hs = PG_GETARG_HS(1);
+ hs = PG_GETARG_HSTORE_P(1);
entries = ARRPTR(hs);
ptr = STRPTR(hs);
@@ -974,7 +986,11 @@ hstore_populate_record(PG_FUNCTION_ARGS)
if (HS_COUNT(hs) == 0 && rec)
PG_RETURN_POINTER(rec);
- tupdesc = lookup_rowtype_tupdesc(tupType, tupTypmod);
+ /*
+ * Lookup the input record's tupdesc. For the moment, we don't worry
+ * about whether it is a domain over composite.
+ */
+ tupdesc = lookup_rowtype_tupdesc_domain(tupType, tupTypmod, false);
ncolumns = tupdesc->natts;
if (rec)
@@ -1001,6 +1017,7 @@ hstore_populate_record(PG_FUNCTION_ARGS)
my_extra = (RecordIOData *) fcinfo->flinfo->fn_extra;
my_extra->record_type = InvalidOid;
my_extra->record_typmod = 0;
+ my_extra->domain_info = NULL;
}
if (my_extra->record_type != tupType ||
@@ -1034,21 +1051,22 @@ hstore_populate_record(PG_FUNCTION_ARGS)
for (i = 0; i < ncolumns; ++i)
{
ColumnIOData *column_info = &my_extra->columns[i];
- Oid column_type = tupdesc->attrs[i]->atttypid;
+ Form_pg_attribute att = TupleDescAttr(tupdesc, i);
+ Oid column_type = att->atttypid;
char *value;
int idx;
int vallen;
/* Ignore dropped columns in datatype */
- if (tupdesc->attrs[i]->attisdropped)
+ if (att->attisdropped)
{
nulls[i] = true;
continue;
}
idx = hstoreFindKey(hs, 0,
- NameStr(tupdesc->attrs[i]->attname),
- strlen(NameStr(tupdesc->attrs[i]->attname)));
+ NameStr(att->attname),
+ strlen(NameStr(att->attname)));
/*
* we can't just skip here if the key wasn't found since we might have
@@ -1082,7 +1100,7 @@ hstore_populate_record(PG_FUNCTION_ARGS)
*/
values[i] = InputFunctionCall(&column_info->proc, NULL,
column_info->typioparam,
- tupdesc->attrs[i]->atttypmod);
+ att->atttypmod);
nulls[i] = true;
}
else
@@ -1094,13 +1112,24 @@ hstore_populate_record(PG_FUNCTION_ARGS)
values[i] = InputFunctionCall(&column_info->proc, value,
column_info->typioparam,
- tupdesc->attrs[i]->atttypmod);
+ att->atttypmod);
nulls[i] = false;
}
}
rettuple = heap_form_tuple(tupdesc, values, nulls);
+ /*
+ * If the target type is domain over composite, all we know at this point
+ * is that we've made a valid value of the base composite type. Must
+ * check domain constraints before deciding we're done.
+ */
+ if (argtype != tupdesc->tdtypeid)
+ domain_check(HeapTupleGetDatum(rettuple), false,
+ argtype,
+ &my_extra->domain_info,
+ fcinfo->flinfo->fn_mcxt);
+
ReleaseTupleDesc(tupdesc);
PG_RETURN_DATUM(HeapTupleGetDatum(rettuple));
@@ -1125,7 +1154,7 @@ PG_FUNCTION_INFO_V1(hstore_out);
Datum
hstore_out(PG_FUNCTION_ARGS)
{
- HStore *in = PG_GETARG_HS(0);
+ HStore *in = PG_GETARG_HSTORE_P(0);
int buflen,
i;
int count = HS_COUNT(in);
@@ -1196,7 +1225,7 @@ PG_FUNCTION_INFO_V1(hstore_send);
Datum
hstore_send(PG_FUNCTION_ARGS)
{
- HStore *in = PG_GETARG_HS(0);
+ HStore *in = PG_GETARG_HSTORE_P(0);
int i;
int count = HS_COUNT(in);
char *base = STRPTR(in);
@@ -1205,23 +1234,23 @@ hstore_send(PG_FUNCTION_ARGS)
pq_begintypsend(&buf);
- pq_sendint(&buf, count, 4);
+ pq_sendint32(&buf, count);
for (i = 0; i < count; i++)
{
int32 keylen = HSTORE_KEYLEN(entries, i);
- pq_sendint(&buf, keylen, 4);
+ pq_sendint32(&buf, keylen);
pq_sendtext(&buf, HSTORE_KEY(entries, base, i), keylen);
if (HSTORE_VALISNULL(entries, i))
{
- pq_sendint(&buf, -1, 4);
+ pq_sendint32(&buf, -1);
}
else
{
int32 vallen = HSTORE_VALLEN(entries, i);
- pq_sendint(&buf, vallen, 4);
+ pq_sendint32(&buf, vallen);
pq_sendtext(&buf, HSTORE_VAL(entries, base, i), vallen);
}
}
@@ -1242,7 +1271,7 @@ PG_FUNCTION_INFO_V1(hstore_to_json_loose);
Datum
hstore_to_json_loose(PG_FUNCTION_ARGS)
{
- HStore *in = PG_GETARG_HS(0);
+ HStore *in = PG_GETARG_HSTORE_P(0);
int i;
int count = HS_COUNT(in);
char *base = STRPTR(in);
@@ -1297,7 +1326,7 @@ PG_FUNCTION_INFO_V1(hstore_to_json);
Datum
hstore_to_json(PG_FUNCTION_ARGS)
{
- HStore *in = PG_GETARG_HS(0);
+ HStore *in = PG_GETARG_HSTORE_P(0);
int i;
int count = HS_COUNT(in);
char *base = STRPTR(in);
@@ -1342,7 +1371,7 @@ PG_FUNCTION_INFO_V1(hstore_to_jsonb);
Datum
hstore_to_jsonb(PG_FUNCTION_ARGS)
{
- HStore *in = PG_GETARG_HS(0);
+ HStore *in = PG_GETARG_HSTORE_P(0);
int i;
int count = HS_COUNT(in);
char *base = STRPTR(in);
@@ -1385,7 +1414,7 @@ PG_FUNCTION_INFO_V1(hstore_to_jsonb_loose);
Datum
hstore_to_jsonb_loose(PG_FUNCTION_ARGS)
{
- HStore *in = PG_GETARG_HS(0);
+ HStore *in = PG_GETARG_HSTORE_P(0);
int i;
int count = HS_COUNT(in);
char *base = STRPTR(in);
diff --git a/contrib/hstore/hstore_op.c b/contrib/hstore/hstore_op.c
index 612be23a74..8f9277f8da 100644
--- a/contrib/hstore/hstore_op.c
+++ b/contrib/hstore/hstore_op.c
@@ -130,7 +130,7 @@ PG_FUNCTION_INFO_V1(hstore_fetchval);
Datum
hstore_fetchval(PG_FUNCTION_ARGS)
{
- HStore *hs = PG_GETARG_HS(0);
+ HStore *hs = PG_GETARG_HSTORE_P(0);
text *key = PG_GETARG_TEXT_PP(1);
HEntry *entries = ARRPTR(hs);
text *out;
@@ -151,7 +151,7 @@ PG_FUNCTION_INFO_V1(hstore_exists);
Datum
hstore_exists(PG_FUNCTION_ARGS)
{
- HStore *hs = PG_GETARG_HS(0);
+ HStore *hs = PG_GETARG_HSTORE_P(0);
text *key = PG_GETARG_TEXT_PP(1);
int idx = hstoreFindKey(hs, NULL,
VARDATA_ANY(key), VARSIZE_ANY_EXHDR(key));
@@ -164,7 +164,7 @@ PG_FUNCTION_INFO_V1(hstore_exists_any);
Datum
hstore_exists_any(PG_FUNCTION_ARGS)
{
- HStore *hs = PG_GETARG_HS(0);
+ HStore *hs = PG_GETARG_HSTORE_P(0);
ArrayType *keys = PG_GETARG_ARRAYTYPE_P(1);
int nkeys;
Pairs *key_pairs = hstoreArrayToPairs(keys, &nkeys);
@@ -198,7 +198,7 @@ PG_FUNCTION_INFO_V1(hstore_exists_all);
Datum
hstore_exists_all(PG_FUNCTION_ARGS)
{
- HStore *hs = PG_GETARG_HS(0);
+ HStore *hs = PG_GETARG_HSTORE_P(0);
ArrayType *keys = PG_GETARG_ARRAYTYPE_P(1);
int nkeys;
Pairs *key_pairs = hstoreArrayToPairs(keys, &nkeys);
@@ -232,7 +232,7 @@ PG_FUNCTION_INFO_V1(hstore_defined);
Datum
hstore_defined(PG_FUNCTION_ARGS)
{
- HStore *hs = PG_GETARG_HS(0);
+ HStore *hs = PG_GETARG_HSTORE_P(0);
text *key = PG_GETARG_TEXT_PP(1);
HEntry *entries = ARRPTR(hs);
int idx = hstoreFindKey(hs, NULL,
@@ -247,7 +247,7 @@ PG_FUNCTION_INFO_V1(hstore_delete);
Datum
hstore_delete(PG_FUNCTION_ARGS)
{
- HStore *hs = PG_GETARG_HS(0);
+ HStore *hs = PG_GETARG_HSTORE_P(0);
text *key = PG_GETARG_TEXT_PP(1);
char *keyptr = VARDATA_ANY(key);
int keylen = VARSIZE_ANY_EXHDR(key);
@@ -294,7 +294,7 @@ PG_FUNCTION_INFO_V1(hstore_delete_array);
Datum
hstore_delete_array(PG_FUNCTION_ARGS)
{
- HStore *hs = PG_GETARG_HS(0);
+ HStore *hs = PG_GETARG_HSTORE_P(0);
HStore *out = palloc(VARSIZE(hs));
int hs_count = HS_COUNT(hs);
char *ps,
@@ -373,8 +373,8 @@ PG_FUNCTION_INFO_V1(hstore_delete_hstore);
Datum
hstore_delete_hstore(PG_FUNCTION_ARGS)
{
- HStore *hs = PG_GETARG_HS(0);
- HStore *hs2 = PG_GETARG_HS(1);
+ HStore *hs = PG_GETARG_HSTORE_P(0);
+ HStore *hs2 = PG_GETARG_HSTORE_P(1);
HStore *out = palloc(VARSIZE(hs));
int hs_count = HS_COUNT(hs);
int hs2_count = HS_COUNT(hs2);
@@ -473,8 +473,8 @@ PG_FUNCTION_INFO_V1(hstore_concat);
Datum
hstore_concat(PG_FUNCTION_ARGS)
{
- HStore *s1 = PG_GETARG_HS(0);
- HStore *s2 = PG_GETARG_HS(1);
+ HStore *s1 = PG_GETARG_HSTORE_P(0);
+ HStore *s2 = PG_GETARG_HSTORE_P(1);
HStore *out = palloc(VARSIZE(s1) + VARSIZE(s2));
char *ps1,
*ps2,
@@ -571,7 +571,7 @@ PG_FUNCTION_INFO_V1(hstore_slice_to_array);
Datum
hstore_slice_to_array(PG_FUNCTION_ARGS)
{
- HStore *hs = PG_GETARG_HS(0);
+ HStore *hs = PG_GETARG_HSTORE_P(0);
HEntry *entries = ARRPTR(hs);
char *ptr = STRPTR(hs);
ArrayType *key_array = PG_GETARG_ARRAYTYPE_P(1);
@@ -634,7 +634,7 @@ PG_FUNCTION_INFO_V1(hstore_slice_to_hstore);
Datum
hstore_slice_to_hstore(PG_FUNCTION_ARGS)
{
- HStore *hs = PG_GETARG_HS(0);
+ HStore *hs = PG_GETARG_HSTORE_P(0);
HEntry *entries = ARRPTR(hs);
char *ptr = STRPTR(hs);
ArrayType *key_array = PG_GETARG_ARRAYTYPE_P(1);
@@ -696,7 +696,7 @@ PG_FUNCTION_INFO_V1(hstore_akeys);
Datum
hstore_akeys(PG_FUNCTION_ARGS)
{
- HStore *hs = PG_GETARG_HS(0);
+ HStore *hs = PG_GETARG_HSTORE_P(0);
Datum *d;
ArrayType *a;
HEntry *entries = ARRPTR(hs);
@@ -731,7 +731,7 @@ PG_FUNCTION_INFO_V1(hstore_avals);
Datum
hstore_avals(PG_FUNCTION_ARGS)
{
- HStore *hs = PG_GETARG_HS(0);
+ HStore *hs = PG_GETARG_HSTORE_P(0);
Datum *d;
bool *nulls;
ArrayType *a;
@@ -827,7 +827,7 @@ PG_FUNCTION_INFO_V1(hstore_to_array);
Datum
hstore_to_array(PG_FUNCTION_ARGS)
{
- HStore *hs = PG_GETARG_HS(0);
+ HStore *hs = PG_GETARG_HSTORE_P(0);
ArrayType *out = hstore_to_array_internal(hs, 1);
PG_RETURN_POINTER(out);
@@ -837,7 +837,7 @@ PG_FUNCTION_INFO_V1(hstore_to_matrix);
Datum
hstore_to_matrix(PG_FUNCTION_ARGS)
{
- HStore *hs = PG_GETARG_HS(0);
+ HStore *hs = PG_GETARG_HSTORE_P(0);
ArrayType *out = hstore_to_array_internal(hs, 2);
PG_RETURN_POINTER(out);
@@ -891,7 +891,7 @@ hstore_skeys(PG_FUNCTION_ARGS)
if (SRF_IS_FIRSTCALL())
{
- hs = PG_GETARG_HS(0);
+ hs = PG_GETARG_HSTORE_P(0);
funcctx = SRF_FIRSTCALL_INIT();
setup_firstcall(funcctx, hs, NULL);
}
@@ -925,7 +925,7 @@ hstore_svals(PG_FUNCTION_ARGS)
if (SRF_IS_FIRSTCALL())
{
- hs = PG_GETARG_HS(0);
+ hs = PG_GETARG_HSTORE_P(0);
funcctx = SRF_FIRSTCALL_INIT();
setup_firstcall(funcctx, hs, NULL);
}
@@ -967,8 +967,8 @@ PG_FUNCTION_INFO_V1(hstore_contains);
Datum
hstore_contains(PG_FUNCTION_ARGS)
{
- HStore *val = PG_GETARG_HS(0);
- HStore *tmpl = PG_GETARG_HS(1);
+ HStore *val = PG_GETARG_HSTORE_P(0);
+ HStore *tmpl = PG_GETARG_HSTORE_P(1);
bool res = true;
HEntry *te = ARRPTR(tmpl);
char *tstr = STRPTR(tmpl);
@@ -1032,7 +1032,7 @@ hstore_each(PG_FUNCTION_ARGS)
if (SRF_IS_FIRSTCALL())
{
- hs = PG_GETARG_HS(0);
+ hs = PG_GETARG_HSTORE_P(0);
funcctx = SRF_FIRSTCALL_INIT();
setup_firstcall(funcctx, hs, fcinfo);
}
@@ -1087,8 +1087,8 @@ PG_FUNCTION_INFO_V1(hstore_cmp);
Datum
hstore_cmp(PG_FUNCTION_ARGS)
{
- HStore *hs1 = PG_GETARG_HS(0);
- HStore *hs2 = PG_GETARG_HS(1);
+ HStore *hs1 = PG_GETARG_HSTORE_P(0);
+ HStore *hs2 = PG_GETARG_HSTORE_P(1);
int hcount1 = HS_COUNT(hs1);
int hcount2 = HS_COUNT(hs2);
int res = 0;
@@ -1235,7 +1235,7 @@ PG_FUNCTION_INFO_V1(hstore_hash);
Datum
hstore_hash(PG_FUNCTION_ARGS)
{
- HStore *hs = PG_GETARG_HS(0);
+ HStore *hs = PG_GETARG_HSTORE_P(0);
Datum hval = hash_any((unsigned char *) VARDATA(hs),
VARSIZE(hs) - VARHDRSZ);
diff --git a/contrib/hstore_plperl/hstore_plperl.c b/contrib/hstore_plperl/hstore_plperl.c
index cc46a525f6..6bc3bb37fc 100644
--- a/contrib/hstore_plperl/hstore_plperl.c
+++ b/contrib/hstore_plperl/hstore_plperl.c
@@ -68,7 +68,7 @@ Datum
hstore_to_plperl(PG_FUNCTION_ARGS)
{
dTHX;
- HStore *in = PG_GETARG_HS(0);
+ HStore *in = PG_GETARG_HSTORE_P(0);
int i;
int count = HS_COUNT(in);
char *base = STRPTR(in);
diff --git a/contrib/hstore_plpython/expected/hstore_plpython.out b/contrib/hstore_plpython/expected/hstore_plpython.out
index df49cd5f37..1ab5feea93 100644
--- a/contrib/hstore_plpython/expected/hstore_plpython.out
+++ b/contrib/hstore_plpython/expected/hstore_plpython.out
@@ -68,12 +68,30 @@ AS $$
val = [{'a': 1, 'b': 'boo', 'c': None}, {'d': 2}]
return val
$$;
- SELECT test2arr();
+SELECT test2arr();
test2arr
--------------------------------------------------------------
{"\"a\"=>\"1\", \"b\"=>\"boo\", \"c\"=>NULL","\"d\"=>\"2\""}
(1 row)
+-- test python -> domain over hstore
+CREATE DOMAIN hstore_foo AS hstore CHECK(VALUE ? 'foo');
+CREATE FUNCTION test2dom(fn text) RETURNS hstore_foo
+LANGUAGE plpythonu
+TRANSFORM FOR TYPE hstore
+AS $$
+return {'a': 1, fn: 'boo', 'c': None}
+$$;
+SELECT test2dom('foo');
+ test2dom
+-----------------------------------
+ "a"=>"1", "c"=>NULL, "foo"=>"boo"
+(1 row)
+
+SELECT test2dom('bar'); -- fail
+ERROR: value for domain hstore_foo violates check constraint "hstore_foo_check"
+CONTEXT: while creating return value
+PL/Python function "test2dom"
-- test as part of prepare/execute
CREATE FUNCTION test3() RETURNS void
LANGUAGE plpythonu
diff --git a/contrib/hstore_plpython/hstore_plpython.c b/contrib/hstore_plpython/hstore_plpython.c
index b184324ebf..218e6612b1 100644
--- a/contrib/hstore_plpython/hstore_plpython.c
+++ b/contrib/hstore_plpython/hstore_plpython.c
@@ -85,7 +85,7 @@ PG_FUNCTION_INFO_V1(hstore_to_plpython);
Datum
hstore_to_plpython(PG_FUNCTION_ARGS)
{
- HStore *in = PG_GETARG_HS(0);
+ HStore *in = PG_GETARG_HSTORE_P(0);
int i;
int count = HS_COUNT(in);
char *base = STRPTR(in);
@@ -93,6 +93,10 @@ hstore_to_plpython(PG_FUNCTION_ARGS)
PyObject *dict;
dict = PyDict_New();
+ if (!dict)
+ ereport(ERROR,
+ (errcode(ERRCODE_OUT_OF_MEMORY),
+ errmsg("out of memory")));
for (i = 0; i < count; i++)
{
diff --git a/contrib/hstore_plpython/sql/hstore_plpython.sql b/contrib/hstore_plpython/sql/hstore_plpython.sql
index 911bbd67fe..2c54ee6aaa 100644
--- a/contrib/hstore_plpython/sql/hstore_plpython.sql
+++ b/contrib/hstore_plpython/sql/hstore_plpython.sql
@@ -60,7 +60,21 @@ val = [{'a': 1, 'b': 'boo', 'c': None}, {'d': 2}]
return val
$$;
- SELECT test2arr();
+SELECT test2arr();
+
+
+-- test python -> domain over hstore
+CREATE DOMAIN hstore_foo AS hstore CHECK(VALUE ? 'foo');
+
+CREATE FUNCTION test2dom(fn text) RETURNS hstore_foo
+LANGUAGE plpythonu
+TRANSFORM FOR TYPE hstore
+AS $$
+return {'a': 1, fn: 'boo', 'c': None}
+$$;
+
+SELECT test2dom('foo');
+SELECT test2dom('bar'); -- fail
-- test as part of prepare/execute
diff --git a/contrib/intarray/_int_bool.c b/contrib/intarray/_int_bool.c
index a18c645606..91e2a804f2 100644
--- a/contrib/intarray/_int_bool.c
+++ b/contrib/intarray/_int_bool.c
@@ -245,7 +245,7 @@ checkcondition_arr(void *checkval, ITEM *item)
{
StopMiddle = StopLow + (StopHigh - StopLow) / 2;
if (*StopMiddle == item->val)
- return (true);
+ return true;
else if (*StopMiddle < item->val)
StopLow = StopMiddle + 1;
else
@@ -274,7 +274,7 @@ execute(ITEM *curitem, void *checkval, bool calcnot,
return (*chkcond) (checkval, curitem);
else if (curitem->val == (int32) '!')
{
- return (calcnot) ?
+ return calcnot ?
((execute(curitem - 1, checkval, calcnot, chkcond)) ? false : true)
: true;
}
@@ -342,7 +342,7 @@ gin_bool_consistent(QUERYTYPE *query, bool *check)
j = 0;
if (query->size <= 0)
- return FALSE;
+ return false;
/*
* Set up data for checkcondition_gin. This must agree with the query
diff --git a/contrib/intarray/_int_gin.c b/contrib/intarray/_int_gin.c
index 73628bea11..7aebfec54b 100644
--- a/contrib/intarray/_int_gin.c
+++ b/contrib/intarray/_int_gin.c
@@ -116,7 +116,7 @@ ginint4_consistent(PG_FUNCTION_ARGS)
/* Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4); */
bool *recheck = (bool *) PG_GETARG_POINTER(5);
- bool res = FALSE;
+ bool res = false;
int32 i;
switch (strategy)
@@ -125,25 +125,25 @@ ginint4_consistent(PG_FUNCTION_ARGS)
/* result is not lossy */
*recheck = false;
/* at least one element in check[] is true, so result = true */
- res = TRUE;
+ res = true;
break;
case RTContainedByStrategyNumber:
case RTOldContainedByStrategyNumber:
/* we will need recheck */
*recheck = true;
/* at least one element in check[] is true, so result = true */
- res = TRUE;
+ res = true;
break;
case RTSameStrategyNumber:
/* we will need recheck */
*recheck = true;
/* Must have all elements in check[] true */
- res = TRUE;
+ res = true;
for (i = 0; i < nkeys; i++)
{
if (!check[i])
{
- res = FALSE;
+ res = false;
break;
}
}
@@ -153,12 +153,12 @@ ginint4_consistent(PG_FUNCTION_ARGS)
/* result is not lossy */
*recheck = false;
/* Must have all elements in check[] true */
- res = TRUE;
+ res = true;
for (i = 0; i < nkeys; i++)
{
if (!check[i])
{
- res = FALSE;
+ res = false;
break;
}
}
diff --git a/contrib/intarray/_int_gist.c b/contrib/intarray/_int_gist.c
index 79521b29b0..911d18023b 100644
--- a/contrib/intarray/_int_gist.c
+++ b/contrib/intarray/_int_gist.c
@@ -27,7 +27,7 @@ PG_FUNCTION_INFO_V1(g_int_same);
/*
** The GiST Consistent method for _intments
** Should return false if for all data items x below entry,
-** the predicate x op query == FALSE, where op is the oper
+** the predicate x op query == false, where op is the oper
** corresponding to strategy in the pg_amop table.
*/
Datum
@@ -89,7 +89,7 @@ g_int_consistent(PG_FUNCTION_ARGS)
query);
break;
default:
- retval = FALSE;
+ retval = false;
}
pfree(query);
PG_RETURN_BOOL(retval);
@@ -159,7 +159,7 @@ g_int_compress(PG_FUNCTION_ARGS)
retval = palloc(sizeof(GISTENTRY));
gistentryinit(*retval, PointerGetDatum(r),
- entry->rel, entry->page, entry->offset, FALSE);
+ entry->rel, entry->page, entry->offset, false);
PG_RETURN_POINTER(retval);
}
@@ -206,7 +206,7 @@ g_int_compress(PG_FUNCTION_ARGS)
r = resize_intArrayType(r, len);
retval = palloc(sizeof(GISTENTRY));
gistentryinit(*retval, PointerGetDatum(r),
- entry->rel, entry->page, entry->offset, FALSE);
+ entry->rel, entry->page, entry->offset, false);
PG_RETURN_POINTER(retval);
}
else
@@ -236,7 +236,7 @@ g_int_decompress(PG_FUNCTION_ARGS)
{
retval = palloc(sizeof(GISTENTRY));
gistentryinit(*retval, PointerGetDatum(in),
- entry->rel, entry->page, entry->offset, FALSE);
+ entry->rel, entry->page, entry->offset, false);
PG_RETURN_POINTER(retval);
}
@@ -251,7 +251,7 @@ g_int_decompress(PG_FUNCTION_ARGS)
{
retval = palloc(sizeof(GISTENTRY));
gistentryinit(*retval, PointerGetDatum(in),
- entry->rel, entry->page, entry->offset, FALSE);
+ entry->rel, entry->page, entry->offset, false);
PG_RETURN_POINTER(retval);
}
@@ -273,7 +273,7 @@ g_int_decompress(PG_FUNCTION_ARGS)
pfree(in);
retval = palloc(sizeof(GISTENTRY));
gistentryinit(*retval, PointerGetDatum(r),
- entry->rel, entry->page, entry->offset, FALSE);
+ entry->rel, entry->page, entry->offset, false);
PG_RETURN_POINTER(retval);
}
@@ -321,14 +321,14 @@ g_int_same(PG_FUNCTION_ARGS)
*result = false;
PG_RETURN_POINTER(result);
}
- *result = TRUE;
+ *result = true;
da = ARRPTR(a);
db = ARRPTR(b);
while (n--)
{
if (*da++ != *db++)
{
- *result = FALSE;
+ *result = false;
break;
}
}
diff --git a/contrib/intarray/_int_op.c b/contrib/intarray/_int_op.c
index 3637c4564c..fe7fcc4662 100644
--- a/contrib/intarray/_int_op.c
+++ b/contrib/intarray/_int_op.c
@@ -74,19 +74,19 @@ _int_same(PG_FUNCTION_ARGS)
da = ARRPTR(a);
db = ARRPTR(b);
- result = FALSE;
+ result = false;
if (na == nb)
{
SORT(a);
SORT(b);
- result = TRUE;
+ result = true;
for (n = 0; n < na; n++)
{
if (da[n] != db[n])
{
- result = FALSE;
+ result = false;
break;
}
}
@@ -110,7 +110,7 @@ _int_overlap(PG_FUNCTION_ARGS)
CHECKARRVALID(a);
CHECKARRVALID(b);
if (ARRISEMPTY(a) || ARRISEMPTY(b))
- return FALSE;
+ return false;
SORT(a);
SORT(b);
diff --git a/contrib/intarray/_int_selfuncs.c b/contrib/intarray/_int_selfuncs.c
index acb87d10f0..4c3f60c1dd 100644
--- a/contrib/intarray/_int_selfuncs.c
+++ b/contrib/intarray/_int_selfuncs.c
@@ -3,7 +3,7 @@
* _int_selfuncs.c
* Functions for selectivity estimation of intarray operators
*
- * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
*
diff --git a/contrib/intarray/_int_tool.c b/contrib/intarray/_int_tool.c
index 2fdfd2ec63..ee8fb64a47 100644
--- a/contrib/intarray/_int_tool.c
+++ b/contrib/intarray/_int_tool.c
@@ -40,7 +40,7 @@ inner_int_contains(ArrayType *a, ArrayType *b)
break; /* db[j] is not in da */
}
- return (n == nb) ? TRUE : FALSE;
+ return (n == nb) ? true : false;
}
/* arguments are assumed sorted */
@@ -65,12 +65,12 @@ inner_int_overlap(ArrayType *a, ArrayType *b)
if (da[i] < db[j])
i++;
else if (da[i] == db[j])
- return TRUE;
+ return true;
else
j++;
}
- return FALSE;
+ return false;
}
ArrayType *
diff --git a/contrib/intarray/_intbig_gist.c b/contrib/intarray/_intbig_gist.c
index 6dae7c91c1..de7bc82a23 100644
--- a/contrib/intarray/_intbig_gist.c
+++ b/contrib/intarray/_intbig_gist.c
@@ -168,7 +168,7 @@ g_intbig_compress(PG_FUNCTION_ARGS)
retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
gistentryinit(*retval, PointerGetDatum(res),
entry->rel, entry->page,
- entry->offset, FALSE);
+ entry->offset, false);
if (in != DatumGetArrayTypeP(entry->key))
pfree(in);
@@ -195,7 +195,7 @@ g_intbig_compress(PG_FUNCTION_ARGS)
retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
gistentryinit(*retval, PointerGetDatum(res),
entry->rel, entry->page,
- entry->offset, FALSE);
+ entry->offset, false);
PG_RETURN_POINTER(retval);
}
@@ -594,7 +594,7 @@ g_intbig_consistent(PG_FUNCTION_ARGS)
retval = _intbig_overlap((GISTTYPE *) DatumGetPointer(entry->key), query);
break;
default:
- retval = FALSE;
+ retval = false;
}
PG_FREE_IF_COPY(query, 1);
PG_RETURN_BOOL(retval);
diff --git a/contrib/isn/CMakeLists.txt b/contrib/isn/CMakeLists.txt
index 6180d4e955..3233da7415 100644
--- a/contrib/isn/CMakeLists.txt
+++ b/contrib/isn/CMakeLists.txt
@@ -19,6 +19,7 @@ install(FILES
${extension_name}.control
${extension_name}--1.1.sql
${extension_name}--1.0--1.1.sql
+ ${extension_name}--1.1--1.2.sql
${extension_name}--unpackaged--1.0.sql
DESTINATION ${PGSHAREDIR}/extension)
diff --git a/contrib/isn/Makefile b/contrib/isn/Makefile
index 9543a4b1cf..ab6b175f9a 100644
--- a/contrib/isn/Makefile
+++ b/contrib/isn/Makefile
@@ -3,7 +3,8 @@
MODULES = isn
EXTENSION = isn
-DATA = isn--1.1.sql isn--1.0--1.1.sql isn--unpackaged--1.0.sql
+DATA = isn--1.1.sql isn--1.1--1.2.sql \
+ isn--1.0--1.1.sql isn--unpackaged--1.0.sql
PGFILEDESC = "isn - data types for international product numbering standards"
REGRESS = isn
diff --git a/contrib/isn/isn--1.1--1.2.sql b/contrib/isn/isn--1.1--1.2.sql
new file mode 100644
index 0000000000..d626a5f44d
--- /dev/null
+++ b/contrib/isn/isn--1.1--1.2.sql
@@ -0,0 +1,228 @@
+/* contrib/isn/isn--1.1--1.2.sql */
+
+-- complain if script is sourced in psql, rather than via ALTER EXTENSION
+\echo Use "ALTER EXTENSION isn UPDATE TO '1.2'" to load this file. \quit
+
+ALTER OPERATOR <= (ean13, ean13) SET (
+ RESTRICT = scalarlesel,
+ JOIN = scalarlejoinsel);
+
+ALTER OPERATOR >= (ean13, ean13) SET (
+ RESTRICT = scalargesel,
+ JOIN = scalargejoinsel);
+
+ALTER OPERATOR <= (ean13, isbn13) SET (
+ RESTRICT = scalarlesel,
+ JOIN = scalarlejoinsel);
+
+ALTER OPERATOR >= (ean13, isbn13) SET (
+ RESTRICT = scalargesel,
+ JOIN = scalargejoinsel);
+
+ALTER OPERATOR <= (isbn13, ean13) SET (
+ RESTRICT = scalarlesel,
+ JOIN = scalarlejoinsel);
+
+ALTER OPERATOR >= (isbn13, ean13) SET (
+ RESTRICT = scalargesel,
+ JOIN = scalargejoinsel);
+
+ALTER OPERATOR <= (ean13, ismn13) SET (
+ RESTRICT = scalarlesel,
+ JOIN = scalarlejoinsel);
+
+ALTER OPERATOR >= (ean13, ismn13) SET (
+ RESTRICT = scalargesel,
+ JOIN = scalargejoinsel);
+
+ALTER OPERATOR <= (ismn13, ean13) SET (
+ RESTRICT = scalarlesel,
+ JOIN = scalarlejoinsel);
+
+ALTER OPERATOR >= (ismn13, ean13) SET (
+ RESTRICT = scalargesel,
+ JOIN = scalargejoinsel);
+
+ALTER OPERATOR <= (ean13, issn13) SET (
+ RESTRICT = scalarlesel,
+ JOIN = scalarlejoinsel);
+
+ALTER OPERATOR >= (ean13, issn13) SET (
+ RESTRICT = scalargesel,
+ JOIN = scalargejoinsel);
+
+ALTER OPERATOR <= (ean13, isbn) SET (
+ RESTRICT = scalarlesel,
+ JOIN = scalarlejoinsel);
+
+ALTER OPERATOR >= (ean13, isbn) SET (
+ RESTRICT = scalargesel,
+ JOIN = scalargejoinsel);
+
+ALTER OPERATOR <= (ean13, ismn) SET (
+ RESTRICT = scalarlesel,
+ JOIN = scalarlejoinsel);
+
+ALTER OPERATOR >= (ean13, ismn) SET (
+ RESTRICT = scalargesel,
+ JOIN = scalargejoinsel);
+
+ALTER OPERATOR <= (ean13, issn) SET (
+ RESTRICT = scalarlesel,
+ JOIN = scalarlejoinsel);
+
+ALTER OPERATOR >= (ean13, issn) SET (
+ RESTRICT = scalargesel,
+ JOIN = scalargejoinsel);
+
+ALTER OPERATOR <= (ean13, upc) SET (
+ RESTRICT = scalarlesel,
+ JOIN = scalarlejoinsel);
+
+ALTER OPERATOR >= (ean13, upc) SET (
+ RESTRICT = scalargesel,
+ JOIN = scalargejoinsel);
+
+ALTER OPERATOR <= (isbn13, isbn13) SET (
+ RESTRICT = scalarlesel,
+ JOIN = scalarlejoinsel);
+
+ALTER OPERATOR >= (isbn13, isbn13) SET (
+ RESTRICT = scalargesel,
+ JOIN = scalargejoinsel);
+
+ALTER OPERATOR <= (isbn13, isbn) SET (
+ RESTRICT = scalarlesel,
+ JOIN = scalarlejoinsel);
+
+ALTER OPERATOR >= (isbn13, isbn) SET (
+ RESTRICT = scalargesel,
+ JOIN = scalargejoinsel);
+
+ALTER OPERATOR <= (isbn, isbn) SET (
+ RESTRICT = scalarlesel,
+ JOIN = scalarlejoinsel);
+
+ALTER OPERATOR >= (isbn, isbn) SET (
+ RESTRICT = scalargesel,
+ JOIN = scalargejoinsel);
+
+ALTER OPERATOR <= (isbn, isbn13) SET (
+ RESTRICT = scalarlesel,
+ JOIN = scalarlejoinsel);
+
+ALTER OPERATOR >= (isbn, isbn13) SET (
+ RESTRICT = scalargesel,
+ JOIN = scalargejoinsel);
+
+ALTER OPERATOR <= (isbn, ean13) SET (
+ RESTRICT = scalarlesel,
+ JOIN = scalarlejoinsel);
+
+ALTER OPERATOR >= (isbn, ean13) SET (
+ RESTRICT = scalargesel,
+ JOIN = scalargejoinsel);
+
+ALTER OPERATOR <= (ismn13, ismn13) SET (
+ RESTRICT = scalarlesel,
+ JOIN = scalarlejoinsel);
+
+ALTER OPERATOR >= (ismn13, ismn13) SET (
+ RESTRICT = scalargesel,
+ JOIN = scalargejoinsel);
+
+ALTER OPERATOR <= (ismn13, ismn) SET (
+ RESTRICT = scalarlesel,
+ JOIN = scalarlejoinsel);
+
+ALTER OPERATOR >= (ismn13, ismn) SET (
+ RESTRICT = scalargesel,
+ JOIN = scalargejoinsel);
+
+ALTER OPERATOR <= (ismn, ismn) SET (
+ RESTRICT = scalarlesel,
+ JOIN = scalarlejoinsel);
+
+ALTER OPERATOR >= (ismn, ismn) SET (
+ RESTRICT = scalargesel,
+ JOIN = scalargejoinsel);
+
+ALTER OPERATOR <= (ismn, ismn13) SET (
+ RESTRICT = scalarlesel,
+ JOIN = scalarlejoinsel);
+
+ALTER OPERATOR >= (ismn, ismn13) SET (
+ RESTRICT = scalargesel,
+ JOIN = scalargejoinsel);
+
+ALTER OPERATOR <= (ismn, ean13) SET (
+ RESTRICT = scalarlesel,
+ JOIN = scalarlejoinsel);
+
+ALTER OPERATOR >= (ismn, ean13) SET (
+ RESTRICT = scalargesel,
+ JOIN = scalargejoinsel);
+
+ALTER OPERATOR <= (issn13, issn13) SET (
+ RESTRICT = scalarlesel,
+ JOIN = scalarlejoinsel);
+
+ALTER OPERATOR >= (issn13, issn13) SET (
+ RESTRICT = scalargesel,
+ JOIN = scalargejoinsel);
+
+ALTER OPERATOR <= (issn13, issn) SET (
+ RESTRICT = scalarlesel,
+ JOIN = scalarlejoinsel);
+
+ALTER OPERATOR >= (issn13, issn) SET (
+ RESTRICT = scalargesel,
+ JOIN = scalargejoinsel);
+
+ALTER OPERATOR <= (issn13, ean13) SET (
+ RESTRICT = scalarlesel,
+ JOIN = scalarlejoinsel);
+
+ALTER OPERATOR >= (issn13, ean13) SET (
+ RESTRICT = scalargesel,
+ JOIN = scalargejoinsel);
+
+ALTER OPERATOR <= (issn, issn) SET (
+ RESTRICT = scalarlesel,
+ JOIN = scalarlejoinsel);
+
+ALTER OPERATOR >= (issn, issn) SET (
+ RESTRICT = scalargesel,
+ JOIN = scalargejoinsel);
+
+ALTER OPERATOR <= (issn, issn13) SET (
+ RESTRICT = scalarlesel,
+ JOIN = scalarlejoinsel);
+
+ALTER OPERATOR >= (issn, issn13) SET (
+ RESTRICT = scalargesel,
+ JOIN = scalargejoinsel);
+
+ALTER OPERATOR <= (issn, ean13) SET (
+ RESTRICT = scalarlesel,
+ JOIN = scalarlejoinsel);
+
+ALTER OPERATOR >= (issn, ean13) SET (
+ RESTRICT = scalargesel,
+ JOIN = scalargejoinsel);
+
+ALTER OPERATOR <= (upc, upc) SET (
+ RESTRICT = scalarlesel,
+ JOIN = scalarlejoinsel);
+
+ALTER OPERATOR >= (upc, upc) SET (
+ RESTRICT = scalargesel,
+ JOIN = scalargejoinsel);
+
+ALTER OPERATOR <= (upc, ean13) SET (
+ RESTRICT = scalarlesel,
+ JOIN = scalarlejoinsel);
+
+ALTER OPERATOR >= (upc, ean13) SET (
+ RESTRICT = scalargesel,
+ JOIN = scalargejoinsel);
diff --git a/contrib/isn/isn.c b/contrib/isn/isn.c
index 4d845b716f..897d83e0ca 100644
--- a/contrib/isn/isn.c
+++ b/contrib/isn/isn.c
@@ -4,7 +4,7 @@
* PostgreSQL type definitions for ISNs (ISBN, ISMN, ISSN, EAN13, UPC)
*
* Author: German Mendez Bravo (Kronuz)
- * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
*
* IDENTIFICATION
* contrib/isn/isn.c
@@ -26,6 +26,12 @@
PG_MODULE_MAGIC;
+#ifdef USE_ASSERT_CHECKING
+#define ISN_DEBUG 1
+#else
+#define ISN_DEBUG 0
+#endif
+
#define MAXEAN13LEN 18
enum isn_type
@@ -36,7 +42,6 @@ enum isn_type
static const char *const isn_names[] = {"EAN13/UPC/ISxN", "EAN13/UPC/ISxN", "EAN13", "ISBN", "ISMN", "ISSN", "UPC"};
static bool g_weak = false;
-static bool g_initialized = false;
/***********************************************************************
@@ -56,7 +61,7 @@ static bool g_initialized = false;
/*
* Check if the table and its index is correct (just for debugging)
*/
-#ifdef ISN_DEBUG
+pg_attribute_unused()
static bool
check_table(const char *(*TABLE)[2], const unsigned TABLE_index[10][2])
{
@@ -68,7 +73,6 @@ check_table(const char *(*TABLE)[2], const unsigned TABLE_index[10][2])
y = -1,
i = 0,
j,
- cnt = 0,
init = 0;
if (TABLE == NULL || TABLE_index == NULL)
@@ -131,7 +135,6 @@ check_table(const char *(*TABLE)[2], const unsigned TABLE_index[10][2])
elog(DEBUG1, "index %d is invalid", j);
return false;
}
-#endif /* ISN_DEBUG */
/*----------------------------------------------------------
* Formatting and conversion routines.
@@ -922,22 +925,24 @@ string2ean(const char *str, bool errorOK, ean13 *result,
* Exported routines.
*---------------------------------------------------------*/
+void _PG_init(void);
+
void
-initialize(void)
+_PG_init(void)
{
-#ifdef ISN_DEBUG
- if (!check_table(EAN13, EAN13_index))
- elog(LOG, "EAN13 failed check");
- if (!check_table(ISBN, ISBN_index))
- elog(LOG, "ISBN failed check");
- if (!check_table(ISMN, ISMN_index))
- elog(LOG, "ISMN failed check");
- if (!check_table(ISSN, ISSN_index))
- elog(LOG, "ISSN failed check");
- if (!check_table(UPC, UPC_index))
- elog(LOG, "UPC failed check");
-#endif
- g_initialized = true;
+ if (ISN_DEBUG)
+ {
+ if (!check_table(EAN13_range, EAN13_index))
+ elog(ERROR, "EAN13 failed check");
+ if (!check_table(ISBN_range, ISBN_index))
+ elog(ERROR, "ISBN failed check");
+ if (!check_table(ISMN_range, ISMN_index))
+ elog(ERROR, "ISMN failed check");
+ if (!check_table(ISSN_range, ISSN_index))
+ elog(ERROR, "ISSN failed check");
+ if (!check_table(UPC_range, UPC_index))
+ elog(ERROR, "UPC failed check");
+ }
}
/* isn_out
diff --git a/contrib/isn/isn.control b/contrib/isn/isn.control
index 544bd8d0bf..765dce0e0a 100644
--- a/contrib/isn/isn.control
+++ b/contrib/isn/isn.control
@@ -1,5 +1,5 @@
# isn extension
comment = 'data types for international product numbering standards'
-default_version = '1.1'
+default_version = '1.2'
module_pathname = '$libdir/isn'
relocatable = true
diff --git a/contrib/isn/isn.h b/contrib/isn/isn.h
index e2c8a26234..29632d8518 100644
--- a/contrib/isn/isn.h
+++ b/contrib/isn/isn.h
@@ -4,7 +4,7 @@
* PostgreSQL type definitions for ISNs (ISBN, ISMN, ISSN, EAN13, UPC)
*
* Author: German Mendez Bravo (Kronuz)
- * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
*
* IDENTIFICATION
* contrib/isn/isn.h
diff --git a/contrib/lo/.gitignore b/contrib/lo/.gitignore
new file mode 100644
index 0000000000..5dcb3ff972
--- /dev/null
+++ b/contrib/lo/.gitignore
@@ -0,0 +1,4 @@
+# Generated subdirectories
+/log/
+/results/
+/tmp_check/
diff --git a/contrib/lo/Makefile b/contrib/lo/Makefile
index 71f0cb0d24..bd4fd6b72d 100644
--- a/contrib/lo/Makefile
+++ b/contrib/lo/Makefile
@@ -6,6 +6,8 @@ EXTENSION = lo
DATA = lo--1.1.sql lo--1.0--1.1.sql lo--unpackaged--1.0.sql
PGFILEDESC = "lo - management for large objects"
+REGRESS = lo
+
ifdef USE_PGXS
PG_CONFIG = pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
diff --git a/contrib/lo/expected/lo.out b/contrib/lo/expected/lo.out
new file mode 100644
index 0000000000..f7104aee3f
--- /dev/null
+++ b/contrib/lo/expected/lo.out
@@ -0,0 +1,42 @@
+CREATE EXTENSION lo;
+CREATE TABLE image (title text, raster lo);
+CREATE TRIGGER t_raster BEFORE UPDATE OR DELETE ON image
+ FOR EACH ROW EXECUTE PROCEDURE lo_manage(raster);
+SELECT lo_create(43213);
+ lo_create
+-----------
+ 43213
+(1 row)
+
+SELECT lo_create(43214);
+ lo_create
+-----------
+ 43214
+(1 row)
+
+INSERT INTO image (title, raster) VALUES ('beautiful image', 43213);
+SELECT lo_get(43213);
+ lo_get
+--------
+ \x
+(1 row)
+
+SELECT lo_get(43214);
+ lo_get
+--------
+ \x
+(1 row)
+
+UPDATE image SET raster = 43214 WHERE title = 'beautiful image';
+SELECT lo_get(43213);
+ERROR: large object 43213 does not exist
+SELECT lo_get(43214);
+ lo_get
+--------
+ \x
+(1 row)
+
+DELETE FROM image;
+SELECT lo_get(43214);
+ERROR: large object 43214 does not exist
+DROP TABLE image;
diff --git a/contrib/lo/sql/lo.sql b/contrib/lo/sql/lo.sql
new file mode 100644
index 0000000000..34ba6f00ec
--- /dev/null
+++ b/contrib/lo/sql/lo.sql
@@ -0,0 +1,25 @@
+CREATE EXTENSION lo;
+
+CREATE TABLE image (title text, raster lo);
+
+CREATE TRIGGER t_raster BEFORE UPDATE OR DELETE ON image
+ FOR EACH ROW EXECUTE PROCEDURE lo_manage(raster);
+
+SELECT lo_create(43213);
+SELECT lo_create(43214);
+
+INSERT INTO image (title, raster) VALUES ('beautiful image', 43213);
+
+SELECT lo_get(43213);
+SELECT lo_get(43214);
+
+UPDATE image SET raster = 43214 WHERE title = 'beautiful image';
+
+SELECT lo_get(43213);
+SELECT lo_get(43214);
+
+DELETE FROM image;
+
+SELECT lo_get(43214);
+
+DROP TABLE image;
diff --git a/contrib/ltree/_ltree_gist.c b/contrib/ltree/_ltree_gist.c
index a387f5b899..28bf7ad963 100644
--- a/contrib/ltree/_ltree_gist.c
+++ b/contrib/ltree/_ltree_gist.c
@@ -100,7 +100,7 @@ _ltree_compress(PG_FUNCTION_ARGS)
retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
gistentryinit(*retval, PointerGetDatum(key),
entry->rel, entry->page,
- entry->offset, FALSE);
+ entry->offset, false);
}
else if (!LTG_ISALLTRUE(entry->key))
{
@@ -123,7 +123,7 @@ _ltree_compress(PG_FUNCTION_ARGS)
retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
gistentryinit(*retval, PointerGetDatum(key),
entry->rel, entry->page,
- entry->offset, FALSE);
+ entry->offset, false);
}
PG_RETURN_POINTER(retval);
}
@@ -545,7 +545,7 @@ Datum
_ltree_consistent(PG_FUNCTION_ARGS)
{
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- char *query = (char *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(1)));
+ void *query = (void *) PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
/* Oid subtype = PG_GETARG_OID(3); */
diff --git a/contrib/ltree/_ltree_op.c b/contrib/ltree/_ltree_op.c
index fdf6ebb43b..9bb6bcaeff 100644
--- a/contrib/ltree/_ltree_op.c
+++ b/contrib/ltree/_ltree_op.c
@@ -71,7 +71,7 @@ Datum
_ltree_isparent(PG_FUNCTION_ARGS)
{
ArrayType *la = PG_GETARG_ARRAYTYPE_P(0);
- ltree *query = PG_GETARG_LTREE(1);
+ ltree *query = PG_GETARG_LTREE_P(1);
bool res = array_iterator(la, ltree_isparent, (void *) query, NULL);
PG_FREE_IF_COPY(la, 0);
@@ -92,7 +92,7 @@ Datum
_ltree_risparent(PG_FUNCTION_ARGS)
{
ArrayType *la = PG_GETARG_ARRAYTYPE_P(0);
- ltree *query = PG_GETARG_LTREE(1);
+ ltree *query = PG_GETARG_LTREE_P(1);
bool res = array_iterator(la, ltree_risparent, (void *) query, NULL);
PG_FREE_IF_COPY(la, 0);
@@ -113,7 +113,7 @@ Datum
_ltq_regex(PG_FUNCTION_ARGS)
{
ArrayType *la = PG_GETARG_ARRAYTYPE_P(0);
- lquery *query = PG_GETARG_LQUERY(1);
+ lquery *query = PG_GETARG_LQUERY_P(1);
bool res = array_iterator(la, ltq_regex, (void *) query, NULL);
PG_FREE_IF_COPY(la, 0);
@@ -178,7 +178,7 @@ Datum
_ltxtq_exec(PG_FUNCTION_ARGS)
{
ArrayType *la = PG_GETARG_ARRAYTYPE_P(0);
- ltxtquery *query = PG_GETARG_LTXTQUERY(1);
+ ltxtquery *query = PG_GETARG_LTXTQUERY_P(1);
bool res = array_iterator(la, ltxtq_exec, (void *) query, NULL);
PG_FREE_IF_COPY(la, 0);
@@ -200,7 +200,7 @@ Datum
_ltree_extract_isparent(PG_FUNCTION_ARGS)
{
ArrayType *la = PG_GETARG_ARRAYTYPE_P(0);
- ltree *query = PG_GETARG_LTREE(1);
+ ltree *query = PG_GETARG_LTREE_P(1);
ltree *found,
*item;
@@ -223,7 +223,7 @@ Datum
_ltree_extract_risparent(PG_FUNCTION_ARGS)
{
ArrayType *la = PG_GETARG_ARRAYTYPE_P(0);
- ltree *query = PG_GETARG_LTREE(1);
+ ltree *query = PG_GETARG_LTREE_P(1);
ltree *found,
*item;
@@ -246,7 +246,7 @@ Datum
_ltq_extract_regex(PG_FUNCTION_ARGS)
{
ArrayType *la = PG_GETARG_ARRAYTYPE_P(0);
- lquery *query = PG_GETARG_LQUERY(1);
+ lquery *query = PG_GETARG_LQUERY_P(1);
ltree *found,
*item;
@@ -269,7 +269,7 @@ Datum
_ltxtq_extract_exec(PG_FUNCTION_ARGS)
{
ArrayType *la = PG_GETARG_ARRAYTYPE_P(0);
- ltxtquery *query = PG_GETARG_LTXTQUERY(1);
+ ltxtquery *query = PG_GETARG_LTXTQUERY_P(1);
ltree *found,
*item;
diff --git a/contrib/ltree/lquery_op.c b/contrib/ltree/lquery_op.c
index 229ddd0ae3..b6d2deb1af 100644
--- a/contrib/ltree/lquery_op.c
+++ b/contrib/ltree/lquery_op.c
@@ -302,8 +302,8 @@ checkCond(lquery_level *curq, int query_numlevel, ltree_level *curt, int tree_nu
Datum
ltq_regex(PG_FUNCTION_ARGS)
{
- ltree *tree = PG_GETARG_LTREE(0);
- lquery *query = PG_GETARG_LQUERY(1);
+ ltree *tree = PG_GETARG_LTREE_P(0);
+ lquery *query = PG_GETARG_LQUERY_P(1);
bool res = false;
if (query->flag & LQUERY_HASNOT)
@@ -338,7 +338,7 @@ ltq_rregex(PG_FUNCTION_ARGS)
Datum
lt_q_regex(PG_FUNCTION_ARGS)
{
- ltree *tree = PG_GETARG_LTREE(0);
+ ltree *tree = PG_GETARG_LTREE_P(0);
ArrayType *_query = PG_GETARG_ARRAYTYPE_P(1);
lquery *query = (lquery *) ARR_DATA_PTR(_query);
bool res = false;
diff --git a/contrib/ltree/ltree.h b/contrib/ltree/ltree.h
index fd86323ffe..e4b8c84fa6 100644
--- a/contrib/ltree/ltree.h
+++ b/contrib/ltree/ltree.h
@@ -165,12 +165,21 @@ bool compare_subnode(ltree_level *t, char *q, int len,
ltree *lca_inner(ltree **a, int len);
int ltree_strncasecmp(const char *a, const char *b, size_t s);
-#define PG_GETARG_LTREE(x) ((ltree*)DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(x))))
-#define PG_GETARG_LTREE_COPY(x) ((ltree*)DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(x))))
-#define PG_GETARG_LQUERY(x) ((lquery*)DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(x))))
-#define PG_GETARG_LQUERY_COPY(x) ((lquery*)DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(x))))
-#define PG_GETARG_LTXTQUERY(x) ((ltxtquery*)DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(x))))
-#define PG_GETARG_LTXTQUERY_COPY(x) ((ltxtquery*)DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(x))))
+/* fmgr macros for ltree objects */
+#define DatumGetLtreeP(X) ((ltree *) PG_DETOAST_DATUM(X))
+#define DatumGetLtreePCopy(X) ((ltree *) PG_DETOAST_DATUM_COPY(X))
+#define PG_GETARG_LTREE_P(n) DatumGetLtreeP(PG_GETARG_DATUM(n))
+#define PG_GETARG_LTREE_P_COPY(n) DatumGetLtreePCopy(PG_GETARG_DATUM(n))
+
+#define DatumGetLqueryP(X) ((lquery *) PG_DETOAST_DATUM(X))
+#define DatumGetLqueryPCopy(X) ((lquery *) PG_DETOAST_DATUM_COPY(X))
+#define PG_GETARG_LQUERY_P(n) DatumGetLqueryP(PG_GETARG_DATUM(n))
+#define PG_GETARG_LQUERY_P_COPY(n) DatumGetLqueryPCopy(PG_GETARG_DATUM(n))
+
+#define DatumGetLtxtqueryP(X) ((ltxtquery *) PG_DETOAST_DATUM(X))
+#define DatumGetLtxtqueryPCopy(X) ((ltxtquery *) PG_DETOAST_DATUM_COPY(X))
+#define PG_GETARG_LTXTQUERY_P(n) DatumGetLtxtqueryP(PG_GETARG_DATUM(n))
+#define PG_GETARG_LTXTQUERY_P_COPY(n) DatumGetLtxtqueryPCopy(PG_GETARG_DATUM(n))
/* GiST support for ltree */
diff --git a/contrib/ltree/ltree_gist.c b/contrib/ltree/ltree_gist.c
index 70e78a672a..12aa8fff20 100644
--- a/contrib/ltree/ltree_gist.c
+++ b/contrib/ltree/ltree_gist.c
@@ -53,7 +53,7 @@ ltree_compress(PG_FUNCTION_ARGS)
if (entry->leafkey)
{ /* ltree */
ltree_gist *key;
- ltree *val = (ltree *) DatumGetPointer(PG_DETOAST_DATUM(entry->key));
+ ltree *val = DatumGetLtreeP(entry->key);
int32 len = LTG_HDRSIZE + VARSIZE(val);
key = (ltree_gist *) palloc0(len);
@@ -64,7 +64,7 @@ ltree_compress(PG_FUNCTION_ARGS)
retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
gistentryinit(*retval, PointerGetDatum(key),
entry->rel, entry->page,
- entry->offset, FALSE);
+ entry->offset, false);
}
PG_RETURN_POINTER(retval);
}
@@ -73,7 +73,7 @@ Datum
ltree_decompress(PG_FUNCTION_ARGS)
{
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- ltree_gist *key = (ltree_gist *) DatumGetPointer(PG_DETOAST_DATUM(entry->key));
+ ltree_gist *key = (ltree_gist *) PG_DETOAST_DATUM(entry->key);
if (PointerGetDatum(key) != entry->key)
{
@@ -81,7 +81,7 @@ ltree_decompress(PG_FUNCTION_ARGS)
gistentryinit(*retval, PointerGetDatum(key),
entry->rel, entry->page,
- entry->offset, FALSE);
+ entry->offset, false);
PG_RETURN_POINTER(retval);
}
PG_RETURN_POINTER(entry);
@@ -621,18 +621,18 @@ ltree_consistent(PG_FUNCTION_ARGS)
switch (strategy)
{
case BTLessStrategyNumber:
- query = PG_GETARG_LTREE(1);
+ query = PG_GETARG_LTREE_P(1);
res = (GIST_LEAF(entry)) ?
(ltree_compare((ltree *) query, LTG_NODE(key)) > 0)
:
(ltree_compare((ltree *) query, LTG_GETLNODE(key)) >= 0);
break;
case BTLessEqualStrategyNumber:
- query = PG_GETARG_LTREE(1);
+ query = PG_GETARG_LTREE_P(1);
res = (ltree_compare((ltree *) query, LTG_GETLNODE(key)) >= 0);
break;
case BTEqualStrategyNumber:
- query = PG_GETARG_LTREE(1);
+ query = PG_GETARG_LTREE_P(1);
if (GIST_LEAF(entry))
res = (ltree_compare((ltree *) query, LTG_NODE(key)) == 0);
else
@@ -643,25 +643,25 @@ ltree_consistent(PG_FUNCTION_ARGS)
);
break;
case BTGreaterEqualStrategyNumber:
- query = PG_GETARG_LTREE(1);
+ query = PG_GETARG_LTREE_P(1);
res = (ltree_compare((ltree *) query, LTG_GETRNODE(key)) <= 0);
break;
case BTGreaterStrategyNumber:
- query = PG_GETARG_LTREE(1);
+ query = PG_GETARG_LTREE_P(1);
res = (GIST_LEAF(entry)) ?
(ltree_compare((ltree *) query, LTG_GETRNODE(key)) < 0)
:
(ltree_compare((ltree *) query, LTG_GETRNODE(key)) <= 0);
break;
case 10:
- query = PG_GETARG_LTREE_COPY(1);
+ query = PG_GETARG_LTREE_P_COPY(1);
res = (GIST_LEAF(entry)) ?
inner_isparent((ltree *) query, LTG_NODE(key))
:
gist_isparent(key, (ltree *) query);
break;
case 11:
- query = PG_GETARG_LTREE(1);
+ query = PG_GETARG_LTREE_P(1);
res = (GIST_LEAF(entry)) ?
inner_isparent(LTG_NODE(key), (ltree *) query)
:
@@ -669,7 +669,7 @@ ltree_consistent(PG_FUNCTION_ARGS)
break;
case 12:
case 13:
- query = PG_GETARG_LQUERY(1);
+ query = PG_GETARG_LQUERY_P(1);
if (GIST_LEAF(entry))
res = DatumGetBool(DirectFunctionCall2(ltq_regex,
PointerGetDatum(LTG_NODE(key)),
@@ -680,18 +680,18 @@ ltree_consistent(PG_FUNCTION_ARGS)
break;
case 14:
case 15:
- query = PG_GETARG_LQUERY(1);
+ query = PG_GETARG_LTXTQUERY_P(1);
if (GIST_LEAF(entry))
res = DatumGetBool(DirectFunctionCall2(ltxtq_exec,
PointerGetDatum(LTG_NODE(key)),
- PointerGetDatum((lquery *) query)
+ PointerGetDatum((ltxtquery *) query)
));
else
res = gist_qtxt(key, (ltxtquery *) query);
break;
case 16:
case 17:
- query = DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(1)));
+ query = PG_GETARG_ARRAYTYPE_P(1);
if (GIST_LEAF(entry))
res = DatumGetBool(DirectFunctionCall2(lt_q_regex,
PointerGetDatum(LTG_NODE(key)),
diff --git a/contrib/ltree/ltree_io.c b/contrib/ltree/ltree_io.c
index 34ca597a48..f54f037443 100644
--- a/contrib/ltree/ltree_io.c
+++ b/contrib/ltree/ltree_io.c
@@ -149,7 +149,7 @@ ltree_in(PG_FUNCTION_ARGS)
Datum
ltree_out(PG_FUNCTION_ARGS)
{
- ltree *in = PG_GETARG_LTREE(0);
+ ltree *in = PG_GETARG_LTREE_P(0);
char *buf,
*ptr;
int i;
@@ -521,7 +521,7 @@ lquery_in(PG_FUNCTION_ARGS)
Datum
lquery_out(PG_FUNCTION_ARGS)
{
- lquery *in = PG_GETARG_LQUERY(0);
+ lquery *in = PG_GETARG_LQUERY_P(0);
char *buf,
*ptr;
int i,
diff --git a/contrib/ltree/ltree_op.c b/contrib/ltree/ltree_op.c
index aa1e9918be..d62ca02521 100644
--- a/contrib/ltree/ltree_op.c
+++ b/contrib/ltree/ltree_op.c
@@ -67,65 +67,65 @@ ltree_compare(const ltree *a, const ltree *b)
}
#define RUNCMP \
-ltree *a = PG_GETARG_LTREE(0); \
-ltree *b = PG_GETARG_LTREE(1); \
-int res = ltree_compare(a,b); \
-PG_FREE_IF_COPY(a,0); \
-PG_FREE_IF_COPY(b,1); \
+ltree *a = PG_GETARG_LTREE_P(0); \
+ltree *b = PG_GETARG_LTREE_P(1); \
+int res = ltree_compare(a,b); \
+PG_FREE_IF_COPY(a,0); \
+PG_FREE_IF_COPY(b,1)
Datum
ltree_cmp(PG_FUNCTION_ARGS)
{
- RUNCMP
- PG_RETURN_INT32(res);
+ RUNCMP;
+ PG_RETURN_INT32(res);
}
Datum
ltree_lt(PG_FUNCTION_ARGS)
{
- RUNCMP
- PG_RETURN_BOOL((res < 0) ? true : false);
+ RUNCMP;
+ PG_RETURN_BOOL((res < 0) ? true : false);
}
Datum
ltree_le(PG_FUNCTION_ARGS)
{
- RUNCMP
- PG_RETURN_BOOL((res <= 0) ? true : false);
+ RUNCMP;
+ PG_RETURN_BOOL((res <= 0) ? true : false);
}
Datum
ltree_eq(PG_FUNCTION_ARGS)
{
- RUNCMP
- PG_RETURN_BOOL((res == 0) ? true : false);
+ RUNCMP;
+ PG_RETURN_BOOL((res == 0) ? true : false);
}
Datum
ltree_ge(PG_FUNCTION_ARGS)
{
- RUNCMP
- PG_RETURN_BOOL((res >= 0) ? true : false);
+ RUNCMP;
+ PG_RETURN_BOOL((res >= 0) ? true : false);
}
Datum
ltree_gt(PG_FUNCTION_ARGS)
{
- RUNCMP
- PG_RETURN_BOOL((res > 0) ? true : false);
+ RUNCMP;
+ PG_RETURN_BOOL((res > 0) ? true : false);
}
Datum
ltree_ne(PG_FUNCTION_ARGS)
{
- RUNCMP
- PG_RETURN_BOOL((res != 0) ? true : false);
+ RUNCMP;
+ PG_RETURN_BOOL((res != 0) ? true : false);
}
Datum
nlevel(PG_FUNCTION_ARGS)
{
- ltree *a = PG_GETARG_LTREE(0);
+ ltree *a = PG_GETARG_LTREE_P(0);
int res = a->numlevel;
PG_FREE_IF_COPY(a, 0);
@@ -159,8 +159,8 @@ inner_isparent(const ltree *c, const ltree *p)
Datum
ltree_isparent(PG_FUNCTION_ARGS)
{
- ltree *c = PG_GETARG_LTREE(1);
- ltree *p = PG_GETARG_LTREE(0);
+ ltree *c = PG_GETARG_LTREE_P(1);
+ ltree *p = PG_GETARG_LTREE_P(0);
bool res = inner_isparent(c, p);
PG_FREE_IF_COPY(c, 1);
@@ -171,8 +171,8 @@ ltree_isparent(PG_FUNCTION_ARGS)
Datum
ltree_risparent(PG_FUNCTION_ARGS)
{
- ltree *c = PG_GETARG_LTREE(0);
- ltree *p = PG_GETARG_LTREE(1);
+ ltree *c = PG_GETARG_LTREE_P(0);
+ ltree *p = PG_GETARG_LTREE_P(1);
bool res = inner_isparent(c, p);
PG_FREE_IF_COPY(c, 0);
@@ -223,7 +223,7 @@ inner_subltree(ltree *t, int32 startpos, int32 endpos)
Datum
subltree(PG_FUNCTION_ARGS)
{
- ltree *t = PG_GETARG_LTREE(0);
+ ltree *t = PG_GETARG_LTREE_P(0);
ltree *res = inner_subltree(t, PG_GETARG_INT32(1), PG_GETARG_INT32(2));
PG_FREE_IF_COPY(t, 0);
@@ -233,7 +233,7 @@ subltree(PG_FUNCTION_ARGS)
Datum
subpath(PG_FUNCTION_ARGS)
{
- ltree *t = PG_GETARG_LTREE(0);
+ ltree *t = PG_GETARG_LTREE_P(0);
int32 start = PG_GETARG_INT32(1);
int32 len = (fcinfo->nargs == 3) ? PG_GETARG_INT32(2) : 0;
int32 end;
@@ -282,8 +282,8 @@ ltree_concat(ltree *a, ltree *b)
Datum
ltree_addltree(PG_FUNCTION_ARGS)
{
- ltree *a = PG_GETARG_LTREE(0);
- ltree *b = PG_GETARG_LTREE(1);
+ ltree *a = PG_GETARG_LTREE_P(0);
+ ltree *b = PG_GETARG_LTREE_P(1);
ltree *r;
r = ltree_concat(a, b);
@@ -295,7 +295,7 @@ ltree_addltree(PG_FUNCTION_ARGS)
Datum
ltree_addtext(PG_FUNCTION_ARGS)
{
- ltree *a = PG_GETARG_LTREE(0);
+ ltree *a = PG_GETARG_LTREE_P(0);
text *b = PG_GETARG_TEXT_PP(1);
char *s;
ltree *r,
@@ -320,8 +320,8 @@ ltree_addtext(PG_FUNCTION_ARGS)
Datum
ltree_index(PG_FUNCTION_ARGS)
{
- ltree *a = PG_GETARG_LTREE(0);
- ltree *b = PG_GETARG_LTREE(1);
+ ltree *a = PG_GETARG_LTREE_P(0);
+ ltree *b = PG_GETARG_LTREE_P(1);
int start = (fcinfo->nargs == 3) ? PG_GETARG_INT32(2) : 0;
int i,
j;
@@ -380,7 +380,7 @@ ltree_index(PG_FUNCTION_ARGS)
Datum
ltree_textadd(PG_FUNCTION_ARGS)
{
- ltree *a = PG_GETARG_LTREE(1);
+ ltree *a = PG_GETARG_LTREE_P(1);
text *b = PG_GETARG_TEXT_PP(0);
char *s;
ltree *r,
@@ -476,7 +476,7 @@ lca(PG_FUNCTION_ARGS)
a = (ltree **) palloc(sizeof(ltree *) * fcinfo->nargs);
for (i = 0; i < fcinfo->nargs; i++)
- a[i] = PG_GETARG_LTREE(i);
+ a[i] = PG_GETARG_LTREE_P(i);
res = lca_inner(a, (int) fcinfo->nargs);
for (i = 0; i < fcinfo->nargs; i++)
PG_FREE_IF_COPY(a[i], i);
@@ -508,7 +508,7 @@ text2ltree(PG_FUNCTION_ARGS)
Datum
ltree2text(PG_FUNCTION_ARGS)
{
- ltree *in = PG_GETARG_LTREE(0);
+ ltree *in = PG_GETARG_LTREE_P(0);
char *ptr;
int i;
ltree_level *curlevel;
diff --git a/contrib/ltree/ltxtquery_io.c b/contrib/ltree/ltxtquery_io.c
index 9ca1994249..56bf39d145 100644
--- a/contrib/ltree/ltxtquery_io.c
+++ b/contrib/ltree/ltxtquery_io.c
@@ -515,7 +515,7 @@ infix(INFIX *in, bool first)
Datum
ltxtq_out(PG_FUNCTION_ARGS)
{
- ltxtquery *query = PG_GETARG_LTXTQUERY(0);
+ ltxtquery *query = PG_GETARG_LTXTQUERY_P(0);
INFIX nrm;
if (query->size == 0)
diff --git a/contrib/ltree/ltxtquery_op.c b/contrib/ltree/ltxtquery_op.c
index 1428c8b478..dc0ee82bb6 100644
--- a/contrib/ltree/ltxtquery_op.c
+++ b/contrib/ltree/ltxtquery_op.c
@@ -26,7 +26,7 @@ ltree_execute(ITEM *curitem, void *checkval, bool calcnot, bool (*chkcond) (void
return (*chkcond) (checkval, curitem);
else if (curitem->val == (int32) '!')
{
- return (calcnot) ?
+ return calcnot ?
((ltree_execute(curitem + 1, checkval, calcnot, chkcond)) ? false : true)
: true;
}
@@ -86,8 +86,8 @@ checkcondition_str(void *checkval, ITEM *val)
Datum
ltxtq_exec(PG_FUNCTION_ARGS)
{
- ltree *val = PG_GETARG_LTREE(0);
- ltxtquery *query = PG_GETARG_LTXTQUERY(1);
+ ltree *val = PG_GETARG_LTREE_P(0);
+ ltxtquery *query = PG_GETARG_LTXTQUERY_P(1);
CHKVAL chkval;
bool result;
diff --git a/contrib/ltree_plpython/ltree_plpython.c b/contrib/ltree_plpython/ltree_plpython.c
index bdd462a91b..e88636a0a9 100644
--- a/contrib/ltree_plpython/ltree_plpython.c
+++ b/contrib/ltree_plpython/ltree_plpython.c
@@ -40,12 +40,16 @@ PG_FUNCTION_INFO_V1(ltree_to_plpython);
Datum
ltree_to_plpython(PG_FUNCTION_ARGS)
{
- ltree *in = PG_GETARG_LTREE(0);
+ ltree *in = PG_GETARG_LTREE_P(0);
int i;
PyObject *list;
ltree_level *curlevel;
list = PyList_New(in->numlevel);
+ if (!list)
+ ereport(ERROR,
+ (errcode(ERRCODE_OUT_OF_MEMORY),
+ errmsg("out of memory")));
curlevel = LTREE_FIRST(in);
for (i = 0; i < in->numlevel; i++)
diff --git a/contrib/oid2name/oid2name.c b/contrib/oid2name/oid2name.c
index 8af99decad..769e527384 100644
--- a/contrib/oid2name/oid2name.c
+++ b/contrib/oid2name/oid2name.c
@@ -11,6 +11,7 @@
#include "catalog/pg_class.h"
+#include "fe_utils/connect.h"
#include "libpq-fe.h"
#include "pg_getopt.h"
@@ -266,6 +267,7 @@ sql_conn(struct options *my_opts)
bool have_password = false;
char password[100];
bool new_pass;
+ PGresult *res;
/*
* Start the connection. Loop until we have a password if requested by
@@ -323,6 +325,17 @@ sql_conn(struct options *my_opts)
exit(1);
}
+ res = PQexec(conn, ALWAYS_SECURE_SEARCH_PATH_SQL);
+ if (PQresultStatus(res) != PGRES_TUPLES_OK)
+ {
+ fprintf(stderr, "oid2name: could not clear search_path: %s\n",
+ PQerrorMessage(conn));
+ PQclear(res);
+ PQfinish(conn);
+ exit(-1);
+ }
+ PQclear(res);
+
/* return the conn if good */
return conn;
}
diff --git a/contrib/pageinspect/brinfuncs.c b/contrib/pageinspect/brinfuncs.c
index 13da7616e7..f4f0dea860 100644
--- a/contrib/pageinspect/brinfuncs.c
+++ b/contrib/pageinspect/brinfuncs.c
@@ -2,7 +2,7 @@
* brinfuncs.c
* Functions to investigate BRIN indexes
*
- * Copyright (c) 2014-2017, PostgreSQL Global Development Group
+ * Copyright (c) 2014-2018, PostgreSQL Global Development Group
*
* IDENTIFICATION
* contrib/pageinspect/brinfuncs.c
diff --git a/contrib/pageinspect/expected/page.out b/contrib/pageinspect/expected/page.out
index 8e15947a81..5edb650085 100644
--- a/contrib/pageinspect/expected/page.out
+++ b/contrib/pageinspect/expected/page.out
@@ -92,3 +92,20 @@ create table test_part1 partition of test_partitioned for values from ( 1 ) to (
select get_raw_page('test_part1', 0); -- get farther and error about empty table
ERROR: block number 0 is out of range for relation "test_part1"
drop table test_partitioned;
+-- check null bitmap alignment for table whose number of attributes is multiple of 8
+create table test8 (f1 int, f2 int, f3 int, f4 int, f5 int, f6 int, f7 int, f8 int);
+insert into test8(f1, f8) values (x'7f00007f'::int, 0);
+select t_bits, t_data from heap_page_items(get_raw_page('test8', 0));
+ t_bits | t_data
+----------+--------------------
+ 10000001 | \x7f00007f00000000
+(1 row)
+
+select tuple_data_split('test8'::regclass, t_data, t_infomask, t_infomask2, t_bits)
+ from heap_page_items(get_raw_page('test8', 0));
+ tuple_data_split
+-------------------------------------------------------------
+ {"\\x7f00007f",NULL,NULL,NULL,NULL,NULL,NULL,"\\x00000000"}
+(1 row)
+
+drop table test8;
diff --git a/contrib/pageinspect/fsmfuncs.c b/contrib/pageinspect/fsmfuncs.c
index 615dab8b13..86e8075845 100644
--- a/contrib/pageinspect/fsmfuncs.c
+++ b/contrib/pageinspect/fsmfuncs.c
@@ -9,7 +9,7 @@
* there's hardly any use case for using these without superuser-rights
* anyway.
*
- * Copyright (c) 2007-2017, PostgreSQL Global Development Group
+ * Copyright (c) 2007-2018, PostgreSQL Global Development Group
*
* IDENTIFICATION
* contrib/pageinspect/fsmfuncs.c
diff --git a/contrib/pageinspect/ginfuncs.c b/contrib/pageinspect/ginfuncs.c
index f774495b6f..d42609c577 100644
--- a/contrib/pageinspect/ginfuncs.c
+++ b/contrib/pageinspect/ginfuncs.c
@@ -2,7 +2,7 @@
* ginfuncs.c
* Functions to investigate the content of GIN indexes
*
- * Copyright (c) 2014-2017, PostgreSQL Global Development Group
+ * Copyright (c) 2014-2018, PostgreSQL Global Development Group
*
* IDENTIFICATION
* contrib/pageinspect/ginfuncs.c
diff --git a/contrib/pageinspect/hashfuncs.c b/contrib/pageinspect/hashfuncs.c
index dbe3b6ab04..99b61b8669 100644
--- a/contrib/pageinspect/hashfuncs.c
+++ b/contrib/pageinspect/hashfuncs.c
@@ -2,7 +2,7 @@
* hashfuncs.c
* Functions to investigate the content of HASH indexes
*
- * Copyright (c) 2017, PostgreSQL Global Development Group
+ * Copyright (c) 2017-2018, PostgreSQL Global Development Group
*
* IDENTIFICATION
* contrib/pageinspect/hashfuncs.c
@@ -313,10 +313,10 @@ hash_page_items(PG_FUNCTION_ARGS)
fctx = SRF_FIRSTCALL_INIT();
- page = verify_hash_page(raw_page, LH_BUCKET_PAGE | LH_OVERFLOW_PAGE);
-
mctx = MemoryContextSwitchTo(fctx->multi_call_memory_ctx);
+ page = verify_hash_page(raw_page, LH_BUCKET_PAGE | LH_OVERFLOW_PAGE);
+
uargs = palloc(sizeof(struct user_args));
uargs->page = page;
diff --git a/contrib/pageinspect/heapfuncs.c b/contrib/pageinspect/heapfuncs.c
index 72d1776a4a..7438257c5b 100644
--- a/contrib/pageinspect/heapfuncs.c
+++ b/contrib/pageinspect/heapfuncs.c
@@ -15,7 +15,7 @@
* there's hardly any use case for using these without superuser-rights
* anyway.
*
- * Copyright (c) 2007-2017, PostgreSQL Global Development Group
+ * Copyright (c) 2007-2018, PostgreSQL Global Development Group
*
* IDENTIFICATION
* contrib/pageinspect/heapfuncs.c
@@ -234,7 +234,7 @@ heap_page_items(PG_FUNCTION_ARGS)
int bits_len;
bits_len =
- ((tuphdr->t_infomask2 & HEAP_NATTS_MASK) / 8 + 1) * 8;
+ BITMAPLEN(HeapTupleHeaderGetNatts(tuphdr)) * BITS_PER_BYTE;
values[11] = CStringGetTextDatum(
bits_to_text(tuphdr->t_bits, bits_len));
}
@@ -316,7 +316,7 @@ tuple_data_split_internal(Oid relid, char *tupdata,
bool is_null;
bytea *attr_data = NULL;
- attr = tupdesc->attrs[i];
+ attr = TupleDescAttr(tupdesc, i);
is_null = (t_infomask & HEAP_HASNULL) && att_isnull(i, t_bits);
/*
@@ -334,7 +334,7 @@ tuple_data_split_internal(Oid relid, char *tupdata,
if (attr->attlen == -1)
{
- off = att_align_pointer(off, tupdesc->attrs[i]->attalign, -1,
+ off = att_align_pointer(off, attr->attalign, -1,
tupdata + off);
/*
@@ -353,7 +353,7 @@ tuple_data_split_internal(Oid relid, char *tupdata,
}
else
{
- off = att_align_nominal(off, tupdesc->attrs[i]->attalign);
+ off = att_align_nominal(off, attr->attalign);
len = attr->attlen;
}
@@ -371,7 +371,7 @@ tuple_data_split_internal(Oid relid, char *tupdata,
memcpy(VARDATA(attr_data), tupdata + off, len);
}
- off = att_addlength_pointer(off, tupdesc->attrs[i]->attlen,
+ off = att_addlength_pointer(off, attr->attlen,
tupdata + off);
}
@@ -436,24 +436,19 @@ tuple_data_split(PG_FUNCTION_ARGS)
int bits_str_len;
int bits_len;
- bits_len = (t_infomask2 & HEAP_NATTS_MASK) / 8 + 1;
+ bits_len = BITMAPLEN(t_infomask2 & HEAP_NATTS_MASK) * BITS_PER_BYTE;
if (!t_bits_str)
ereport(ERROR,
(errcode(ERRCODE_DATA_CORRUPTED),
errmsg("argument of t_bits is null, but it is expected to be null and %d character long",
- bits_len * 8)));
+ bits_len)));
bits_str_len = strlen(t_bits_str);
- if ((bits_str_len % 8) != 0)
- ereport(ERROR,
- (errcode(ERRCODE_DATA_CORRUPTED),
- errmsg("length of t_bits is not a multiple of eight")));
-
- if (bits_len * 8 != bits_str_len)
+ if (bits_len != bits_str_len)
ereport(ERROR,
(errcode(ERRCODE_DATA_CORRUPTED),
errmsg("unexpected length of t_bits %u, expected %d",
- bits_str_len, bits_len * 8)));
+ bits_str_len, bits_len)));
/* do the conversion */
t_bits = text_to_bits(t_bits_str, bits_str_len);
diff --git a/contrib/pageinspect/pageinspect.h b/contrib/pageinspect/pageinspect.h
index f49cf9e892..ab7d5d66cd 100644
--- a/contrib/pageinspect/pageinspect.h
+++ b/contrib/pageinspect/pageinspect.h
@@ -3,7 +3,7 @@
* pageinspect.h
* Common functions for pageinspect.
*
- * Copyright (c) 2017, PostgreSQL Global Development Group
+ * Copyright (c) 2017-2018, PostgreSQL Global Development Group
*
* IDENTIFICATION
* contrib/pageinspect/pageinspect.h
diff --git a/contrib/pageinspect/rawpage.c b/contrib/pageinspect/rawpage.c
index e9d3131bda..3d4d4f6f93 100644
--- a/contrib/pageinspect/rawpage.c
+++ b/contrib/pageinspect/rawpage.c
@@ -5,7 +5,7 @@
*
* Access-method specific inspection functions are in separate files.
*
- * Copyright (c) 2007-2017, PostgreSQL Global Development Group
+ * Copyright (c) 2007-2018, PostgreSQL Global Development Group
*
* IDENTIFICATION
* contrib/pageinspect/rawpage.c
@@ -253,7 +253,7 @@ page_header(PG_FUNCTION_ARGS)
lsn = PageGetLSN(page);
/* pageinspect >= 1.2 uses pg_lsn instead of text for the LSN field. */
- if (tupdesc->attrs[0]->atttypid == TEXTOID)
+ if (TupleDescAttr(tupdesc, 0)->atttypid == TEXTOID)
{
char lsnchar[64];
diff --git a/contrib/pageinspect/sql/page.sql b/contrib/pageinspect/sql/page.sql
index 493ca9b211..8f35830e06 100644
--- a/contrib/pageinspect/sql/page.sql
+++ b/contrib/pageinspect/sql/page.sql
@@ -41,3 +41,11 @@ select get_raw_page('test_partitioned', 0); -- error about partitioned table
create table test_part1 partition of test_partitioned for values from ( 1 ) to (100);
select get_raw_page('test_part1', 0); -- get farther and error about empty table
drop table test_partitioned;
+
+-- check null bitmap alignment for table whose number of attributes is multiple of 8
+create table test8 (f1 int, f2 int, f3 int, f4 int, f5 int, f6 int, f7 int, f8 int);
+insert into test8(f1, f8) values (x'7f00007f'::int, 0);
+select t_bits, t_data from heap_page_items(get_raw_page('test8', 0));
+select tuple_data_split('test8'::regclass, t_data, t_infomask, t_infomask2, t_bits)
+ from heap_page_items(get_raw_page('test8', 0));
+drop table test8;
diff --git a/contrib/passwordcheck/.gitignore b/contrib/passwordcheck/.gitignore
new file mode 100644
index 0000000000..5dcb3ff972
--- /dev/null
+++ b/contrib/passwordcheck/.gitignore
@@ -0,0 +1,4 @@
+# Generated subdirectories
+/log/
+/results/
+/tmp_check/
diff --git a/contrib/passwordcheck/Makefile b/contrib/passwordcheck/Makefile
index 4652aeb3d7..4da0b1417c 100644
--- a/contrib/passwordcheck/Makefile
+++ b/contrib/passwordcheck/Makefile
@@ -8,6 +8,8 @@ PGFILEDESC = "passwordcheck - strengthen user password checks"
# PG_CPPFLAGS = -DUSE_CRACKLIB '-DCRACKLIB_DICTPATH="/usr/lib/cracklib_dict"'
# SHLIB_LINK = -lcrack
+REGRESS = passwordcheck
+
ifdef USE_PGXS
PG_CONFIG = pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
diff --git a/contrib/passwordcheck/expected/passwordcheck.out b/contrib/passwordcheck/expected/passwordcheck.out
new file mode 100644
index 0000000000..e04cda6bd9
--- /dev/null
+++ b/contrib/passwordcheck/expected/passwordcheck.out
@@ -0,0 +1,19 @@
+LOAD 'passwordcheck';
+CREATE USER regress_user1;
+-- ok
+ALTER USER regress_user1 PASSWORD 'a_nice_long_password';
+-- error: too short
+ALTER USER regress_user1 PASSWORD 'tooshrt';
+ERROR: password is too short
+-- error: contains user name
+ALTER USER regress_user1 PASSWORD 'xyzregress_user1';
+ERROR: password must not contain user name
+-- error: contains only letters
+ALTER USER regress_user1 PASSWORD 'alessnicelongpassword';
+ERROR: password must contain both letters and nonletters
+-- encrypted ok (password is "secret")
+ALTER USER regress_user1 PASSWORD 'md51a44d829a20a23eac686d9f0d258af13';
+-- error: password is user name
+ALTER USER regress_user1 PASSWORD 'md5e589150ae7d28f93333afae92b36ef48';
+ERROR: password must not equal user name
+DROP USER regress_user1;
diff --git a/contrib/passwordcheck/passwordcheck.c b/contrib/passwordcheck/passwordcheck.c
index b80fd458ad..d3d9ff3676 100644
--- a/contrib/passwordcheck/passwordcheck.c
+++ b/contrib/passwordcheck/passwordcheck.c
@@ -3,7 +3,7 @@
* passwordcheck.c
*
*
- * Copyright (c) 2009-2017, PostgreSQL Global Development Group
+ * Copyright (c) 2009-2018, PostgreSQL Global Development Group
*
* Author: Laurenz Albe
*
@@ -70,7 +70,7 @@ check_password(const char *username,
if (plain_crypt_verify(username, shadow_pass, username, &logdetail) == STATUS_OK)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("password must not contain user name")));
+ errmsg("password must not equal user name")));
}
else
{
diff --git a/contrib/passwordcheck/sql/passwordcheck.sql b/contrib/passwordcheck/sql/passwordcheck.sql
new file mode 100644
index 0000000000..d98796ac49
--- /dev/null
+++ b/contrib/passwordcheck/sql/passwordcheck.sql
@@ -0,0 +1,23 @@
+LOAD 'passwordcheck';
+
+CREATE USER regress_user1;
+
+-- ok
+ALTER USER regress_user1 PASSWORD 'a_nice_long_password';
+
+-- error: too short
+ALTER USER regress_user1 PASSWORD 'tooshrt';
+
+-- error: contains user name
+ALTER USER regress_user1 PASSWORD 'xyzregress_user1';
+
+-- error: contains only letters
+ALTER USER regress_user1 PASSWORD 'alessnicelongpassword';
+
+-- encrypted ok (password is "secret")
+ALTER USER regress_user1 PASSWORD 'md51a44d829a20a23eac686d9f0d258af13';
+
+-- error: password is user name
+ALTER USER regress_user1 PASSWORD 'md5e589150ae7d28f93333afae92b36ef48';
+
+DROP USER regress_user1;
diff --git a/contrib/pg_prewarm/Makefile b/contrib/pg_prewarm/Makefile
index 7ad941e72b..88580d1118 100644
--- a/contrib/pg_prewarm/Makefile
+++ b/contrib/pg_prewarm/Makefile
@@ -1,10 +1,10 @@
# contrib/pg_prewarm/Makefile
MODULE_big = pg_prewarm
-OBJS = pg_prewarm.o $(WIN32RES)
+OBJS = pg_prewarm.o autoprewarm.o $(WIN32RES)
EXTENSION = pg_prewarm
-DATA = pg_prewarm--1.1.sql pg_prewarm--1.0--1.1.sql
+DATA = pg_prewarm--1.1--1.2.sql pg_prewarm--1.1.sql pg_prewarm--1.0--1.1.sql
PGFILEDESC = "pg_prewarm - preload relation data into system buffer cache"
ifdef USE_PGXS
diff --git a/contrib/pg_prewarm/autoprewarm.c b/contrib/pg_prewarm/autoprewarm.c
new file mode 100644
index 0000000000..f99f9c07af
--- /dev/null
+++ b/contrib/pg_prewarm/autoprewarm.c
@@ -0,0 +1,928 @@
+/*-------------------------------------------------------------------------
+ *
+ * autoprewarm.c
+ * Periodically dump information about the blocks present in
+ * shared_buffers, and reload them on server restart.
+ *
+ * Due to locking considerations, we can't actually begin prewarming
+ * until the server reaches a consistent state. We need the catalogs
+ * to be consistent so that we can figure out which relation to lock,
+ * and we need to lock the relations so that we don't try to prewarm
+ * pages from a relation that is in the process of being dropped.
+ *
+ * While prewarming, autoprewarm will use two workers. There's a
+ * master worker that reads and sorts the list of blocks to be
+ * prewarmed and then launches a per-database worker for each
+ * relevant database in turn. The former keeps running after the
+ * initial prewarm is complete to update the dump file periodically.
+ *
+ * Copyright (c) 2016-2018, PostgreSQL Global Development Group
+ *
+ * IDENTIFICATION
+ * contrib/pg_prewarm/autoprewarm.c
+ *
+ *-------------------------------------------------------------------------
+ */
+
+#include "postgres.h"
+#include
+
+#include "access/heapam.h"
+#include "access/xact.h"
+#include "catalog/pg_class.h"
+#include "catalog/pg_type.h"
+#include "miscadmin.h"
+#include "pgstat.h"
+#include "postmaster/bgworker.h"
+#include "storage/buf_internals.h"
+#include "storage/dsm.h"
+#include "storage/ipc.h"
+#include "storage/latch.h"
+#include "storage/lwlock.h"
+#include "storage/proc.h"
+#include "storage/procsignal.h"
+#include "storage/shmem.h"
+#include "storage/smgr.h"
+#include "tcop/tcopprot.h"
+#include "utils/acl.h"
+#include "utils/guc.h"
+#include "utils/memutils.h"
+#include "utils/rel.h"
+#include "utils/relfilenodemap.h"
+#include "utils/resowner.h"
+
+#define AUTOPREWARM_FILE "autoprewarm.blocks"
+
+/* Metadata for each block we dump. */
+typedef struct BlockInfoRecord
+{
+ Oid database;
+ Oid tablespace;
+ Oid filenode;
+ ForkNumber forknum;
+ BlockNumber blocknum;
+} BlockInfoRecord;
+
+/* Shared state information for autoprewarm bgworker. */
+typedef struct AutoPrewarmSharedState
+{
+ LWLock lock; /* mutual exclusion */
+ pid_t bgworker_pid; /* for main bgworker */
+ pid_t pid_using_dumpfile; /* for autoprewarm or block dump */
+
+ /* Following items are for communication with per-database worker */
+ dsm_handle block_info_handle;
+ Oid database;
+ int64 prewarm_start_idx;
+ int64 prewarm_stop_idx;
+ int64 prewarmed_blocks;
+} AutoPrewarmSharedState;
+
+void _PG_init(void);
+void autoprewarm_main(Datum main_arg);
+void autoprewarm_database_main(Datum main_arg);
+
+PG_FUNCTION_INFO_V1(autoprewarm_start_worker);
+PG_FUNCTION_INFO_V1(autoprewarm_dump_now);
+
+static void apw_load_buffers(void);
+static int64 apw_dump_now(bool is_bgworker, bool dump_unlogged);
+static void apw_start_master_worker(void);
+static void apw_start_database_worker(void);
+static bool apw_init_shmem(void);
+static void apw_detach_shmem(int code, Datum arg);
+static int apw_compare_blockinfo(const void *p, const void *q);
+static void apw_sigterm_handler(SIGNAL_ARGS);
+static void apw_sighup_handler(SIGNAL_ARGS);
+
+/* Flags set by signal handlers */
+static volatile sig_atomic_t got_sigterm = false;
+static volatile sig_atomic_t got_sighup = false;
+
+/* Pointer to shared-memory state. */
+static AutoPrewarmSharedState *apw_state = NULL;
+
+/* GUC variables. */
+static bool autoprewarm = true; /* start worker? */
+static int autoprewarm_interval; /* dump interval */
+
+/*
+ * Module load callback.
+ */
+void
+_PG_init(void)
+{
+ DefineCustomIntVariable("pg_prewarm.autoprewarm_interval",
+ "Sets the interval between dumps of shared buffers",
+ "If set to zero, time-based dumping is disabled.",
+ &autoprewarm_interval,
+ 300,
+ 0, INT_MAX / 1000,
+ PGC_SIGHUP,
+ GUC_UNIT_S,
+ NULL,
+ NULL,
+ NULL);
+
+ if (!process_shared_preload_libraries_in_progress)
+ return;
+
+ /* can't define PGC_POSTMASTER variable after startup */
+ DefineCustomBoolVariable("pg_prewarm.autoprewarm",
+ "Starts the autoprewarm worker.",
+ NULL,
+ &autoprewarm,
+ true,
+ PGC_POSTMASTER,
+ 0,
+ NULL,
+ NULL,
+ NULL);
+
+ EmitWarningsOnPlaceholders("pg_prewarm");
+
+ RequestAddinShmemSpace(MAXALIGN(sizeof(AutoPrewarmSharedState)));
+
+ /* Register autoprewarm worker, if enabled. */
+ if (autoprewarm)
+ apw_start_master_worker();
+}
+
+/*
+ * Main entry point for the master autoprewarm process. Per-database workers
+ * have a separate entry point.
+ */
+void
+autoprewarm_main(Datum main_arg)
+{
+ bool first_time = true;
+ TimestampTz last_dump_time = 0;
+
+ /* Establish signal handlers; once that's done, unblock signals. */
+ pqsignal(SIGTERM, apw_sigterm_handler);
+ pqsignal(SIGHUP, apw_sighup_handler);
+ pqsignal(SIGUSR1, procsignal_sigusr1_handler);
+ BackgroundWorkerUnblockSignals();
+
+ /* Create (if necessary) and attach to our shared memory area. */
+ if (apw_init_shmem())
+ first_time = false;
+
+ /* Set on-detach hook so that our PID will be cleared on exit. */
+ on_shmem_exit(apw_detach_shmem, 0);
+
+ /*
+ * Store our PID in the shared memory area --- unless there's already
+ * another worker running, in which case just exit.
+ */
+ LWLockAcquire(&apw_state->lock, LW_EXCLUSIVE);
+ if (apw_state->bgworker_pid != InvalidPid)
+ {
+ LWLockRelease(&apw_state->lock);
+ ereport(LOG,
+ (errmsg("autoprewarm worker is already running under PID %d",
+ apw_state->bgworker_pid)));
+ return;
+ }
+ apw_state->bgworker_pid = MyProcPid;
+ LWLockRelease(&apw_state->lock);
+
+ /*
+ * Preload buffers from the dump file only if we just created the shared
+ * memory region. Otherwise, it's either already been done or shouldn't
+ * be done - e.g. because the old dump file has been overwritten since the
+ * server was started.
+ *
+ * There's not much point in performing a dump immediately after we finish
+ * preloading; so, if we do end up preloading, consider the last dump time
+ * to be equal to the current time.
+ */
+ if (first_time)
+ {
+ apw_load_buffers();
+ last_dump_time = GetCurrentTimestamp();
+ }
+
+ /* Periodically dump buffers until terminated. */
+ while (!got_sigterm)
+ {
+ int rc;
+
+ /* In case of a SIGHUP, just reload the configuration. */
+ if (got_sighup)
+ {
+ got_sighup = false;
+ ProcessConfigFile(PGC_SIGHUP);
+ }
+
+ if (autoprewarm_interval <= 0)
+ {
+ /* We're only dumping at shutdown, so just wait forever. */
+ rc = WaitLatch(&MyProc->procLatch,
+ WL_LATCH_SET | WL_POSTMASTER_DEATH,
+ -1L,
+ PG_WAIT_EXTENSION);
+ }
+ else
+ {
+ long delay_in_ms = 0;
+ TimestampTz next_dump_time = 0;
+ long secs = 0;
+ int usecs = 0;
+
+ /* Compute the next dump time. */
+ next_dump_time =
+ TimestampTzPlusMilliseconds(last_dump_time,
+ autoprewarm_interval * 1000);
+ TimestampDifference(GetCurrentTimestamp(), next_dump_time,
+ &secs, &usecs);
+ delay_in_ms = secs + (usecs / 1000);
+
+ /* Perform a dump if it's time. */
+ if (delay_in_ms <= 0)
+ {
+ last_dump_time = GetCurrentTimestamp();
+ apw_dump_now(true, false);
+ continue;
+ }
+
+ /* Sleep until the next dump time. */
+ rc = WaitLatch(&MyProc->procLatch,
+ WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH,
+ delay_in_ms,
+ PG_WAIT_EXTENSION);
+ }
+
+ /* Reset the latch, bail out if postmaster died, otherwise loop. */
+ ResetLatch(&MyProc->procLatch);
+ if (rc & WL_POSTMASTER_DEATH)
+ proc_exit(1);
+ }
+
+ /*
+ * Dump one last time. We assume this is probably the result of a system
+ * shutdown, although it's possible that we've merely been terminated.
+ */
+ apw_dump_now(true, true);
+}
+
+/*
+ * Read the dump file and launch per-database workers one at a time to
+ * prewarm the buffers found there.
+ */
+static void
+apw_load_buffers(void)
+{
+ FILE *file = NULL;
+ int64 num_elements,
+ i;
+ BlockInfoRecord *blkinfo;
+ dsm_segment *seg;
+
+ /*
+ * Skip the prewarm if the dump file is in use; otherwise, prevent any
+ * other process from writing it while we're using it.
+ */
+ LWLockAcquire(&apw_state->lock, LW_EXCLUSIVE);
+ if (apw_state->pid_using_dumpfile == InvalidPid)
+ apw_state->pid_using_dumpfile = MyProcPid;
+ else
+ {
+ LWLockRelease(&apw_state->lock);
+ ereport(LOG,
+ (errmsg("skipping prewarm because block dump file is being written by PID %d",
+ apw_state->pid_using_dumpfile)));
+ return;
+ }
+ LWLockRelease(&apw_state->lock);
+
+ /*
+ * Open the block dump file. Exit quietly if it doesn't exist, but report
+ * any other error.
+ */
+ file = AllocateFile(AUTOPREWARM_FILE, "r");
+ if (!file)
+ {
+ if (errno == ENOENT)
+ {
+ LWLockAcquire(&apw_state->lock, LW_EXCLUSIVE);
+ apw_state->pid_using_dumpfile = InvalidPid;
+ LWLockRelease(&apw_state->lock);
+ return; /* No file to load. */
+ }
+ ereport(ERROR,
+ (errcode_for_file_access(),
+ errmsg("could not read file \"%s\": %m",
+ AUTOPREWARM_FILE)));
+ }
+
+ /* First line of the file is a record count. */
+ if (fscanf(file, "<<" INT64_FORMAT ">>\n", &num_elements) != 1)
+ ereport(ERROR,
+ (errcode_for_file_access(),
+ errmsg("could not read from file \"%s\": %m",
+ AUTOPREWARM_FILE)));
+
+ /* Allocate a dynamic shared memory segment to store the record data. */
+ seg = dsm_create(sizeof(BlockInfoRecord) * num_elements, 0);
+ blkinfo = (BlockInfoRecord *) dsm_segment_address(seg);
+
+ /* Read records, one per line. */
+ for (i = 0; i < num_elements; i++)
+ {
+ unsigned forknum;
+
+ if (fscanf(file, "%u,%u,%u,%u,%u\n", &blkinfo[i].database,
+ &blkinfo[i].tablespace, &blkinfo[i].filenode,
+ &forknum, &blkinfo[i].blocknum) != 5)
+ ereport(ERROR,
+ (errmsg("autoprewarm block dump file is corrupted at line " INT64_FORMAT,
+ i + 1)));
+ blkinfo[i].forknum = forknum;
+ }
+
+ FreeFile(file);
+
+ /* Sort the blocks to be loaded. */
+ pg_qsort(blkinfo, num_elements, sizeof(BlockInfoRecord),
+ apw_compare_blockinfo);
+
+ /* Populate shared memory state. */
+ apw_state->block_info_handle = dsm_segment_handle(seg);
+ apw_state->prewarm_start_idx = apw_state->prewarm_stop_idx = 0;
+ apw_state->prewarmed_blocks = 0;
+
+ /* Get the info position of the first block of the next database. */
+ while (apw_state->prewarm_start_idx < num_elements)
+ {
+ uint32 i = apw_state->prewarm_start_idx;
+ Oid current_db = blkinfo[i].database;
+
+ /*
+ * Advance the prewarm_stop_idx to the first BlockRecordInfo that does
+ * not belong to this database.
+ */
+ i++;
+ while (i < num_elements)
+ {
+ if (current_db != blkinfo[i].database)
+ {
+ /*
+ * Combine BlockRecordInfos for global objects with those of
+ * the database.
+ */
+ if (current_db != InvalidOid)
+ break;
+ current_db = blkinfo[i].database;
+ }
+
+ i++;
+ }
+
+ /*
+ * If we reach this point with current_db == InvalidOid, then only
+ * BlockRecordInfos belonging to global objects exist. We can't
+ * prewarm without a database connection, so just bail out.
+ */
+ if (current_db == InvalidOid)
+ break;
+
+ /* Configure stop point and database for next per-database worker. */
+ apw_state->prewarm_stop_idx = i;
+ apw_state->database = current_db;
+ Assert(apw_state->prewarm_start_idx < apw_state->prewarm_stop_idx);
+
+ /* If we've run out of free buffers, don't launch another worker. */
+ if (!have_free_buffer())
+ break;
+
+ /*
+ * Start a per-database worker to load blocks for this database; this
+ * function will return once the per-database worker exits.
+ */
+ apw_start_database_worker();
+
+ /* Prepare for next database. */
+ apw_state->prewarm_start_idx = apw_state->prewarm_stop_idx;
+ }
+
+ /* Clean up. */
+ dsm_detach(seg);
+ LWLockAcquire(&apw_state->lock, LW_EXCLUSIVE);
+ apw_state->block_info_handle = DSM_HANDLE_INVALID;
+ apw_state->pid_using_dumpfile = InvalidPid;
+ LWLockRelease(&apw_state->lock);
+
+ /* Report our success. */
+ ereport(LOG,
+ (errmsg("autoprewarm successfully prewarmed " INT64_FORMAT
+ " of " INT64_FORMAT " previously-loaded blocks",
+ apw_state->prewarmed_blocks, num_elements)));
+}
+
+/*
+ * Prewarm all blocks for one database (and possibly also global objects, if
+ * those got grouped with this database).
+ */
+void
+autoprewarm_database_main(Datum main_arg)
+{
+ uint32 pos;
+ BlockInfoRecord *block_info;
+ Relation rel = NULL;
+ BlockNumber nblocks = 0;
+ BlockInfoRecord *old_blk = NULL;
+ dsm_segment *seg;
+
+ /* Establish signal handlers; once that's done, unblock signals. */
+ pqsignal(SIGTERM, die);
+ BackgroundWorkerUnblockSignals();
+
+ /* Connect to correct database and get block information. */
+ apw_init_shmem();
+ seg = dsm_attach(apw_state->block_info_handle);
+ if (seg == NULL)
+ ereport(ERROR,
+ (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
+ errmsg("could not map dynamic shared memory segment")));
+ BackgroundWorkerInitializeConnectionByOid(apw_state->database, InvalidOid);
+ block_info = (BlockInfoRecord *) dsm_segment_address(seg);
+ pos = apw_state->prewarm_start_idx;
+
+ /*
+ * Loop until we run out of blocks to prewarm or until we run out of free
+ * buffers.
+ */
+ while (pos < apw_state->prewarm_stop_idx && have_free_buffer())
+ {
+ BlockInfoRecord *blk = &block_info[pos++];
+ Buffer buf;
+
+ CHECK_FOR_INTERRUPTS();
+
+ /*
+ * Quit if we've reached records for another database. If previous
+ * blocks are of some global objects, then continue pre-warming.
+ */
+ if (old_blk != NULL && old_blk->database != blk->database &&
+ old_blk->database != 0)
+ break;
+
+ /*
+ * As soon as we encounter a block of a new relation, close the old
+ * relation. Note that rel will be NULL if try_relation_open failed
+ * previously; in that case, there is nothing to close.
+ */
+ if (old_blk != NULL && old_blk->filenode != blk->filenode &&
+ rel != NULL)
+ {
+ relation_close(rel, AccessShareLock);
+ rel = NULL;
+ CommitTransactionCommand();
+ }
+
+ /*
+ * Try to open each new relation, but only once, when we first
+ * encounter it. If it's been dropped, skip the associated blocks.
+ */
+ if (old_blk == NULL || old_blk->filenode != blk->filenode)
+ {
+ Oid reloid;
+
+ Assert(rel == NULL);
+ StartTransactionCommand();
+ reloid = RelidByRelfilenode(blk->tablespace, blk->filenode);
+ if (OidIsValid(reloid))
+ rel = try_relation_open(reloid, AccessShareLock);
+
+ if (!rel)
+ CommitTransactionCommand();
+ }
+ if (!rel)
+ {
+ old_blk = blk;
+ continue;
+ }
+
+ /* Once per fork, check for fork existence and size. */
+ if (old_blk == NULL ||
+ old_blk->filenode != blk->filenode ||
+ old_blk->forknum != blk->forknum)
+ {
+ RelationOpenSmgr(rel);
+
+ /*
+ * smgrexists is not safe for illegal forknum, hence check whether
+ * the passed forknum is valid before using it in smgrexists.
+ */
+ if (blk->forknum > InvalidForkNumber &&
+ blk->forknum <= MAX_FORKNUM &&
+ smgrexists(rel->rd_smgr, blk->forknum))
+ nblocks = RelationGetNumberOfBlocksInFork(rel, blk->forknum);
+ else
+ nblocks = 0;
+ }
+
+ /* Check whether blocknum is valid and within fork file size. */
+ if (blk->blocknum >= nblocks)
+ {
+ /* Move to next forknum. */
+ old_blk = blk;
+ continue;
+ }
+
+ /* Prewarm buffer. */
+ buf = ReadBufferExtended(rel, blk->forknum, blk->blocknum, RBM_NORMAL,
+ NULL);
+ if (BufferIsValid(buf))
+ {
+ apw_state->prewarmed_blocks++;
+ ReleaseBuffer(buf);
+ }
+
+ old_blk = blk;
+ }
+
+ dsm_detach(seg);
+
+ /* Release lock on previous relation. */
+ if (rel)
+ {
+ relation_close(rel, AccessShareLock);
+ CommitTransactionCommand();
+ }
+}
+
+/*
+ * Dump information on blocks in shared buffers. We use a text format here
+ * so that it's easy to understand and even change the file contents if
+ * necessary.
+ */
+static int64
+apw_dump_now(bool is_bgworker, bool dump_unlogged)
+{
+ uint32 i;
+ int ret;
+ int64 num_blocks;
+ BlockInfoRecord *block_info_array;
+ BufferDesc *bufHdr;
+ FILE *file;
+ char transient_dump_file_path[MAXPGPATH];
+ pid_t pid;
+
+ LWLockAcquire(&apw_state->lock, LW_EXCLUSIVE);
+ pid = apw_state->pid_using_dumpfile;
+ if (apw_state->pid_using_dumpfile == InvalidPid)
+ apw_state->pid_using_dumpfile = MyProcPid;
+ LWLockRelease(&apw_state->lock);
+
+ if (pid != InvalidPid)
+ {
+ if (!is_bgworker)
+ ereport(ERROR,
+ (errmsg("could not perform block dump because dump file is being used by PID %d",
+ apw_state->pid_using_dumpfile)));
+
+ ereport(LOG,
+ (errmsg("skipping block dump because it is already being performed by PID %d",
+ apw_state->pid_using_dumpfile)));
+ return 0;
+ }
+
+ block_info_array =
+ (BlockInfoRecord *) palloc(sizeof(BlockInfoRecord) * NBuffers);
+
+ for (num_blocks = 0, i = 0; i < NBuffers; i++)
+ {
+ uint32 buf_state;
+
+ CHECK_FOR_INTERRUPTS();
+
+ bufHdr = GetBufferDescriptor(i);
+
+ /* Lock each buffer header before inspecting. */
+ buf_state = LockBufHdr(bufHdr);
+
+ /*
+ * Unlogged tables will be automatically truncated after a crash or
+ * unclean shutdown. In such cases we need not prewarm them. Dump them
+ * only if requested by caller.
+ */
+ if (buf_state & BM_TAG_VALID &&
+ ((buf_state & BM_PERMANENT) || dump_unlogged))
+ {
+ block_info_array[num_blocks].database = bufHdr->tag.rnode.dbNode;
+ block_info_array[num_blocks].tablespace = bufHdr->tag.rnode.spcNode;
+ block_info_array[num_blocks].filenode = bufHdr->tag.rnode.relNode;
+ block_info_array[num_blocks].forknum = bufHdr->tag.forkNum;
+ block_info_array[num_blocks].blocknum = bufHdr->tag.blockNum;
+ ++num_blocks;
+ }
+
+ UnlockBufHdr(bufHdr, buf_state);
+ }
+
+ snprintf(transient_dump_file_path, MAXPGPATH, "%s.tmp", AUTOPREWARM_FILE);
+ file = AllocateFile(transient_dump_file_path, "w");
+ if (!file)
+ ereport(ERROR,
+ (errcode_for_file_access(),
+ errmsg("could not open file \"%s\": %m",
+ transient_dump_file_path)));
+
+ ret = fprintf(file, "<<" INT64_FORMAT ">>\n", num_blocks);
+ if (ret < 0)
+ {
+ int save_errno = errno;
+
+ FreeFile(file);
+ unlink(transient_dump_file_path);
+ errno = save_errno;
+ ereport(ERROR,
+ (errcode_for_file_access(),
+ errmsg("could not write to file \"%s\" : %m",
+ transient_dump_file_path)));
+ }
+
+ for (i = 0; i < num_blocks; i++)
+ {
+ CHECK_FOR_INTERRUPTS();
+
+ ret = fprintf(file, "%u,%u,%u,%u,%u\n",
+ block_info_array[i].database,
+ block_info_array[i].tablespace,
+ block_info_array[i].filenode,
+ (uint32) block_info_array[i].forknum,
+ block_info_array[i].blocknum);
+ if (ret < 0)
+ {
+ int save_errno = errno;
+
+ FreeFile(file);
+ unlink(transient_dump_file_path);
+ errno = save_errno;
+ ereport(ERROR,
+ (errcode_for_file_access(),
+ errmsg("could not write to file \"%s\" : %m",
+ transient_dump_file_path)));
+ }
+ }
+
+ pfree(block_info_array);
+
+ /*
+ * Rename transient_dump_file_path to AUTOPREWARM_FILE to make things
+ * permanent.
+ */
+ ret = FreeFile(file);
+ if (ret != 0)
+ {
+ int save_errno = errno;
+
+ unlink(transient_dump_file_path);
+ errno = save_errno;
+ ereport(ERROR,
+ (errcode_for_file_access(),
+ errmsg("could not close file \"%s\" : %m",
+ transient_dump_file_path)));
+ }
+
+ (void) durable_rename(transient_dump_file_path, AUTOPREWARM_FILE, ERROR);
+ apw_state->pid_using_dumpfile = InvalidPid;
+
+ ereport(DEBUG1,
+ (errmsg("wrote block details for " INT64_FORMAT " blocks",
+ num_blocks)));
+ return num_blocks;
+}
+
+/*
+ * SQL-callable function to launch autoprewarm.
+ */
+Datum
+autoprewarm_start_worker(PG_FUNCTION_ARGS)
+{
+ pid_t pid;
+
+ if (!autoprewarm)
+ ereport(ERROR,
+ (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
+ errmsg("autoprewarm is disabled")));
+
+ apw_init_shmem();
+ LWLockAcquire(&apw_state->lock, LW_EXCLUSIVE);
+ pid = apw_state->bgworker_pid;
+ LWLockRelease(&apw_state->lock);
+
+ if (pid != InvalidPid)
+ ereport(ERROR,
+ (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
+ errmsg("autoprewarm worker is already running under PID %d",
+ pid)));
+
+ apw_start_master_worker();
+
+ PG_RETURN_VOID();
+}
+
+/*
+ * SQL-callable function to perform an immediate block dump.
+ */
+Datum
+autoprewarm_dump_now(PG_FUNCTION_ARGS)
+{
+ int64 num_blocks;
+
+ apw_init_shmem();
+
+ PG_ENSURE_ERROR_CLEANUP(apw_detach_shmem, 0);
+ {
+ num_blocks = apw_dump_now(false, true);
+ }
+ PG_END_ENSURE_ERROR_CLEANUP(apw_detach_shmem, 0);
+
+ PG_RETURN_INT64(num_blocks);
+}
+
+/*
+ * Allocate and initialize autoprewarm related shared memory, if not already
+ * done, and set up backend-local pointer to that state. Returns true if an
+ * existing shared memory segment was found.
+ */
+static bool
+apw_init_shmem(void)
+{
+ bool found;
+
+ LWLockAcquire(AddinShmemInitLock, LW_EXCLUSIVE);
+ apw_state = ShmemInitStruct("autoprewarm",
+ sizeof(AutoPrewarmSharedState),
+ &found);
+ if (!found)
+ {
+ /* First time through ... */
+ LWLockInitialize(&apw_state->lock, LWLockNewTrancheId());
+ apw_state->bgworker_pid = InvalidPid;
+ apw_state->pid_using_dumpfile = InvalidPid;
+ }
+ LWLockRelease(AddinShmemInitLock);
+
+ LWLockRegisterTranche(apw_state->lock.tranche, "autoprewarm");
+
+ return found;
+}
+
+/*
+ * Clear our PID from autoprewarm shared state.
+ */
+static void
+apw_detach_shmem(int code, Datum arg)
+{
+ LWLockAcquire(&apw_state->lock, LW_EXCLUSIVE);
+ if (apw_state->pid_using_dumpfile == MyProcPid)
+ apw_state->pid_using_dumpfile = InvalidPid;
+ if (apw_state->bgworker_pid == MyProcPid)
+ apw_state->bgworker_pid = InvalidPid;
+ LWLockRelease(&apw_state->lock);
+}
+
+/*
+ * Start autoprewarm master worker process.
+ */
+static void
+apw_start_master_worker(void)
+{
+ BackgroundWorker worker;
+ BackgroundWorkerHandle *handle;
+ BgwHandleStatus status;
+ pid_t pid;
+
+ MemSet(&worker, 0, sizeof(BackgroundWorker));
+ worker.bgw_flags = BGWORKER_SHMEM_ACCESS;
+ worker.bgw_start_time = BgWorkerStart_ConsistentState;
+ strcpy(worker.bgw_library_name, "pg_prewarm");
+ strcpy(worker.bgw_function_name, "autoprewarm_main");
+ strcpy(worker.bgw_name, "autoprewarm master");
+ strcpy(worker.bgw_type, "autoprewarm master");
+
+ if (process_shared_preload_libraries_in_progress)
+ {
+ RegisterBackgroundWorker(&worker);
+ return;
+ }
+
+ /* must set notify PID to wait for startup */
+ worker.bgw_notify_pid = MyProcPid;
+
+ if (!RegisterDynamicBackgroundWorker(&worker, &handle))
+ ereport(ERROR,
+ (errcode(ERRCODE_INSUFFICIENT_RESOURCES),
+ errmsg("could not register background process"),
+ errhint("You may need to increase max_worker_processes.")));
+
+ status = WaitForBackgroundWorkerStartup(handle, &pid);
+ if (status != BGWH_STARTED)
+ ereport(ERROR,
+ (errcode(ERRCODE_INSUFFICIENT_RESOURCES),
+ errmsg("could not start background process"),
+ errhint("More details may be available in the server log.")));
+}
+
+/*
+ * Start autoprewarm per-database worker process.
+ */
+static void
+apw_start_database_worker(void)
+{
+ BackgroundWorker worker;
+ BackgroundWorkerHandle *handle;
+
+ MemSet(&worker, 0, sizeof(BackgroundWorker));
+ worker.bgw_flags =
+ BGWORKER_SHMEM_ACCESS | BGWORKER_BACKEND_DATABASE_CONNECTION;
+ worker.bgw_start_time = BgWorkerStart_ConsistentState;
+ strcpy(worker.bgw_library_name, "pg_prewarm");
+ strcpy(worker.bgw_function_name, "autoprewarm_database_main");
+ strcpy(worker.bgw_name, "autoprewarm worker");
+ strcpy(worker.bgw_type, "autoprewarm worker");
+
+ /* must set notify PID to wait for shutdown */
+ worker.bgw_notify_pid = MyProcPid;
+
+ if (!RegisterDynamicBackgroundWorker(&worker, &handle))
+ ereport(ERROR,
+ (errcode(ERRCODE_INSUFFICIENT_RESOURCES),
+ errmsg("registering dynamic bgworker autoprewarm failed"),
+ errhint("Consider increasing configuration parameter \"max_worker_processes\".")));
+
+ /*
+ * Ignore return value; if it fails, postmaster has died, but we have
+ * checks for that elsewhere.
+ */
+ WaitForBackgroundWorkerShutdown(handle);
+}
+
+/* Compare member elements to check whether they are not equal. */
+#define cmp_member_elem(fld) \
+do { \
+ if (a->fld < b->fld) \
+ return -1; \
+ else if (a->fld > b->fld) \
+ return 1; \
+} while(0);
+
+/*
+ * apw_compare_blockinfo
+ *
+ * We depend on all records for a particular database being consecutive
+ * in the dump file; each per-database worker will preload blocks until
+ * it sees a block for some other database. Sorting by tablespace,
+ * filenode, forknum, and blocknum isn't critical for correctness, but
+ * helps us get a sequential I/O pattern.
+ */
+static int
+apw_compare_blockinfo(const void *p, const void *q)
+{
+ BlockInfoRecord *a = (BlockInfoRecord *) p;
+ BlockInfoRecord *b = (BlockInfoRecord *) q;
+
+ cmp_member_elem(database);
+ cmp_member_elem(tablespace);
+ cmp_member_elem(filenode);
+ cmp_member_elem(forknum);
+ cmp_member_elem(blocknum);
+
+ return 0;
+}
+
+/*
+ * Signal handler for SIGTERM
+ */
+static void
+apw_sigterm_handler(SIGNAL_ARGS)
+{
+ int save_errno = errno;
+
+ got_sigterm = true;
+
+ if (MyProc)
+ SetLatch(&MyProc->procLatch);
+
+ errno = save_errno;
+}
+
+/*
+ * Signal handler for SIGHUP
+ */
+static void
+apw_sighup_handler(SIGNAL_ARGS)
+{
+ int save_errno = errno;
+
+ got_sighup = true;
+
+ if (MyProc)
+ SetLatch(&MyProc->procLatch);
+
+ errno = save_errno;
+}
diff --git a/contrib/pg_prewarm/pg_prewarm--1.1--1.2.sql b/contrib/pg_prewarm/pg_prewarm--1.1--1.2.sql
new file mode 100644
index 0000000000..2381c06eb9
--- /dev/null
+++ b/contrib/pg_prewarm/pg_prewarm--1.1--1.2.sql
@@ -0,0 +1,14 @@
+/* contrib/pg_prewarm/pg_prewarm--1.1--1.2.sql */
+
+-- complain if script is sourced in psql, rather than via ALTER EXTENSION
+\echo Use "ALTER EXTENSION pg_prewarm UPDATE TO '1.2'" to load this file. \quit
+
+CREATE FUNCTION autoprewarm_start_worker()
+RETURNS VOID STRICT
+AS 'MODULE_PATHNAME', 'autoprewarm_start_worker'
+LANGUAGE C;
+
+CREATE FUNCTION autoprewarm_dump_now()
+RETURNS pg_catalog.int8 STRICT
+AS 'MODULE_PATHNAME', 'autoprewarm_dump_now'
+LANGUAGE C;
diff --git a/contrib/pg_prewarm/pg_prewarm.c b/contrib/pg_prewarm/pg_prewarm.c
index fec62b1a54..7f084462b1 100644
--- a/contrib/pg_prewarm/pg_prewarm.c
+++ b/contrib/pg_prewarm/pg_prewarm.c
@@ -3,7 +3,7 @@
* pg_prewarm.c
* prewarming utilities
*
- * Copyright (c) 2010-2017, PostgreSQL Global Development Group
+ * Copyright (c) 2010-2018, PostgreSQL Global Development Group
*
* IDENTIFICATION
* contrib/pg_prewarm/pg_prewarm.c
@@ -107,7 +107,7 @@ pg_prewarm(PG_FUNCTION_ARGS)
rel = relation_open(relOid, AccessShareLock);
aclresult = pg_class_aclcheck(relOid, GetUserId(), ACL_SELECT);
if (aclresult != ACLCHECK_OK)
- aclcheck_error(aclresult, ACL_KIND_CLASS, get_rel_name(relOid));
+ aclcheck_error(aclresult, get_relkind_objtype(rel->rd_rel->relkind), get_rel_name(relOid));
/* Check that the fork exists. */
RelationOpenSmgr(rel);
diff --git a/contrib/pg_prewarm/pg_prewarm.control b/contrib/pg_prewarm/pg_prewarm.control
index cf2fb92bed..40e3add481 100644
--- a/contrib/pg_prewarm/pg_prewarm.control
+++ b/contrib/pg_prewarm/pg_prewarm.control
@@ -1,5 +1,5 @@
# pg_prewarm extension
comment = 'prewarm relation data'
-default_version = '1.1'
+default_version = '1.2'
module_pathname = '$libdir/pg_prewarm'
relocatable = true
diff --git a/contrib/pg_standby/pg_standby.c b/contrib/pg_standby/pg_standby.c
index d7fa2a80c6..cb785971a9 100644
--- a/contrib/pg_standby/pg_standby.c
+++ b/contrib/pg_standby/pg_standby.c
@@ -36,6 +36,8 @@
const char *progname;
+int WalSegSz = -1;
+
/* Options and defaults */
int sleeptime = 5; /* amount of time to sleep between file checks */
int waittime = -1; /* how long we have been waiting, -1 no wait
@@ -100,6 +102,10 @@ int nextWALFileType;
struct stat stat_buf;
+static bool SetWALFileNameForCleanup(void);
+static bool SetWALSegSize(void);
+
+
/* =====================================================================
*
* Customizable section
@@ -175,6 +181,35 @@ CustomizableNextWALFileReady(void)
{
if (stat(WALFilePath, &stat_buf) == 0)
{
+ /*
+ * If we've not seen any WAL segments, we don't know the WAL segment
+ * size, which we need. If it looks like a WAL segment, determine size
+ * of segments for the cluster.
+ */
+ if (WalSegSz == -1 && IsXLogFileName(nextWALFileName))
+ {
+ if (SetWALSegSize())
+ {
+ /*
+ * Successfully determined WAL segment size. Can compute
+ * cleanup cutoff now.
+ */
+ need_cleanup = SetWALFileNameForCleanup();
+ if (debug)
+ {
+ fprintf(stderr,
+ _("WAL segment size: %d \n"), WalSegSz);
+ fprintf(stderr, "Keep archive history: ");
+
+ if (need_cleanup)
+ fprintf(stderr, "%s and later\n",
+ exclusiveCleanupFileName);
+ else
+ fprintf(stderr, "no cleanup required\n");
+ }
+ }
+ }
+
/*
* If it's a backup file, return immediately. If it's a regular file
* return only if it's the right size already.
@@ -184,7 +219,7 @@ CustomizableNextWALFileReady(void)
nextWALFileType = XLOG_BACKUP_LABEL;
return true;
}
- else if (stat_buf.st_size == XLOG_SEG_SIZE)
+ else if (WalSegSz > 0 && stat_buf.st_size == WalSegSz)
{
#ifdef WIN32
@@ -204,7 +239,7 @@ CustomizableNextWALFileReady(void)
/*
* If still too small, wait until it is the correct size
*/
- if (stat_buf.st_size > XLOG_SEG_SIZE)
+ if (WalSegSz > 0 && stat_buf.st_size > WalSegSz)
{
if (debug)
{
@@ -218,8 +253,6 @@ CustomizableNextWALFileReady(void)
return false;
}
-#define MaxSegmentsPerLogFile ( 0xFFFFFFFF / XLOG_SEG_SIZE )
-
static void
CustomizableCleanupPriorWALFiles(void)
{
@@ -315,6 +348,7 @@ SetWALFileNameForCleanup(void)
uint32 log_diff = 0,
seg_diff = 0;
bool cleanup = false;
+ int max_segments_per_logfile = (0xFFFFFFFF / WalSegSz);
if (restartWALFileName)
{
@@ -336,12 +370,12 @@ SetWALFileNameForCleanup(void)
sscanf(nextWALFileName, "%08X%08X%08X", &tli, &log, &seg);
if (tli > 0 && seg > 0)
{
- log_diff = keepfiles / MaxSegmentsPerLogFile;
- seg_diff = keepfiles % MaxSegmentsPerLogFile;
+ log_diff = keepfiles / max_segments_per_logfile;
+ seg_diff = keepfiles % max_segments_per_logfile;
if (seg_diff > seg)
{
log_diff++;
- seg = MaxSegmentsPerLogFile - (seg_diff - seg);
+ seg = max_segments_per_logfile - (seg_diff - seg);
}
else
seg -= seg_diff;
@@ -364,6 +398,74 @@ SetWALFileNameForCleanup(void)
return cleanup;
}
+/*
+ * Try to set the wal segment size from the WAL file specified by WALFilePath.
+ *
+ * Return true if size could be determined, false otherwise.
+ */
+static bool
+SetWALSegSize(void)
+{
+ bool ret_val = false;
+ int fd;
+
+ /* malloc this buffer to ensure sufficient alignment: */
+ char *buf = (char *) pg_malloc(XLOG_BLCKSZ);
+
+ Assert(WalSegSz == -1);
+
+ if ((fd = open(WALFilePath, O_RDWR, 0)) < 0)
+ {
+ fprintf(stderr, "%s: could not open WAL file \"%s\": %s\n",
+ progname, WALFilePath, strerror(errno));
+ pg_free(buf);
+ return false;
+ }
+
+ errno = 0;
+ if (read(fd, buf, XLOG_BLCKSZ) == XLOG_BLCKSZ)
+ {
+ XLogLongPageHeader longhdr = (XLogLongPageHeader) buf;
+
+ WalSegSz = longhdr->xlp_seg_size;
+
+ if (IsValidWalSegSize(WalSegSz))
+ {
+ /* successfully retrieved WAL segment size */
+ ret_val = true;
+ }
+ else
+ fprintf(stderr,
+ "%s: WAL segment size must be a power of two between 1MB and 1GB, but the WAL file header specifies %d bytes\n",
+ progname, WalSegSz);
+ }
+ else
+ {
+ /*
+ * Don't complain loudly, this is to be expected for segments being
+ * created.
+ */
+ if (errno != 0)
+ {
+ if (debug)
+ fprintf(stderr, "could not read file \"%s\": %s\n",
+ WALFilePath, strerror(errno));
+ }
+ else
+ {
+ if (debug)
+ fprintf(stderr, "not enough data in file \"%s\"\n",
+ WALFilePath);
+ }
+ }
+
+ fflush(stderr);
+
+ close(fd);
+ pg_free(buf);
+ return ret_val;
+}
+
/*
* CheckForExternalTrigger()
*
@@ -708,8 +810,6 @@ main(int argc, char **argv)
CustomizableInitialize();
- need_cleanup = SetWALFileNameForCleanup();
-
if (debug)
{
fprintf(stderr, "Trigger file: %s\n", triggerPath ? triggerPath : "");
@@ -721,11 +821,6 @@ main(int argc, char **argv)
fprintf(stderr, "Max wait interval: %d %s\n",
maxwaittime, (maxwaittime > 0 ? "seconds" : "forever"));
fprintf(stderr, "Command for restore: %s\n", restoreCommand);
- fprintf(stderr, "Keep archive history: ");
- if (need_cleanup)
- fprintf(stderr, "%s and later\n", exclusiveCleanupFileName);
- else
- fprintf(stderr, "no cleanup required\n");
fflush(stderr);
}
diff --git a/contrib/pg_stat_statements/pg_stat_statements.c b/contrib/pg_stat_statements/pg_stat_statements.c
index fa409d72b7..928673498a 100644
--- a/contrib/pg_stat_statements/pg_stat_statements.c
+++ b/contrib/pg_stat_statements/pg_stat_statements.c
@@ -21,7 +21,7 @@
* as the collations of Vars and, most notably, the values of constants.
*
* This jumble is acquired at the end of parse analysis of each query, and
- * a 32-bit hash of it is stored into the query's Query.queryId field.
+ * a 64-bit hash of it is stored into the query's Query.queryId field.
* The server then copies this value around, making it available in plan
* tree(s) generated from the query. The executor can then use this value
* to blame query costs on the proper queryId.
@@ -48,7 +48,7 @@
* in the file to be read or written while holding only shared lock.
*
*
- * Copyright (c) 2008-2017, PostgreSQL Global Development Group
+ * Copyright (c) 2008-2018, PostgreSQL Global Development Group
*
* IDENTIFICATION
* contrib/pg_stat_statements/pg_stat_statements.c
@@ -95,7 +95,7 @@ PG_MODULE_MAGIC;
#define PGSS_TEXT_FILE PG_STAT_TMP_DIR "/pgss_query_texts.stat"
/* Magic number identifying the stats file format */
-static const uint32 PGSS_FILE_HEADER = 0x20140125;
+static const uint32 PGSS_FILE_HEADER = 0x20171004;
/* PostgreSQL major version number, changes in which invalidate all entries */
static const uint32 PGSS_PG_MAJOR_VERSION = PG_VERSION_NUM / 100;
@@ -125,12 +125,17 @@ typedef enum pgssVersion
/*
* Hashtable key that defines the identity of a hashtable entry. We separate
* queries by user and by database even if they are otherwise identical.
+ *
+ * Right now, this structure contains no padding. If you add any, make sure
+ * to teach pgss_store() to zero the padding bytes. Otherwise, things will
+ * break, because pgss_hash is created using HASH_BLOBS, and thus tag_hash
+ * is used to hash this.
*/
typedef struct pgssHashKey
{
Oid userid; /* user OID */
Oid dbid; /* database OID */
- uint32 queryid; /* query identifier */
+ uint64 queryid; /* query identifier */
} pgssHashKey;
/*
@@ -301,10 +306,8 @@ static void pgss_ProcessUtility(PlannedStmt *pstmt, const char *queryString,
ProcessUtilityContext context, ParamListInfo params,
QueryEnvironment *queryEnv,
DestReceiver *dest, char *completionTag);
-static uint32 pgss_hash_fn(const void *key, Size keysize);
-static int pgss_match_fn(const void *key1, const void *key2, Size keysize);
-static uint32 pgss_hash_string(const char *str, int len);
-static void pgss_store(const char *query, uint32 queryId,
+static uint64 pgss_hash_string(const char *str, int len);
+static void pgss_store(const char *query, uint64 queryId,
int query_location, int query_len,
double total_time, uint64 rows,
const BufferUsage *bufusage,
@@ -500,12 +503,10 @@ pgss_shmem_startup(void)
memset(&info, 0, sizeof(info));
info.keysize = sizeof(pgssHashKey);
info.entrysize = sizeof(pgssEntry);
- info.hash = pgss_hash_fn;
- info.match = pgss_match_fn;
pgss_hash = ShmemInitHash("pg_stat_statements hash",
pgss_max, pgss_max,
&info,
- HASH_ELEM | HASH_FUNCTION | HASH_COMPARE);
+ HASH_ELEM | HASH_BLOBS);
LWLockRelease(AddinShmemInitLock);
@@ -781,7 +782,7 @@ pgss_post_parse_analyze(ParseState *pstate, Query *query)
prev_post_parse_analyze_hook(pstate, query);
/* Assert we didn't do this already */
- Assert(query->queryId == 0);
+ Assert(query->queryId == UINT64CONST(0));
/* Safety check... */
if (!pgss || !pgss_hash)
@@ -797,7 +798,7 @@ pgss_post_parse_analyze(ParseState *pstate, Query *query)
*/
if (query->utilityStmt)
{
- query->queryId = 0;
+ query->queryId = UINT64CONST(0);
return;
}
@@ -812,14 +813,15 @@ pgss_post_parse_analyze(ParseState *pstate, Query *query)
/* Compute query ID and mark the Query node with it */
JumbleQuery(&jstate, query);
- query->queryId = hash_any(jstate.jumble, jstate.jumble_len);
+ query->queryId =
+ DatumGetUInt64(hash_any_extended(jstate.jumble, jstate.jumble_len, 0));
/*
* If we are unlucky enough to get a hash of zero, use 1 instead, to
* prevent confusion with the utility-statement case.
*/
- if (query->queryId == 0)
- query->queryId = 1;
+ if (query->queryId == UINT64CONST(0))
+ query->queryId = UINT64CONST(1);
/*
* If we were able to identify any ignorable constants, we immediately
@@ -855,7 +857,7 @@ pgss_ExecutorStart(QueryDesc *queryDesc, int eflags)
* counting of optimizable statements that are directly contained in
* utility statements.
*/
- if (pgss_enabled() && queryDesc->plannedstmt->queryId != 0)
+ if (pgss_enabled() && queryDesc->plannedstmt->queryId != UINT64CONST(0))
{
/*
* Set up to track total elapsed time in ExecutorRun. Make sure the
@@ -926,9 +928,9 @@ pgss_ExecutorFinish(QueryDesc *queryDesc)
static void
pgss_ExecutorEnd(QueryDesc *queryDesc)
{
- uint32 queryId = queryDesc->plannedstmt->queryId;
+ uint64 queryId = queryDesc->plannedstmt->queryId;
- if (queryId != 0 && queryDesc->totaltime && pgss_enabled())
+ if (queryId != UINT64CONST(0) && queryDesc->totaltime && pgss_enabled())
{
/*
* Make sure stats accumulation is done. (Note: it's okay if several
@@ -1069,45 +1071,16 @@ pgss_ProcessUtility(PlannedStmt *pstmt, const char *queryString,
}
}
-/*
- * Calculate hash value for a key
- */
-static uint32
-pgss_hash_fn(const void *key, Size keysize)
-{
- const pgssHashKey *k = (const pgssHashKey *) key;
-
- return hash_uint32((uint32) k->userid) ^
- hash_uint32((uint32) k->dbid) ^
- hash_uint32((uint32) k->queryid);
-}
-
-/*
- * Compare two keys - zero means match
- */
-static int
-pgss_match_fn(const void *key1, const void *key2, Size keysize)
-{
- const pgssHashKey *k1 = (const pgssHashKey *) key1;
- const pgssHashKey *k2 = (const pgssHashKey *) key2;
-
- if (k1->userid == k2->userid &&
- k1->dbid == k2->dbid &&
- k1->queryid == k2->queryid)
- return 0;
- else
- return 1;
-}
-
/*
* Given an arbitrarily long query string, produce a hash for the purposes of
* identifying the query, without normalizing constants. Used when hashing
* utility statements.
*/
-static uint32
+static uint64
pgss_hash_string(const char *str, int len)
{
- return hash_any((const unsigned char *) str, len);
+ return DatumGetUInt64(hash_any_extended((const unsigned char *) str,
+ len, 0));
}
/*
@@ -1121,7 +1094,7 @@ pgss_hash_string(const char *str, int len)
* query string. total_time, rows, bufusage are ignored in this case.
*/
static void
-pgss_store(const char *query, uint32 queryId,
+pgss_store(const char *query, uint64 queryId,
int query_location, int query_len,
double total_time, uint64 rows,
const BufferUsage *bufusage,
@@ -1173,7 +1146,7 @@ pgss_store(const char *query, uint32 queryId,
/*
* For utility statements, we just hash the query string to get an ID.
*/
- if (queryId == 0)
+ if (queryId == UINT64CONST(0))
queryId = pgss_hash_string(query, query_len);
/* Set up key for hashtable search */
@@ -1869,8 +1842,7 @@ qtext_store(const char *query, int query_len,
*query_offset = off;
/* Now write the data into the successfully-reserved part of the file */
- fd = OpenTransientFile(PGSS_TEXT_FILE, O_RDWR | O_CREAT | PG_BINARY,
- S_IRUSR | S_IWUSR);
+ fd = OpenTransientFile(PGSS_TEXT_FILE, O_RDWR | O_CREAT | PG_BINARY);
if (fd < 0)
goto error;
@@ -1934,7 +1906,7 @@ qtext_load_file(Size *buffer_size)
int fd;
struct stat stat;
- fd = OpenTransientFile(PGSS_TEXT_FILE, O_RDONLY | PG_BINARY, 0);
+ fd = OpenTransientFile(PGSS_TEXT_FILE, O_RDONLY | PG_BINARY);
if (fd < 0)
{
if (errno != ENOENT)
@@ -2325,8 +2297,10 @@ AppendJumble(pgssJumbleState *jstate, const unsigned char *item, Size size)
if (jumble_len >= JUMBLE_SIZE)
{
- uint32 start_hash = hash_any(jumble, JUMBLE_SIZE);
+ uint64 start_hash;
+ start_hash = DatumGetUInt64(hash_any_extended(jumble,
+ JUMBLE_SIZE, 0));
memcpy(jumble, &start_hash, sizeof(start_hash));
jumble_len = sizeof(start_hash);
}
@@ -2631,6 +2605,7 @@ JumbleExpr(pgssJumbleState *jstate, Node *node)
APP_JUMB(acexpr->resulttype);
JumbleExpr(jstate, (Node *) acexpr->arg);
+ JumbleExpr(jstate, (Node *) acexpr->elemexpr);
}
break;
case T_ConvertRowtypeExpr:
diff --git a/contrib/pg_trgm/expected/pg_trgm.out b/contrib/pg_trgm/expected/pg_trgm.out
index c3304b0ceb..6efc54356a 100644
--- a/contrib/pg_trgm/expected/pg_trgm.out
+++ b/contrib/pg_trgm/expected/pg_trgm.out
@@ -7,6 +7,9 @@ WHERE opc.oid >= 16384 AND NOT amvalidate(opc.oid);
--------+---------
(0 rows)
+--backslash is used in tests below, installcheck will fail if
+--standard_conforming_string is off
+set standard_conforming_strings=on;
select show_trgm('');
show_trgm
-----------
diff --git a/contrib/pg_trgm/sql/pg_trgm.sql b/contrib/pg_trgm/sql/pg_trgm.sql
index fe8d0a7495..96ae542320 100644
--- a/contrib/pg_trgm/sql/pg_trgm.sql
+++ b/contrib/pg_trgm/sql/pg_trgm.sql
@@ -5,6 +5,10 @@ SELECT amname, opcname
FROM pg_opclass opc LEFT JOIN pg_am am ON am.oid = opcmethod
WHERE opc.oid >= 16384 AND NOT amvalidate(opc.oid);
+--backslash is used in tests below, installcheck will fail if
+--standard_conforming_string is off
+set standard_conforming_strings=on;
+
select show_trgm('');
select show_trgm('(*&^$@%@');
select show_trgm('a b c');
diff --git a/contrib/pg_trgm/trgm_gist.c b/contrib/pg_trgm/trgm_gist.c
index ed02af875c..e55dc19a65 100644
--- a/contrib/pg_trgm/trgm_gist.c
+++ b/contrib/pg_trgm/trgm_gist.c
@@ -106,7 +106,7 @@ gtrgm_compress(PG_FUNCTION_ARGS)
retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
gistentryinit(*retval, PointerGetDatum(res),
entry->rel, entry->page,
- entry->offset, FALSE);
+ entry->offset, false);
}
else if (ISSIGNKEY(DatumGetPointer(entry->key)) &&
!ISALLTRUE(DatumGetPointer(entry->key)))
@@ -130,7 +130,7 @@ gtrgm_compress(PG_FUNCTION_ARGS)
retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
gistentryinit(*retval, PointerGetDatum(res),
entry->rel, entry->page,
- entry->offset, FALSE);
+ entry->offset, false);
}
PG_RETURN_POINTER(retval);
}
diff --git a/contrib/pg_trgm/trgm_regexp.c b/contrib/pg_trgm/trgm_regexp.c
index 1d474e2aac..547e7c094f 100644
--- a/contrib/pg_trgm/trgm_regexp.c
+++ b/contrib/pg_trgm/trgm_regexp.c
@@ -181,7 +181,7 @@
* 7) Mark state 3 final because state 5 of source NFA is marked as final.
*
*
- * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
@@ -634,7 +634,7 @@ createTrgmNFAInternal(regex_t *regex, TrgmPackedGraph **graph,
* Main entry point for evaluating a graph during index scanning.
*
* The check[] array is indexed by trigram number (in the array of simple
- * trigrams returned by createTrgmNFA), and holds TRUE for those trigrams
+ * trigrams returned by createTrgmNFA), and holds true for those trigrams
* that are present in the index entry being checked.
*/
bool
@@ -1451,7 +1451,7 @@ prefixContains(TrgmPrefix *prefix1, TrgmPrefix *prefix2)
* Get vector of all color trigrams in graph and select which of them
* to expand into simple trigrams.
*
- * Returns TRUE if OK, FALSE if exhausted resource limits.
+ * Returns true if OK, false if exhausted resource limits.
*/
static bool
selectColorTrigrams(TrgmNFA *trgmNFA)
diff --git a/contrib/pg_visibility/pg_visibility.c b/contrib/pg_visibility/pg_visibility.c
index 2cc9575d9f..944dea66fc 100644
--- a/contrib/pg_visibility/pg_visibility.c
+++ b/contrib/pg_visibility/pg_visibility.c
@@ -3,7 +3,7 @@
* pg_visibility.c
* display visibility map information and page-level visibility bits
*
- * Copyright (c) 2016-2017, PostgreSQL Global Development Group
+ * Copyright (c) 2016-2018, PostgreSQL Global Development Group
*
* contrib/pg_visibility/pg_visibility.c
*-------------------------------------------------------------------------
diff --git a/contrib/pgcrypto/crypt-des.c b/contrib/pgcrypto/crypt-des.c
index 60bdbb0c91..ed07fc4606 100644
--- a/contrib/pgcrypto/crypt-des.c
+++ b/contrib/pgcrypto/crypt-des.c
@@ -62,13 +62,10 @@
#include "postgres.h"
#include "miscadmin.h"
+#include "port/pg_bswap.h"
#include "px-crypt.h"
-/* for ntohl/htonl */
-#include
-#include
-
#define _PASSWORD_EFMT1 '_'
static const char _crypt_a64[] =
@@ -206,18 +203,18 @@ static inline int
ascii_to_bin(char ch)
{
if (ch > 'z')
- return (0);
+ return 0;
if (ch >= 'a')
return (ch - 'a' + 38);
if (ch > 'Z')
- return (0);
+ return 0;
if (ch >= 'A')
return (ch - 'A' + 12);
if (ch > '9')
- return (0);
+ return 0;
if (ch >= '.')
return (ch - '.');
- return (0);
+ return 0;
}
static void
@@ -408,8 +405,8 @@ des_setkey(const char *key)
if (!des_initialised)
des_init();
- rawkey0 = ntohl(*(const uint32 *) key);
- rawkey1 = ntohl(*(const uint32 *) (key + 4));
+ rawkey0 = pg_ntoh32(*(const uint32 *) key);
+ rawkey1 = pg_ntoh32(*(const uint32 *) (key + 4));
if ((rawkey0 | rawkey1)
&& rawkey0 == old_rawkey0
@@ -420,7 +417,7 @@ des_setkey(const char *key)
* (which is weak and has bad parity anyway) in order to simplify the
* starting conditions.
*/
- return (0);
+ return 0;
}
old_rawkey0 = rawkey0;
old_rawkey1 = rawkey1;
@@ -479,7 +476,7 @@ des_setkey(const char *key)
| comp_maskr[6][(t1 >> 7) & 0x7f]
| comp_maskr[7][t1 & 0x7f];
}
- return (0);
+ return 0;
}
static int
@@ -500,7 +497,7 @@ do_des(uint32 l_in, uint32 r_in, uint32 *l_out, uint32 *r_out, int count)
int round;
if (count == 0)
- return (1);
+ return 1;
else if (count > 0)
{
/*
@@ -613,7 +610,7 @@ do_des(uint32 l_in, uint32 r_in, uint32 *l_out, uint32 *r_out, int count)
| fp_maskr[5][(r >> 16) & 0xff]
| fp_maskr[6][(r >> 8) & 0xff]
| fp_maskr[7][r & 0xff];
- return (0);
+ return 0;
}
static int
@@ -634,20 +631,20 @@ des_cipher(const char *in, char *out, long salt, int count)
/* copy data to avoid assuming input is word-aligned */
memcpy(buffer, in, sizeof(buffer));
- rawl = ntohl(buffer[0]);
- rawr = ntohl(buffer[1]);
+ rawl = pg_ntoh32(buffer[0]);
+ rawr = pg_ntoh32(buffer[1]);
retval = do_des(rawl, rawr, &l_out, &r_out, count);
if (retval)
- return (retval);
+ return retval;
- buffer[0] = htonl(l_out);
- buffer[1] = htonl(r_out);
+ buffer[0] = pg_hton32(l_out);
+ buffer[1] = pg_hton32(r_out);
/* copy data to avoid assuming output is word-aligned */
memcpy(out, buffer, sizeof(buffer));
- return (retval);
+ return retval;
}
char *
@@ -680,7 +677,7 @@ px_crypt_des(const char *key, const char *setting)
key++;
}
if (des_setkey((char *) keybuf))
- return (NULL);
+ return NULL;
#ifndef DISABLE_XDES
if (*setting == _PASSWORD_EFMT1)
@@ -711,7 +708,7 @@ px_crypt_des(const char *key, const char *setting)
* Encrypt the key with itself.
*/
if (des_cipher((char *) keybuf, (char *) keybuf, 0L, 1))
- return (NULL);
+ return NULL;
/*
* And XOR with the next 8 characters of the key.
@@ -721,7 +718,7 @@ px_crypt_des(const char *key, const char *setting)
*q++ ^= *key++ << 1;
if (des_setkey((char *) keybuf))
- return (NULL);
+ return NULL;
}
StrNCpy(output, setting, 10);
@@ -767,7 +764,7 @@ px_crypt_des(const char *key, const char *setting)
* Do it.
*/
if (do_des(0L, 0L, &r0, &r1, count))
- return (NULL);
+ return NULL;
/*
* Now encode the result...
@@ -790,5 +787,5 @@ px_crypt_des(const char *key, const char *setting)
*p++ = _crypt_a64[l & 0x3f];
*p = 0;
- return (output);
+ return output;
}
diff --git a/contrib/pgcrypto/expected/rijndael.out b/contrib/pgcrypto/expected/rijndael.out
index 14b2650c32..5366604a3d 100644
--- a/contrib/pgcrypto/expected/rijndael.out
+++ b/contrib/pgcrypto/expected/rijndael.out
@@ -1,5 +1,5 @@
--
--- AES / Rijndael-128 cipher
+-- AES cipher (aka Rijndael-128, -192, or -256)
--
-- ensure consistent test output regardless of the default bytea format
SET bytea_output TO escape;
diff --git a/contrib/pgcrypto/pgcrypto.c b/contrib/pgcrypto/pgcrypto.c
index e09f3378da..de09ececcf 100644
--- a/contrib/pgcrypto/pgcrypto.c
+++ b/contrib/pgcrypto/pgcrypto.c
@@ -47,7 +47,7 @@ PG_MODULE_MAGIC;
/* private stuff */
typedef int (*PFN) (const char *name, void **res);
-static void *find_provider(text *name, PFN pf, char *desc, int silent);
+static void *find_provider(text *name, PFN pf, const char *desc, int silent);
/* SQL function: hash(bytea, text) returns bytea */
PG_FUNCTION_INFO_V1(pg_digest);
@@ -474,7 +474,7 @@ pg_random_uuid(PG_FUNCTION_ARGS)
static void *
find_provider(text *name,
PFN provider_lookup,
- char *desc, int silent)
+ const char *desc, int silent)
{
void *res;
char *buf;
diff --git a/contrib/pgcrypto/sql/rijndael.sql b/contrib/pgcrypto/sql/rijndael.sql
index bfbf95d39b..a9bcbf33d0 100644
--- a/contrib/pgcrypto/sql/rijndael.sql
+++ b/contrib/pgcrypto/sql/rijndael.sql
@@ -1,5 +1,5 @@
--
--- AES / Rijndael-128 cipher
+-- AES cipher (aka Rijndael-128, -192, or -256)
--
-- ensure consistent test output regardless of the default bytea format
SET bytea_output TO escape;
diff --git a/contrib/pgrowlocks/pgrowlocks.c b/contrib/pgrowlocks/pgrowlocks.c
index eabca65bd2..94e051d642 100644
--- a/contrib/pgrowlocks/pgrowlocks.c
+++ b/contrib/pgrowlocks/pgrowlocks.c
@@ -121,7 +121,7 @@ pgrowlocks(PG_FUNCTION_ARGS)
aclresult = is_member_of_role(GetUserId(), DEFAULT_ROLE_STAT_SCAN_TABLES) ? ACLCHECK_OK : ACLCHECK_NO_PRIV;
if (aclresult != ACLCHECK_OK)
- aclcheck_error(aclresult, ACL_KIND_CLASS,
+ aclcheck_error(aclresult, get_relkind_objtype(rel->rd_rel->relkind),
RelationGetRelationName(rel));
scan = heap_beginscan(rel, GetActiveSnapshot(), 0, NULL);
diff --git a/contrib/pgstattuple/pgstatapprox.c b/contrib/pgstattuple/pgstatapprox.c
index 5bf06138a5..3cfbc08649 100644
--- a/contrib/pgstattuple/pgstatapprox.c
+++ b/contrib/pgstattuple/pgstatapprox.c
@@ -3,7 +3,7 @@
* pgstatapprox.c
* Bloat estimation functions
*
- * Copyright (c) 2014-2017, PostgreSQL Global Development Group
+ * Copyright (c) 2014-2018, PostgreSQL Global Development Group
*
* IDENTIFICATION
* contrib/pgstattuple/pgstatapprox.c
diff --git a/contrib/pgstattuple/pgstatindex.c b/contrib/pgstattuple/pgstatindex.c
index 9365ba7e02..75317b96a2 100644
--- a/contrib/pgstattuple/pgstatindex.c
+++ b/contrib/pgstattuple/pgstatindex.c
@@ -568,7 +568,7 @@ pgstatginindex_internal(Oid relid, FunctionCallInfo fcinfo)
tuple = heap_form_tuple(tupleDesc, values, nulls);
result = HeapTupleGetDatum(tuple);
- return (result);
+ return result;
}
/* ------------------------------------------------------
diff --git a/contrib/pgstattuple/pgstattuple.c b/contrib/pgstattuple/pgstattuple.c
index 7a91cc3468..7ca1bb24d2 100644
--- a/contrib/pgstattuple/pgstattuple.c
+++ b/contrib/pgstattuple/pgstattuple.c
@@ -416,7 +416,7 @@ pgstat_btree_page(pgstattuple_type *stat, Relation rel, BlockNumber blkno,
BTPageOpaque opaque;
opaque = (BTPageOpaque) PageGetSpecialPointer(page);
- if (opaque->btpo_flags & (BTP_DELETED | BTP_HALF_DEAD))
+ if (P_IGNORE(opaque))
{
/* recyclable page */
stat->free_space += BLCKSZ;
diff --git a/contrib/postgres_fdw/connection.c b/contrib/postgres_fdw/connection.c
index be4ec07cf9..00c926b983 100644
--- a/contrib/postgres_fdw/connection.c
+++ b/contrib/postgres_fdw/connection.c
@@ -3,7 +3,7 @@
* connection.c
* Connection management functions for postgres_fdw
*
- * Portions Copyright (c) 2012-2017, PostgreSQL Global Development Group
+ * Portions Copyright (c) 2012-2018, PostgreSQL Global Development Group
*
* IDENTIFICATION
* contrib/postgres_fdw/connection.c
@@ -75,7 +75,7 @@ static bool xact_got_connection = false;
/* prototypes of private functions */
static PGconn *connect_pg_server(ForeignServer *server, UserMapping *user);
static void disconnect_pg_server(ConnCacheEntry *entry);
-static void check_conn_params(const char **keywords, const char **values);
+static void check_conn_params(const char **keywords, const char **values, UserMapping *user);
static void configure_remote_session(PGconn *conn);
static void do_sql_command(PGconn *conn, const char *sql);
static void begin_remote_xact(ConnCacheEntry *entry);
@@ -261,7 +261,7 @@ connect_pg_server(ForeignServer *server, UserMapping *user)
keywords[n] = values[n] = NULL;
/* verify connection parameters and make connection */
- check_conn_params(keywords, values);
+ check_conn_params(keywords, values, user);
conn = PQconnectdbParams(keywords, values, false);
if (!conn || PQstatus(conn) != CONNECTION_OK)
@@ -276,7 +276,7 @@ connect_pg_server(ForeignServer *server, UserMapping *user)
* otherwise, he's piggybacking on the postgres server's user
* identity. See also dblink_security_check() in contrib/dblink.
*/
- if (!superuser() && !PQconnectionUsedPassword(conn))
+ if (!superuser_arg(user->userid) && !PQconnectionUsedPassword(conn))
ereport(ERROR,
(errcode(ERRCODE_S_R_E_PROHIBITED_SQL_STATEMENT_ATTEMPTED),
errmsg("password is required"),
@@ -322,12 +322,12 @@ disconnect_pg_server(ConnCacheEntry *entry)
* contrib/dblink.)
*/
static void
-check_conn_params(const char **keywords, const char **values)
+check_conn_params(const char **keywords, const char **values, UserMapping *user)
{
int i;
/* no check required if superuser */
- if (superuser())
+ if (superuser_arg(user->userid))
return;
/* ok if params contain a non-empty password */
diff --git a/contrib/postgres_fdw/deparse.c b/contrib/postgres_fdw/deparse.c
index 285cf1b2ee..8cd5843885 100644
--- a/contrib/postgres_fdw/deparse.c
+++ b/contrib/postgres_fdw/deparse.c
@@ -24,7 +24,7 @@
* with collations that match the remote table's columns, which we can
* consider to be user error.
*
- * Portions Copyright (c) 2012-2017, PostgreSQL Global Development Group
+ * Portions Copyright (c) 2012-2018, PostgreSQL Global Development Group
*
* IDENTIFICATION
* contrib/postgres_fdw/deparse.c
@@ -132,7 +132,9 @@ static void deparseTargetList(StringInfo buf,
Bitmapset *attrs_used,
bool qualify_col,
List **retrieved_attrs);
-static void deparseExplicitTargetList(List *tlist, List **retrieved_attrs,
+static void deparseExplicitTargetList(List *tlist,
+ bool is_returning,
+ List **retrieved_attrs,
deparse_expr_cxt *context);
static void deparseSubqueryTargetList(deparse_expr_cxt *context);
static void deparseReturningList(StringInfo buf, PlannerInfo *root,
@@ -168,17 +170,19 @@ static void deparseLockingClause(deparse_expr_cxt *context);
static void appendOrderByClause(List *pathkeys, deparse_expr_cxt *context);
static void appendConditions(List *exprs, deparse_expr_cxt *context);
static void deparseFromExprForRel(StringInfo buf, PlannerInfo *root,
- RelOptInfo *joinrel, bool use_alias, List **params_list);
+ RelOptInfo *foreignrel, bool use_alias,
+ Index ignore_rel, List **ignore_conds,
+ List **params_list);
static void deparseFromExpr(List *quals, deparse_expr_cxt *context);
static void deparseRangeTblRef(StringInfo buf, PlannerInfo *root,
RelOptInfo *foreignrel, bool make_subquery,
- List **params_list);
+ Index ignore_rel, List **ignore_conds, List **params_list);
static void deparseAggref(Aggref *node, deparse_expr_cxt *context);
static void appendGroupByClause(List *tlist, deparse_expr_cxt *context);
static void appendAggOrderBy(List *orderList, List *targetList,
deparse_expr_cxt *context);
static void appendFunctionName(Oid funcid, deparse_expr_cxt *context);
-static Node *deparseSortGroupClause(Index ref, List *tlist,
+static Node *deparseSortGroupClause(Index ref, List *tlist, bool force_colno,
deparse_expr_cxt *context);
/*
@@ -850,10 +854,12 @@ foreign_expr_walker(Node *node,
static char *
deparse_type_name(Oid type_oid, int32 typemod)
{
- if (is_builtin(type_oid))
- return format_type_with_typemod(type_oid, typemod);
- else
- return format_type_with_typemod_qualified(type_oid, typemod);
+ uint8 flags = FORMAT_TYPE_TYPEMOD_GIVEN;
+
+ if (!is_builtin(type_oid))
+ flags |= FORMAT_TYPE_FORCE_QUALIFY;
+
+ return format_type_extended(type_oid, typemod, flags);
}
/*
@@ -921,7 +927,7 @@ build_tlist_to_deparse(RelOptInfo *foreignrel)
*
* List of columns selected is returned in retrieved_attrs.
*/
-extern void
+void
deparseSelectStmtForRel(StringInfo buf, PlannerInfo *root, RelOptInfo *rel,
List *tlist, List *remote_conds, List *pathkeys,
bool is_subquery, List **retrieved_attrs,
@@ -1028,7 +1034,7 @@ deparseSelectSql(List *tlist, bool is_subquery, List **retrieved_attrs,
* For a join or upper relation the input tlist gives the list of
* columns required to be fetched from the foreign server.
*/
- deparseExplicitTargetList(tlist, retrieved_attrs, context);
+ deparseExplicitTargetList(tlist, false, retrieved_attrs, context);
}
else
{
@@ -1071,7 +1077,7 @@ deparseFromExpr(List *quals, deparse_expr_cxt *context)
appendStringInfoString(buf, " FROM ");
deparseFromExprForRel(buf, context->root, scanrel,
(bms_num_members(scanrel->relids) > 1),
- context->params_list);
+ (Index) 0, NULL, context->params_list);
/* Construct WHERE clause */
if (quals != NIL)
@@ -1115,7 +1121,7 @@ deparseTargetList(StringInfo buf,
first = true;
for (i = 1; i <= tupdesc->natts; i++)
{
- Form_pg_attribute attr = tupdesc->attrs[i - 1];
+ Form_pg_attribute attr = TupleDescAttr(tupdesc, i - 1);
/* Ignore dropped attributes. */
if (attr->attisdropped)
@@ -1307,7 +1313,7 @@ appendConditions(List *exprs, deparse_expr_cxt *context)
}
/* Output join name for given join type */
-extern const char *
+const char *
get_jointype_name(JoinType jointype)
{
switch (jointype)
@@ -1340,9 +1346,14 @@ get_jointype_name(JoinType jointype)
*
* retrieved_attrs is the list of continuously increasing integers starting
* from 1. It has same number of entries as tlist.
+ *
+ * This is used for both SELECT and RETURNING targetlists; the is_returning
+ * parameter is true only for a RETURNING targetlist.
*/
static void
-deparseExplicitTargetList(List *tlist, List **retrieved_attrs,
+deparseExplicitTargetList(List *tlist,
+ bool is_returning,
+ List **retrieved_attrs,
deparse_expr_cxt *context)
{
ListCell *lc;
@@ -1357,13 +1368,16 @@ deparseExplicitTargetList(List *tlist, List **retrieved_attrs,
if (i > 0)
appendStringInfoString(buf, ", ");
+ else if (is_returning)
+ appendStringInfoString(buf, " RETURNING ");
+
deparseExpr((Expr *) tle->expr, context);
*retrieved_attrs = lappend_int(*retrieved_attrs, i + 1);
i++;
}
- if (i == 0)
+ if (i == 0 && !is_returning)
appendStringInfoString(buf, "NULL");
}
@@ -1406,10 +1420,17 @@ deparseSubqueryTargetList(deparse_expr_cxt *context)
* The function constructs ... JOIN ... ON ... for join relation. For a base
* relation it just returns schema-qualified tablename, with the appropriate
* alias if so requested.
+ *
+ * 'ignore_rel' is either zero or the RT index of a target relation. In the
+ * latter case the function constructs FROM clause of UPDATE or USING clause
+ * of DELETE; it deparses the join relation as if the relation never contained
+ * the target relation, and creates a List of conditions to be deparsed into
+ * the top-level WHERE clause, which is returned to *ignore_conds.
*/
static void
deparseFromExprForRel(StringInfo buf, PlannerInfo *root, RelOptInfo *foreignrel,
- bool use_alias, List **params_list)
+ bool use_alias, Index ignore_rel, List **ignore_conds,
+ List **params_list)
{
PgFdwRelationInfo *fpinfo = (PgFdwRelationInfo *) foreignrel->fdw_private;
@@ -1417,16 +1438,89 @@ deparseFromExprForRel(StringInfo buf, PlannerInfo *root, RelOptInfo *foreignrel,
{
StringInfoData join_sql_o;
StringInfoData join_sql_i;
+ RelOptInfo *outerrel = fpinfo->outerrel;
+ RelOptInfo *innerrel = fpinfo->innerrel;
+ bool outerrel_is_target = false;
+ bool innerrel_is_target = false;
+
+ if (ignore_rel > 0 && bms_is_member(ignore_rel, foreignrel->relids))
+ {
+ /*
+ * If this is an inner join, add joinclauses to *ignore_conds and
+ * set it to empty so that those can be deparsed into the WHERE
+ * clause. Note that since the target relation can never be
+ * within the nullable side of an outer join, those could safely
+ * be pulled up into the WHERE clause (see foreign_join_ok()).
+ * Note also that since the target relation is only inner-joined
+ * to any other relation in the query, all conditions in the join
+ * tree mentioning the target relation could be deparsed into the
+ * WHERE clause by doing this recursively.
+ */
+ if (fpinfo->jointype == JOIN_INNER)
+ {
+ *ignore_conds = list_concat(*ignore_conds,
+ list_copy(fpinfo->joinclauses));
+ fpinfo->joinclauses = NIL;
+ }
+
+ /*
+ * Check if either of the input relations is the target relation.
+ */
+ if (outerrel->relid == ignore_rel)
+ outerrel_is_target = true;
+ else if (innerrel->relid == ignore_rel)
+ innerrel_is_target = true;
+ }
+
+ /* Deparse outer relation if not the target relation. */
+ if (!outerrel_is_target)
+ {
+ initStringInfo(&join_sql_o);
+ deparseRangeTblRef(&join_sql_o, root, outerrel,
+ fpinfo->make_outerrel_subquery,
+ ignore_rel, ignore_conds, params_list);
+
+ /*
+ * If inner relation is the target relation, skip deparsing it.
+ * Note that since the join of the target relation with any other
+ * relation in the query is an inner join and can never be within
+ * the nullable side of an outer join, the join could be
+ * interchanged with higher-level joins (cf. identity 1 on outer
+ * join reordering shown in src/backend/optimizer/README), which
+ * means it's safe to skip the target-relation deparsing here.
+ */
+ if (innerrel_is_target)
+ {
+ Assert(fpinfo->jointype == JOIN_INNER);
+ Assert(fpinfo->joinclauses == NIL);
+ appendStringInfo(buf, "%s", join_sql_o.data);
+ return;
+ }
+ }
+
+ /* Deparse inner relation if not the target relation. */
+ if (!innerrel_is_target)
+ {
+ initStringInfo(&join_sql_i);
+ deparseRangeTblRef(&join_sql_i, root, innerrel,
+ fpinfo->make_innerrel_subquery,
+ ignore_rel, ignore_conds, params_list);
- /* Deparse outer relation */
- initStringInfo(&join_sql_o);
- deparseRangeTblRef(&join_sql_o, root, fpinfo->outerrel,
- fpinfo->make_outerrel_subquery, params_list);
+ /*
+ * If outer relation is the target relation, skip deparsing it.
+ * See the above note about safety.
+ */
+ if (outerrel_is_target)
+ {
+ Assert(fpinfo->jointype == JOIN_INNER);
+ Assert(fpinfo->joinclauses == NIL);
+ appendStringInfo(buf, "%s", join_sql_i.data);
+ return;
+ }
+ }
- /* Deparse inner relation */
- initStringInfo(&join_sql_i);
- deparseRangeTblRef(&join_sql_i, root, fpinfo->innerrel,
- fpinfo->make_innerrel_subquery, params_list);
+ /* Neither of the relations is the target relation. */
+ Assert(!outerrel_is_target && !innerrel_is_target);
/*
* For a join relation FROM clause entry is deparsed as
@@ -1486,7 +1580,8 @@ deparseFromExprForRel(StringInfo buf, PlannerInfo *root, RelOptInfo *foreignrel,
*/
static void
deparseRangeTblRef(StringInfo buf, PlannerInfo *root, RelOptInfo *foreignrel,
- bool make_subquery, List **params_list)
+ bool make_subquery, Index ignore_rel, List **ignore_conds,
+ List **params_list)
{
PgFdwRelationInfo *fpinfo = (PgFdwRelationInfo *) foreignrel->fdw_private;
@@ -1501,6 +1596,14 @@ deparseRangeTblRef(StringInfo buf, PlannerInfo *root, RelOptInfo *foreignrel,
List *retrieved_attrs;
int ncols;
+ /*
+ * The given relation shouldn't contain the target relation, because
+ * this should only happen for input relations for a full join, and
+ * such relations can never contain an UPDATE/DELETE target.
+ */
+ Assert(ignore_rel == 0 ||
+ !bms_is_member(ignore_rel, foreignrel->relids));
+
/* Deparse the subquery representing the relation. */
appendStringInfoChar(buf, '(');
deparseSelectStmtForRel(buf, root, foreignrel, NIL,
@@ -1534,7 +1637,8 @@ deparseRangeTblRef(StringInfo buf, PlannerInfo *root, RelOptInfo *foreignrel,
}
}
else
- deparseFromExprForRel(buf, root, foreignrel, true, params_list);
+ deparseFromExprForRel(buf, root, foreignrel, true, ignore_rel,
+ ignore_conds, params_list);
}
/*
@@ -1645,13 +1749,23 @@ deparseUpdateSql(StringInfo buf, PlannerInfo *root,
/*
* deparse remote UPDATE statement
*
- * The statement text is appended to buf, and we also create an integer List
- * of the columns being retrieved by RETURNING (if any), which is returned
- * to *retrieved_attrs.
+ * 'buf' is the output buffer to append the statement to
+ * 'rtindex' is the RT index of the associated target relation
+ * 'rel' is the relation descriptor for the target relation
+ * 'foreignrel' is the RelOptInfo for the target relation or the join relation
+ * containing all base relations in the query
+ * 'targetlist' is the tlist of the underlying foreign-scan plan node
+ * 'targetAttrs' is the target columns of the UPDATE
+ * 'remote_conds' is the qual clauses that must be evaluated remotely
+ * '*params_list' is an output list of exprs that will become remote Params
+ * 'returningList' is the RETURNING targetlist
+ * '*retrieved_attrs' is an output list of integers of columns being retrieved
+ * by RETURNING (if any)
*/
void
deparseDirectUpdateSql(StringInfo buf, PlannerInfo *root,
Index rtindex, Relation rel,
+ RelOptInfo *foreignrel,
List *targetlist,
List *targetAttrs,
List *remote_conds,
@@ -1659,7 +1773,6 @@ deparseDirectUpdateSql(StringInfo buf, PlannerInfo *root,
List *returningList,
List **retrieved_attrs)
{
- RelOptInfo *baserel = root->simple_rel_array[rtindex];
deparse_expr_cxt context;
int nestlevel;
bool first;
@@ -1667,13 +1780,15 @@ deparseDirectUpdateSql(StringInfo buf, PlannerInfo *root,
/* Set up context struct for recursion */
context.root = root;
- context.foreignrel = baserel;
- context.scanrel = baserel;
+ context.foreignrel = foreignrel;
+ context.scanrel = foreignrel;
context.buf = buf;
context.params_list = params_list;
appendStringInfoString(buf, "UPDATE ");
deparseRelation(buf, rel);
+ if (foreignrel->reloptkind == RELOPT_JOINREL)
+ appendStringInfo(buf, " %s%d", REL_ALIAS_PREFIX, rtindex);
appendStringInfoString(buf, " SET ");
/* Make sure any constants in the exprs are printed portably */
@@ -1700,14 +1815,28 @@ deparseDirectUpdateSql(StringInfo buf, PlannerInfo *root,
reset_transmission_modes(nestlevel);
+ if (foreignrel->reloptkind == RELOPT_JOINREL)
+ {
+ List *ignore_conds = NIL;
+
+ appendStringInfo(buf, " FROM ");
+ deparseFromExprForRel(buf, root, foreignrel, true, rtindex,
+ &ignore_conds, params_list);
+ remote_conds = list_concat(remote_conds, ignore_conds);
+ }
+
if (remote_conds)
{
appendStringInfoString(buf, " WHERE ");
appendConditions(remote_conds, &context);
}
- deparseReturningList(buf, root, rtindex, rel, false,
- returningList, retrieved_attrs);
+ if (foreignrel->reloptkind == RELOPT_JOINREL)
+ deparseExplicitTargetList(returningList, true, retrieved_attrs,
+ &context);
+ else
+ deparseReturningList(buf, root, rtindex, rel, false,
+ returningList, retrieved_attrs);
}
/*
@@ -1735,30 +1864,49 @@ deparseDeleteSql(StringInfo buf, PlannerInfo *root,
/*
* deparse remote DELETE statement
*
- * The statement text is appended to buf, and we also create an integer List
- * of the columns being retrieved by RETURNING (if any), which is returned
- * to *retrieved_attrs.
+ * 'buf' is the output buffer to append the statement to
+ * 'rtindex' is the RT index of the associated target relation
+ * 'rel' is the relation descriptor for the target relation
+ * 'foreignrel' is the RelOptInfo for the target relation or the join relation
+ * containing all base relations in the query
+ * 'remote_conds' is the qual clauses that must be evaluated remotely
+ * '*params_list' is an output list of exprs that will become remote Params
+ * 'returningList' is the RETURNING targetlist
+ * '*retrieved_attrs' is an output list of integers of columns being retrieved
+ * by RETURNING (if any)
*/
void
deparseDirectDeleteSql(StringInfo buf, PlannerInfo *root,
Index rtindex, Relation rel,
+ RelOptInfo *foreignrel,
List *remote_conds,
List **params_list,
List *returningList,
List **retrieved_attrs)
{
- RelOptInfo *baserel = root->simple_rel_array[rtindex];
deparse_expr_cxt context;
/* Set up context struct for recursion */
context.root = root;
- context.foreignrel = baserel;
- context.scanrel = baserel;
+ context.foreignrel = foreignrel;
+ context.scanrel = foreignrel;
context.buf = buf;
context.params_list = params_list;
appendStringInfoString(buf, "DELETE FROM ");
deparseRelation(buf, rel);
+ if (foreignrel->reloptkind == RELOPT_JOINREL)
+ appendStringInfo(buf, " %s%d", REL_ALIAS_PREFIX, rtindex);
+
+ if (foreignrel->reloptkind == RELOPT_JOINREL)
+ {
+ List *ignore_conds = NIL;
+
+ appendStringInfo(buf, " USING ");
+ deparseFromExprForRel(buf, root, foreignrel, true, rtindex,
+ &ignore_conds, params_list);
+ remote_conds = list_concat(remote_conds, ignore_conds);
+ }
if (remote_conds)
{
@@ -1766,8 +1914,12 @@ deparseDirectDeleteSql(StringInfo buf, PlannerInfo *root,
appendConditions(remote_conds, &context);
}
- deparseReturningList(buf, root, rtindex, rel, false,
- returningList, retrieved_attrs);
+ if (foreignrel->reloptkind == RELOPT_JOINREL)
+ deparseExplicitTargetList(returningList, true, retrieved_attrs,
+ &context);
+ else
+ deparseReturningList(buf, root, rtindex, rel, false,
+ returningList, retrieved_attrs);
}
/*
@@ -1851,7 +2003,7 @@ deparseAnalyzeSql(StringInfo buf, Relation rel, List **retrieved_attrs)
for (i = 0; i < tupdesc->natts; i++)
{
/* Ignore dropped columns. */
- if (tupdesc->attrs[i]->attisdropped)
+ if (TupleDescAttr(tupdesc, i)->attisdropped)
continue;
if (!first)
@@ -1859,7 +2011,7 @@ deparseAnalyzeSql(StringInfo buf, Relation rel, List **retrieved_attrs)
first = false;
/* Use attribute name or column_name option. */
- colname = NameStr(tupdesc->attrs[i]->attname);
+ colname = NameStr(TupleDescAttr(tupdesc, i)->attname);
options = GetForeignColumnOptions(relid, i + 1);
foreach(lc, options)
@@ -2026,7 +2178,7 @@ deparseColumnRef(StringInfo buf, int varno, int varattno, PlannerInfo *root,
* FDW option, use attribute name.
*/
if (colname == NULL)
- colname = get_relid_attribute_name(rte->relid, varattno);
+ colname = get_attname(rte->relid, varattno, false);
if (qualify_col)
ADD_REL_QUALIFIER(buf, varno);
@@ -2853,7 +3005,7 @@ appendAggOrderBy(List *orderList, List *targetList, deparse_expr_cxt *context)
first = false;
sortexpr = deparseSortGroupClause(srt->tleSortGroupRef, targetList,
- context);
+ false, context);
sortcoltype = exprType(sortexpr);
/* See whether operator is default < or > for datatype */
typentry = lookup_type_cache(sortcoltype,
@@ -2960,7 +3112,7 @@ appendGroupByClause(List *tlist, deparse_expr_cxt *context)
appendStringInfoString(buf, ", ");
first = false;
- deparseSortGroupClause(grp->tleSortGroupRef, tlist, context);
+ deparseSortGroupClause(grp->tleSortGroupRef, tlist, true, context);
}
}
@@ -3047,7 +3199,8 @@ appendFunctionName(Oid funcid, deparse_expr_cxt *context)
* need not find it again.
*/
static Node *
-deparseSortGroupClause(Index ref, List *tlist, deparse_expr_cxt *context)
+deparseSortGroupClause(Index ref, List *tlist, bool force_colno,
+ deparse_expr_cxt *context)
{
StringInfo buf = context->buf;
TargetEntry *tle;
@@ -3056,7 +3209,13 @@ deparseSortGroupClause(Index ref, List *tlist, deparse_expr_cxt *context)
tle = get_sortgroupref_tle(ref, tlist);
expr = tle->expr;
- if (expr && IsA(expr, Const))
+ if (force_colno)
+ {
+ /* Use column-number form when requested by caller. */
+ Assert(!tle->resjunk);
+ appendStringInfo(buf, "%d", tle->resno);
+ }
+ else if (expr && IsA(expr, Const))
{
/*
* Force a typecast here so that we don't emit something like "GROUP
diff --git a/contrib/postgres_fdw/expected/postgres_fdw.out b/contrib/postgres_fdw/expected/postgres_fdw.out
index c19b3318c7..08b30f83e0 100644
--- a/contrib/postgres_fdw/expected/postgres_fdw.out
+++ b/contrib/postgres_fdw/expected/postgres_fdw.out
@@ -35,6 +35,9 @@ CREATE TABLE "S 1"."T 1" (
c8 user_enum,
CONSTRAINT t1_pkey PRIMARY KEY ("C 1")
);
+-- "S 1"."T 1" will be heavily updated below, so disable autovacuum for
+-- the table to avoid unexpected effects of that
+ALTER TABLE "S 1"."T 1" SET (autovacuum_enabled = 'false');
CREATE TABLE "S 1"."T 2" (
c1 int NOT NULL,
c2 text,
@@ -1371,24 +1374,27 @@ SELECT t1.c1, ss.a, ss.b FROM (SELECT c1 FROM "S 1"."T 3" WHERE c1 = 50) t1 INNE
Output: ft4.c1, ft4.*, ft5.c1, ft5.*
Relations: (public.ft4) FULL JOIN (public.ft5)
Remote SQL: SELECT s8.c1, s8.c2, s9.c1, s9.c2 FROM ((SELECT c1, ROW(c1, c2, c3) FROM "S 1"."T 3" WHERE ((c1 >= 50)) AND ((c1 <= 60))) s8(c1, c2) FULL JOIN (SELECT c1, ROW(c1, c2, c3) FROM "S 1"."T 4" WHERE ((c1 >= 50)) AND ((c1 <= 60))) s9(c1, c2) ON (((s8.c1 = s9.c1)))) WHERE (((s8.c1 IS NULL) OR (s8.c1 IS NOT NULL))) ORDER BY s8.c1 ASC NULLS LAST, s9.c1 ASC NULLS LAST
- -> Hash Full Join
+ -> Sort
Output: ft4.c1, ft4.*, ft5.c1, ft5.*
- Hash Cond: (ft4.c1 = ft5.c1)
- Filter: ((ft4.c1 IS NULL) OR (ft4.c1 IS NOT NULL))
- -> Foreign Scan on public.ft4
- Output: ft4.c1, ft4.*
- Remote SQL: SELECT c1, c2, c3 FROM "S 1"."T 3" WHERE ((c1 >= 50)) AND ((c1 <= 60))
- -> Hash
- Output: ft5.c1, ft5.*
- -> Foreign Scan on public.ft5
+ Sort Key: ft4.c1, ft5.c1
+ -> Hash Full Join
+ Output: ft4.c1, ft4.*, ft5.c1, ft5.*
+ Hash Cond: (ft4.c1 = ft5.c1)
+ Filter: ((ft4.c1 IS NULL) OR (ft4.c1 IS NOT NULL))
+ -> Foreign Scan on public.ft4
+ Output: ft4.c1, ft4.*
+ Remote SQL: SELECT c1, c2, c3 FROM "S 1"."T 3" WHERE ((c1 >= 50)) AND ((c1 <= 60))
+ -> Hash
Output: ft5.c1, ft5.*
- Remote SQL: SELECT c1, c2, c3 FROM "S 1"."T 4" WHERE ((c1 >= 50)) AND ((c1 <= 60))
+ -> Foreign Scan on public.ft5
+ Output: ft5.c1, ft5.*
+ Remote SQL: SELECT c1, c2, c3 FROM "S 1"."T 4" WHERE ((c1 >= 50)) AND ((c1 <= 60))
-> Materialize
Output: "T 3".c1, "T 3".ctid
-> Seq Scan on "S 1"."T 3"
Output: "T 3".c1, "T 3".ctid
Filter: ("T 3".c1 = 50)
-(25 rows)
+(28 rows)
SELECT t1.c1, ss.a, ss.b FROM (SELECT c1 FROM "S 1"."T 3" WHERE c1 = 50) t1 INNER JOIN (SELECT t2.c1, t3.c1 FROM (SELECT c1 FROM ft4 WHERE c1 between 50 and 60) t2 FULL JOIN (SELECT c1 FROM ft5 WHERE c1 between 50 and 60) t3 ON (t2.c1 = t3.c1) WHERE t2.c1 IS NULL OR t2.c1 IS NOT NULL) ss(a, b) ON (TRUE) ORDER BY t1.c1, ss.a, ss.b FOR UPDATE OF t1;
c1 | a | b
@@ -1701,22 +1707,25 @@ SELECT t1.c1, t2.c1 FROM ft1 t1 JOIN ft2 t2 ON (t1.c1 = t2.c1) ORDER BY t1.c3, t
Output: t1.c1, t2.c1, t1.c3, t1.*, t2.*
Relations: (public.ft1 t1) INNER JOIN (public.ft2 t2)
Remote SQL: SELECT r1."C 1", r1.c3, CASE WHEN (r1.*)::text IS NOT NULL THEN ROW(r1."C 1", r1.c2, r1.c3, r1.c4, r1.c5, r1.c6, r1.c7, r1.c8) END, r2."C 1", CASE WHEN (r2.*)::text IS NOT NULL THEN ROW(r2."C 1", r2.c2, r2.c3, r2.c4, r2.c5, r2.c6, r2.c7, r2.c8) END FROM ("S 1"."T 1" r1 INNER JOIN "S 1"."T 1" r2 ON (((r1."C 1" = r2."C 1")))) ORDER BY r1.c3 ASC NULLS LAST, r1."C 1" ASC NULLS LAST FOR UPDATE OF r1
- -> Merge Join
+ -> Sort
Output: t1.c1, t1.c3, t1.*, t2.c1, t2.*
- Merge Cond: (t1.c1 = t2.c1)
- -> Sort
- Output: t1.c1, t1.c3, t1.*
- Sort Key: t1.c1
- -> Foreign Scan on public.ft1 t1
+ Sort Key: t1.c3, t1.c1
+ -> Merge Join
+ Output: t1.c1, t1.c3, t1.*, t2.c1, t2.*
+ Merge Cond: (t1.c1 = t2.c1)
+ -> Sort
Output: t1.c1, t1.c3, t1.*
- Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c7, c8 FROM "S 1"."T 1" FOR UPDATE
- -> Sort
- Output: t2.c1, t2.*
- Sort Key: t2.c1
- -> Foreign Scan on public.ft2 t2
+ Sort Key: t1.c1
+ -> Foreign Scan on public.ft1 t1
+ Output: t1.c1, t1.c3, t1.*
+ Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c7, c8 FROM "S 1"."T 1" FOR UPDATE
+ -> Sort
Output: t2.c1, t2.*
- Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c7, c8 FROM "S 1"."T 1"
-(23 rows)
+ Sort Key: t2.c1
+ -> Foreign Scan on public.ft2 t2
+ Output: t2.c1, t2.*
+ Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c7, c8 FROM "S 1"."T 1"
+(26 rows)
SELECT t1.c1, t2.c1 FROM ft1 t1 JOIN ft2 t2 ON (t1.c1 = t2.c1) ORDER BY t1.c3, t1.c1 OFFSET 100 LIMIT 10 FOR UPDATE OF t1;
c1 | c1
@@ -1745,22 +1754,25 @@ SELECT t1.c1, t2.c1 FROM ft1 t1 JOIN ft2 t2 ON (t1.c1 = t2.c1) ORDER BY t1.c3, t
Output: t1.c1, t2.c1, t1.c3, t1.*, t2.*
Relations: (public.ft1 t1) INNER JOIN (public.ft2 t2)
Remote SQL: SELECT r1."C 1", r1.c3, CASE WHEN (r1.*)::text IS NOT NULL THEN ROW(r1."C 1", r1.c2, r1.c3, r1.c4, r1.c5, r1.c6, r1.c7, r1.c8) END, r2."C 1", CASE WHEN (r2.*)::text IS NOT NULL THEN ROW(r2."C 1", r2.c2, r2.c3, r2.c4, r2.c5, r2.c6, r2.c7, r2.c8) END FROM ("S 1"."T 1" r1 INNER JOIN "S 1"."T 1" r2 ON (((r1."C 1" = r2."C 1")))) ORDER BY r1.c3 ASC NULLS LAST, r1."C 1" ASC NULLS LAST FOR UPDATE OF r1 FOR UPDATE OF r2
- -> Merge Join
+ -> Sort
Output: t1.c1, t1.c3, t1.*, t2.c1, t2.*
- Merge Cond: (t1.c1 = t2.c1)
- -> Sort
- Output: t1.c1, t1.c3, t1.*
- Sort Key: t1.c1
- -> Foreign Scan on public.ft1 t1
+ Sort Key: t1.c3, t1.c1
+ -> Merge Join
+ Output: t1.c1, t1.c3, t1.*, t2.c1, t2.*
+ Merge Cond: (t1.c1 = t2.c1)
+ -> Sort
Output: t1.c1, t1.c3, t1.*
- Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c7, c8 FROM "S 1"."T 1" FOR UPDATE
- -> Sort
- Output: t2.c1, t2.*
- Sort Key: t2.c1
- -> Foreign Scan on public.ft2 t2
+ Sort Key: t1.c1
+ -> Foreign Scan on public.ft1 t1
+ Output: t1.c1, t1.c3, t1.*
+ Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c7, c8 FROM "S 1"."T 1" FOR UPDATE
+ -> Sort
Output: t2.c1, t2.*
- Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c7, c8 FROM "S 1"."T 1" FOR UPDATE
-(23 rows)
+ Sort Key: t2.c1
+ -> Foreign Scan on public.ft2 t2
+ Output: t2.c1, t2.*
+ Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c7, c8 FROM "S 1"."T 1" FOR UPDATE
+(26 rows)
SELECT t1.c1, t2.c1 FROM ft1 t1 JOIN ft2 t2 ON (t1.c1 = t2.c1) ORDER BY t1.c3, t1.c1 OFFSET 100 LIMIT 10 FOR UPDATE;
c1 | c1
@@ -1790,22 +1802,25 @@ SELECT t1.c1, t2.c1 FROM ft1 t1 JOIN ft2 t2 ON (t1.c1 = t2.c1) ORDER BY t1.c3, t
Output: t1.c1, t2.c1, t1.c3, t1.*, t2.*
Relations: (public.ft1 t1) INNER JOIN (public.ft2 t2)
Remote SQL: SELECT r1."C 1", r1.c3, CASE WHEN (r1.*)::text IS NOT NULL THEN ROW(r1."C 1", r1.c2, r1.c3, r1.c4, r1.c5, r1.c6, r1.c7, r1.c8) END, r2."C 1", CASE WHEN (r2.*)::text IS NOT NULL THEN ROW(r2."C 1", r2.c2, r2.c3, r2.c4, r2.c5, r2.c6, r2.c7, r2.c8) END FROM ("S 1"."T 1" r1 INNER JOIN "S 1"."T 1" r2 ON (((r1."C 1" = r2."C 1")))) ORDER BY r1.c3 ASC NULLS LAST, r1."C 1" ASC NULLS LAST FOR SHARE OF r1
- -> Merge Join
+ -> Sort
Output: t1.c1, t1.c3, t1.*, t2.c1, t2.*
- Merge Cond: (t1.c1 = t2.c1)
- -> Sort
- Output: t1.c1, t1.c3, t1.*
- Sort Key: t1.c1
- -> Foreign Scan on public.ft1 t1
+ Sort Key: t1.c3, t1.c1
+ -> Merge Join
+ Output: t1.c1, t1.c3, t1.*, t2.c1, t2.*
+ Merge Cond: (t1.c1 = t2.c1)
+ -> Sort
Output: t1.c1, t1.c3, t1.*
- Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c7, c8 FROM "S 1"."T 1" FOR SHARE
- -> Sort
- Output: t2.c1, t2.*
- Sort Key: t2.c1
- -> Foreign Scan on public.ft2 t2
+ Sort Key: t1.c1
+ -> Foreign Scan on public.ft1 t1
+ Output: t1.c1, t1.c3, t1.*
+ Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c7, c8 FROM "S 1"."T 1" FOR SHARE
+ -> Sort
Output: t2.c1, t2.*
- Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c7, c8 FROM "S 1"."T 1"
-(23 rows)
+ Sort Key: t2.c1
+ -> Foreign Scan on public.ft2 t2
+ Output: t2.c1, t2.*
+ Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c7, c8 FROM "S 1"."T 1"
+(26 rows)
SELECT t1.c1, t2.c1 FROM ft1 t1 JOIN ft2 t2 ON (t1.c1 = t2.c1) ORDER BY t1.c3, t1.c1 OFFSET 100 LIMIT 10 FOR SHARE OF t1;
c1 | c1
@@ -1834,22 +1849,25 @@ SELECT t1.c1, t2.c1 FROM ft1 t1 JOIN ft2 t2 ON (t1.c1 = t2.c1) ORDER BY t1.c3, t
Output: t1.c1, t2.c1, t1.c3, t1.*, t2.*
Relations: (public.ft1 t1) INNER JOIN (public.ft2 t2)
Remote SQL: SELECT r1."C 1", r1.c3, CASE WHEN (r1.*)::text IS NOT NULL THEN ROW(r1."C 1", r1.c2, r1.c3, r1.c4, r1.c5, r1.c6, r1.c7, r1.c8) END, r2."C 1", CASE WHEN (r2.*)::text IS NOT NULL THEN ROW(r2."C 1", r2.c2, r2.c3, r2.c4, r2.c5, r2.c6, r2.c7, r2.c8) END FROM ("S 1"."T 1" r1 INNER JOIN "S 1"."T 1" r2 ON (((r1."C 1" = r2."C 1")))) ORDER BY r1.c3 ASC NULLS LAST, r1."C 1" ASC NULLS LAST FOR SHARE OF r1 FOR SHARE OF r2
- -> Merge Join
+ -> Sort
Output: t1.c1, t1.c3, t1.*, t2.c1, t2.*
- Merge Cond: (t1.c1 = t2.c1)
- -> Sort
- Output: t1.c1, t1.c3, t1.*
- Sort Key: t1.c1
- -> Foreign Scan on public.ft1 t1
+ Sort Key: t1.c3, t1.c1
+ -> Merge Join
+ Output: t1.c1, t1.c3, t1.*, t2.c1, t2.*
+ Merge Cond: (t1.c1 = t2.c1)
+ -> Sort
Output: t1.c1, t1.c3, t1.*
- Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c7, c8 FROM "S 1"."T 1" FOR SHARE
- -> Sort
- Output: t2.c1, t2.*
- Sort Key: t2.c1
- -> Foreign Scan on public.ft2 t2
+ Sort Key: t1.c1
+ -> Foreign Scan on public.ft1 t1
+ Output: t1.c1, t1.c3, t1.*
+ Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c7, c8 FROM "S 1"."T 1" FOR SHARE
+ -> Sort
Output: t2.c1, t2.*
- Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c7, c8 FROM "S 1"."T 1" FOR SHARE
-(23 rows)
+ Sort Key: t2.c1
+ -> Foreign Scan on public.ft2 t2
+ Output: t2.c1, t2.*
+ Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c7, c8 FROM "S 1"."T 1" FOR SHARE
+(26 rows)
SELECT t1.c1, t2.c1 FROM ft1 t1 JOIN ft2 t2 ON (t1.c1 = t2.c1) ORDER BY t1.c3, t1.c1 OFFSET 100 LIMIT 10 FOR SHARE;
c1 | c1
@@ -2314,8 +2332,78 @@ SELECT ft5, ft5.c1, ft5.c2, ft5.c3, ft4.c1, ft4.c2 FROM ft5 left join ft4 on ft5
(30,31,AAA030) | 30 | 31 | AAA030 | 30 | 31
(4 rows)
+-- multi-way join involving multiple merge joins
+-- (this case used to have EPQ-related planning problems)
+SET enable_nestloop TO false;
+SET enable_hashjoin TO false;
+EXPLAIN (VERBOSE, COSTS OFF)
+SELECT * FROM ft1, ft2, ft4, ft5 WHERE ft1.c1 = ft2.c1 AND ft1.c2 = ft4.c1
+ AND ft1.c2 = ft5.c1 AND ft1.c1 < 100 AND ft2.c1 < 100 FOR UPDATE;
+ QUERY PLAN
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ LockRows
+ Output: ft1.c1, ft1.c2, ft1.c3, ft1.c4, ft1.c5, ft1.c6, ft1.c7, ft1.c8, ft2.c1, ft2.c2, ft2.c3, ft2.c4, ft2.c5, ft2.c6, ft2.c7, ft2.c8, ft4.c1, ft4.c2, ft4.c3, ft5.c1, ft5.c2, ft5.c3, ft1.*, ft2.*, ft4.*, ft5.*
+ -> Foreign Scan
+ Output: ft1.c1, ft1.c2, ft1.c3, ft1.c4, ft1.c5, ft1.c6, ft1.c7, ft1.c8, ft2.c1, ft2.c2, ft2.c3, ft2.c4, ft2.c5, ft2.c6, ft2.c7, ft2.c8, ft4.c1, ft4.c2, ft4.c3, ft5.c1, ft5.c2, ft5.c3, ft1.*, ft2.*, ft4.*, ft5.*
+ Relations: (((public.ft1) INNER JOIN (public.ft2)) INNER JOIN (public.ft4)) INNER JOIN (public.ft5)
+ Remote SQL: SELECT r1."C 1", r1.c2, r1.c3, r1.c4, r1.c5, r1.c6, r1.c7, r1.c8, CASE WHEN (r1.*)::text IS NOT NULL THEN ROW(r1."C 1", r1.c2, r1.c3, r1.c4, r1.c5, r1.c6, r1.c7, r1.c8) END, r2."C 1", r2.c2, r2.c3, r2.c4, r2.c5, r2.c6, r2.c7, r2.c8, CASE WHEN (r2.*)::text IS NOT NULL THEN ROW(r2."C 1", r2.c2, r2.c3, r2.c4, r2.c5, r2.c6, r2.c7, r2.c8) END, r3.c1, r3.c2, r3.c3, CASE WHEN (r3.*)::text IS NOT NULL THEN ROW(r3.c1, r3.c2, r3.c3) END, r4.c1, r4.c2, r4.c3, CASE WHEN (r4.*)::text IS NOT NULL THEN ROW(r4.c1, r4.c2, r4.c3) END FROM ((("S 1"."T 1" r1 INNER JOIN "S 1"."T 1" r2 ON (((r1."C 1" = r2."C 1")) AND ((r2."C 1" < 100)) AND ((r1."C 1" < 100)))) INNER JOIN "S 1"."T 3" r3 ON (((r1.c2 = r3.c1)))) INNER JOIN "S 1"."T 4" r4 ON (((r1.c2 = r4.c1)))) FOR UPDATE OF r1 FOR UPDATE OF r2 FOR UPDATE OF r3 FOR UPDATE OF r4
+ -> Merge Join
+ Output: ft1.c1, ft1.c2, ft1.c3, ft1.c4, ft1.c5, ft1.c6, ft1.c7, ft1.c8, ft1.*, ft2.c1, ft2.c2, ft2.c3, ft2.c4, ft2.c5, ft2.c6, ft2.c7, ft2.c8, ft2.*, ft4.c1, ft4.c2, ft4.c3, ft4.*, ft5.c1, ft5.c2, ft5.c3, ft5.*
+ Merge Cond: (ft1.c2 = ft5.c1)
+ -> Merge Join
+ Output: ft1.c1, ft1.c2, ft1.c3, ft1.c4, ft1.c5, ft1.c6, ft1.c7, ft1.c8, ft1.*, ft2.c1, ft2.c2, ft2.c3, ft2.c4, ft2.c5, ft2.c6, ft2.c7, ft2.c8, ft2.*, ft4.c1, ft4.c2, ft4.c3, ft4.*
+ Merge Cond: (ft1.c2 = ft4.c1)
+ -> Sort
+ Output: ft1.c1, ft1.c2, ft1.c3, ft1.c4, ft1.c5, ft1.c6, ft1.c7, ft1.c8, ft1.*, ft2.c1, ft2.c2, ft2.c3, ft2.c4, ft2.c5, ft2.c6, ft2.c7, ft2.c8, ft2.*
+ Sort Key: ft1.c2
+ -> Merge Join
+ Output: ft1.c1, ft1.c2, ft1.c3, ft1.c4, ft1.c5, ft1.c6, ft1.c7, ft1.c8, ft1.*, ft2.c1, ft2.c2, ft2.c3, ft2.c4, ft2.c5, ft2.c6, ft2.c7, ft2.c8, ft2.*
+ Merge Cond: (ft1.c1 = ft2.c1)
+ -> Sort
+ Output: ft1.c1, ft1.c2, ft1.c3, ft1.c4, ft1.c5, ft1.c6, ft1.c7, ft1.c8, ft1.*
+ Sort Key: ft1.c1
+ -> Foreign Scan on public.ft1
+ Output: ft1.c1, ft1.c2, ft1.c3, ft1.c4, ft1.c5, ft1.c6, ft1.c7, ft1.c8, ft1.*
+ Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c7, c8 FROM "S 1"."T 1" WHERE (("C 1" < 100)) FOR UPDATE
+ -> Materialize
+ Output: ft2.c1, ft2.c2, ft2.c3, ft2.c4, ft2.c5, ft2.c6, ft2.c7, ft2.c8, ft2.*
+ -> Foreign Scan on public.ft2
+ Output: ft2.c1, ft2.c2, ft2.c3, ft2.c4, ft2.c5, ft2.c6, ft2.c7, ft2.c8, ft2.*
+ Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c7, c8 FROM "S 1"."T 1" WHERE (("C 1" < 100)) ORDER BY "C 1" ASC NULLS LAST FOR UPDATE
+ -> Sort
+ Output: ft4.c1, ft4.c2, ft4.c3, ft4.*
+ Sort Key: ft4.c1
+ -> Foreign Scan on public.ft4
+ Output: ft4.c1, ft4.c2, ft4.c3, ft4.*
+ Remote SQL: SELECT c1, c2, c3 FROM "S 1"."T 3" FOR UPDATE
+ -> Sort
+ Output: ft5.c1, ft5.c2, ft5.c3, ft5.*
+ Sort Key: ft5.c1
+ -> Foreign Scan on public.ft5
+ Output: ft5.c1, ft5.c2, ft5.c3, ft5.*
+ Remote SQL: SELECT c1, c2, c3 FROM "S 1"."T 4" FOR UPDATE
+(41 rows)
+
+SELECT * FROM ft1, ft2, ft4, ft5 WHERE ft1.c1 = ft2.c1 AND ft1.c2 = ft4.c1
+ AND ft1.c2 = ft5.c1 AND ft1.c1 < 100 AND ft2.c1 < 100 FOR UPDATE;
+ c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8 | c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8 | c1 | c2 | c3 | c1 | c2 | c3
+----+----+-------+------------------------------+--------------------------+----+------------+-----+----+----+-------+------------------------------+--------------------------+----+------------+-----+----+----+--------+----+----+--------
+ 6 | 6 | 00006 | Wed Jan 07 00:00:00 1970 PST | Wed Jan 07 00:00:00 1970 | 6 | 6 | foo | 6 | 6 | 00006 | Wed Jan 07 00:00:00 1970 PST | Wed Jan 07 00:00:00 1970 | 6 | 6 | foo | 6 | 7 | AAA006 | 6 | 7 | AAA006
+ 16 | 6 | 00016 | Sat Jan 17 00:00:00 1970 PST | Sat Jan 17 00:00:00 1970 | 6 | 6 | foo | 16 | 6 | 00016 | Sat Jan 17 00:00:00 1970 PST | Sat Jan 17 00:00:00 1970 | 6 | 6 | foo | 6 | 7 | AAA006 | 6 | 7 | AAA006
+ 26 | 6 | 00026 | Tue Jan 27 00:00:00 1970 PST | Tue Jan 27 00:00:00 1970 | 6 | 6 | foo | 26 | 6 | 00026 | Tue Jan 27 00:00:00 1970 PST | Tue Jan 27 00:00:00 1970 | 6 | 6 | foo | 6 | 7 | AAA006 | 6 | 7 | AAA006
+ 36 | 6 | 00036 | Fri Feb 06 00:00:00 1970 PST | Fri Feb 06 00:00:00 1970 | 6 | 6 | foo | 36 | 6 | 00036 | Fri Feb 06 00:00:00 1970 PST | Fri Feb 06 00:00:00 1970 | 6 | 6 | foo | 6 | 7 | AAA006 | 6 | 7 | AAA006
+ 46 | 6 | 00046 | Mon Feb 16 00:00:00 1970 PST | Mon Feb 16 00:00:00 1970 | 6 | 6 | foo | 46 | 6 | 00046 | Mon Feb 16 00:00:00 1970 PST | Mon Feb 16 00:00:00 1970 | 6 | 6 | foo | 6 | 7 | AAA006 | 6 | 7 | AAA006
+ 56 | 6 | 00056 | Thu Feb 26 00:00:00 1970 PST | Thu Feb 26 00:00:00 1970 | 6 | 6 | foo | 56 | 6 | 00056 | Thu Feb 26 00:00:00 1970 PST | Thu Feb 26 00:00:00 1970 | 6 | 6 | foo | 6 | 7 | AAA006 | 6 | 7 | AAA006
+ 66 | 6 | 00066 | Sun Mar 08 00:00:00 1970 PST | Sun Mar 08 00:00:00 1970 | 6 | 6 | foo | 66 | 6 | 00066 | Sun Mar 08 00:00:00 1970 PST | Sun Mar 08 00:00:00 1970 | 6 | 6 | foo | 6 | 7 | AAA006 | 6 | 7 | AAA006
+ 76 | 6 | 00076 | Wed Mar 18 00:00:00 1970 PST | Wed Mar 18 00:00:00 1970 | 6 | 6 | foo | 76 | 6 | 00076 | Wed Mar 18 00:00:00 1970 PST | Wed Mar 18 00:00:00 1970 | 6 | 6 | foo | 6 | 7 | AAA006 | 6 | 7 | AAA006
+ 86 | 6 | 00086 | Sat Mar 28 00:00:00 1970 PST | Sat Mar 28 00:00:00 1970 | 6 | 6 | foo | 86 | 6 | 00086 | Sat Mar 28 00:00:00 1970 PST | Sat Mar 28 00:00:00 1970 | 6 | 6 | foo | 6 | 7 | AAA006 | 6 | 7 | AAA006
+ 96 | 6 | 00096 | Tue Apr 07 00:00:00 1970 PST | Tue Apr 07 00:00:00 1970 | 6 | 6 | foo | 96 | 6 | 00096 | Tue Apr 07 00:00:00 1970 PST | Tue Apr 07 00:00:00 1970 | 6 | 6 | foo | 6 | 7 | AAA006 | 6 | 7 | AAA006
+(10 rows)
+
+RESET enable_nestloop;
+RESET enable_hashjoin;
-- check join pushdown in situations where multiple userids are involved
-CREATE ROLE regress_view_owner;
+CREATE ROLE regress_view_owner SUPERUSER;
CREATE USER MAPPING FOR regress_view_owner SERVER loopback;
GRANT SELECT ON ft4 TO regress_view_owner;
GRANT SELECT ON ft5 TO regress_view_owner;
@@ -2462,8 +2550,8 @@ DROP ROLE regress_view_owner;
-- Simple aggregates
explain (verbose, costs off)
select count(c6), sum(c1), avg(c1), min(c2), max(c1), stddev(c2), sum(c1) * (random() <= 1)::int as sum2 from ft1 where c2 < 5 group by c2 order by 1, 2;
- QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------------------------------
+ QUERY PLAN
+------------------------------------------------------------------------------------------------------------------------------------------------------
Result
Output: (count(c6)), (sum(c1)), (avg(c1)), (min(c2)), (max(c1)), (stddev(c2)), ((sum(c1)) * ((random() <= '1'::double precision))::integer), c2
-> Sort
@@ -2472,7 +2560,7 @@ select count(c6), sum(c1), avg(c1), min(c2), max(c1), stddev(c2), sum(c1) * (ran
-> Foreign Scan
Output: (count(c6)), (sum(c1)), (avg(c1)), (min(c2)), (max(c1)), (stddev(c2)), c2
Relations: Aggregate on (public.ft1)
- Remote SQL: SELECT count(c6), sum("C 1"), avg("C 1"), min(c2), max("C 1"), stddev(c2), c2 FROM "S 1"."T 1" WHERE ((c2 < 5)) GROUP BY c2
+ Remote SQL: SELECT count(c6), sum("C 1"), avg("C 1"), min(c2), max("C 1"), stddev(c2), c2 FROM "S 1"."T 1" WHERE ((c2 < 5)) GROUP BY 7
(9 rows)
select count(c6), sum(c1), avg(c1), min(c2), max(c1), stddev(c2), sum(c1) * (random() <= 1)::int as sum2 from ft1 where c2 < 5 group by c2 order by 1, 2;
@@ -2531,15 +2619,15 @@ select sum(t1.c1), count(t2.c1) from ft1 t1 inner join ft2 t2 on (t1.c1 = t2.c1)
-- GROUP BY clause having expressions
explain (verbose, costs off)
select c2/2, sum(c2) * (c2/2) from ft1 group by c2/2 order by c2/2;
- QUERY PLAN
-------------------------------------------------------------------------------------------------
+ QUERY PLAN
+---------------------------------------------------------------------------------------
Sort
Output: ((c2 / 2)), ((sum(c2) * (c2 / 2)))
Sort Key: ((ft1.c2 / 2))
-> Foreign Scan
Output: ((c2 / 2)), ((sum(c2) * (c2 / 2)))
Relations: Aggregate on (public.ft1)
- Remote SQL: SELECT (c2 / 2), (sum(c2) * (c2 / 2)) FROM "S 1"."T 1" GROUP BY ((c2 / 2))
+ Remote SQL: SELECT (c2 / 2), (sum(c2) * (c2 / 2)) FROM "S 1"."T 1" GROUP BY 1
(7 rows)
select c2/2, sum(c2) * (c2/2) from ft1 group by c2/2 order by c2/2;
@@ -2555,8 +2643,8 @@ select c2/2, sum(c2) * (c2/2) from ft1 group by c2/2 order by c2/2;
-- Aggregates in subquery are pushed down.
explain (verbose, costs off)
select count(x.a), sum(x.a) from (select c2 a, sum(c1) b from ft1 group by c2, sqrt(c1) order by 1, 2) x;
- QUERY PLAN
-----------------------------------------------------------------------------------------------------------
+ QUERY PLAN
+---------------------------------------------------------------------------------------------
Aggregate
Output: count(ft1.c2), sum(ft1.c2)
-> Sort
@@ -2565,7 +2653,7 @@ select count(x.a), sum(x.a) from (select c2 a, sum(c1) b from ft1 group by c2, s
-> Foreign Scan
Output: ft1.c2, (sum(ft1.c1)), (sqrt((ft1.c1)::double precision))
Relations: Aggregate on (public.ft1)
- Remote SQL: SELECT c2, sum("C 1"), sqrt("C 1") FROM "S 1"."T 1" GROUP BY c2, (sqrt("C 1"))
+ Remote SQL: SELECT c2, sum("C 1"), sqrt("C 1") FROM "S 1"."T 1" GROUP BY 1, 3
(9 rows)
select count(x.a), sum(x.a) from (select c2 a, sum(c1) b from ft1 group by c2, sqrt(c1) order by 1, 2) x;
@@ -2585,7 +2673,7 @@ select c2 * (random() <= 1)::int as sum1, sum(c1) * c2 as sum2 from ft1 group by
-> Foreign Scan
Output: (c2 * ((random() <= '1'::double precision))::integer), ((sum(c1) * c2)), c2
Relations: Aggregate on (public.ft1)
- Remote SQL: SELECT (sum("C 1") * c2), c2 FROM "S 1"."T 1" GROUP BY c2
+ Remote SQL: SELECT (sum("C 1") * c2), c2 FROM "S 1"."T 1" GROUP BY 2
(7 rows)
select c2 * (random() <= 1)::int as sum1, sum(c1) * c2 as sum2 from ft1 group by c2 order by 1, 2;
@@ -2622,15 +2710,15 @@ select c2 * (random() <= 1)::int as c2 from ft2 group by c2 * (random() <= 1)::i
-- GROUP BY clause in various forms, cardinal, alias and constant expression
explain (verbose, costs off)
select count(c2) w, c2 x, 5 y, 7.0 z from ft1 group by 2, y, 9.0::int order by 2;
- QUERY PLAN
-----------------------------------------------------------------------------------------------------------
+ QUERY PLAN
+---------------------------------------------------------------------------------------
Sort
Output: (count(c2)), c2, 5, 7.0, 9
Sort Key: ft1.c2
-> Foreign Scan
Output: (count(c2)), c2, 5, 7.0, 9
Relations: Aggregate on (public.ft1)
- Remote SQL: SELECT count(c2), c2, 5, 7.0, 9 FROM "S 1"."T 1" GROUP BY c2, 5::integer, 9::integer
+ Remote SQL: SELECT count(c2), c2, 5, 7.0, 9 FROM "S 1"."T 1" GROUP BY 2, 3, 5
(7 rows)
select count(c2) w, c2 x, 5 y, 7.0 z from ft1 group by 2, y, 9.0::int order by 2;
@@ -2648,18 +2736,41 @@ select count(c2) w, c2 x, 5 y, 7.0 z from ft1 group by 2, y, 9.0::int order by 2
100 | 9 | 5 | 7.0
(10 rows)
+-- GROUP BY clause referring to same column multiple times
+-- Also, ORDER BY contains an aggregate function
+explain (verbose, costs off)
+select c2, c2 from ft1 where c2 > 6 group by 1, 2 order by sum(c1);
+ QUERY PLAN
+-----------------------------------------------------------------------------------------------
+ Sort
+ Output: c2, c2, (sum(c1))
+ Sort Key: (sum(ft1.c1))
+ -> Foreign Scan
+ Output: c2, c2, (sum(c1))
+ Relations: Aggregate on (public.ft1)
+ Remote SQL: SELECT c2, c2, sum("C 1") FROM "S 1"."T 1" WHERE ((c2 > 6)) GROUP BY 1, 2
+(7 rows)
+
+select c2, c2 from ft1 where c2 > 6 group by 1, 2 order by sum(c1);
+ c2 | c2
+----+----
+ 7 | 7
+ 8 | 8
+ 9 | 9
+(3 rows)
+
-- Testing HAVING clause shippability
explain (verbose, costs off)
select c2, sum(c1) from ft2 group by c2 having avg(c1) < 500 and sum(c1) < 49800 order by c2;
- QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------------
+ QUERY PLAN
+---------------------------------------------------------------------------------------------------------------------------------------
Sort
Output: c2, (sum(c1))
Sort Key: ft2.c2
-> Foreign Scan
Output: c2, (sum(c1))
Relations: Aggregate on (public.ft2)
- Remote SQL: SELECT c2, sum("C 1") FROM "S 1"."T 1" GROUP BY c2 HAVING ((avg("C 1") < 500::numeric)) AND ((sum("C 1") < 49800))
+ Remote SQL: SELECT c2, sum("C 1") FROM "S 1"."T 1" GROUP BY 1 HAVING ((avg("C 1") < 500::numeric)) AND ((sum("C 1") < 49800))
(7 rows)
select c2, sum(c1) from ft2 group by c2 having avg(c1) < 500 and sum(c1) < 49800 order by c2;
@@ -2672,15 +2783,15 @@ select c2, sum(c1) from ft2 group by c2 having avg(c1) < 500 and sum(c1) < 49800
-- Unshippable HAVING clause will be evaluated locally, and other qual in HAVING clause is pushed down
explain (verbose, costs off)
select count(*) from (select c5, count(c1) from ft1 group by c5, sqrt(c2) having (avg(c1) / avg(c1)) * random() <= 1 and avg(c1) < 500) x;
- QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------------------------
+ QUERY PLAN
+---------------------------------------------------------------------------------------------------------------------------------------
Aggregate
Output: count(*)
-> Foreign Scan
Output: ft1.c5, NULL::bigint, (sqrt((ft1.c2)::double precision))
Filter: (((((avg(ft1.c1)) / (avg(ft1.c1))))::double precision * random()) <= '1'::double precision)
Relations: Aggregate on (public.ft1)
- Remote SQL: SELECT c5, NULL::bigint, sqrt(c2), avg("C 1") FROM "S 1"."T 1" GROUP BY c5, (sqrt(c2)) HAVING ((avg("C 1") < 500::numeric))
+ Remote SQL: SELECT c5, NULL::bigint, sqrt(c2), avg("C 1") FROM "S 1"."T 1" GROUP BY 1, 3 HAVING ((avg("C 1") < 500::numeric))
(7 rows)
select count(*) from (select c5, count(c1) from ft1 group by c5, sqrt(c2) having (avg(c1) / avg(c1)) * random() <= 1 and avg(c1) < 500) x;
@@ -2710,15 +2821,15 @@ select sum(c1) from ft1 group by c2 having avg(c1 * (random() <= 1)::int) > 100
-- ORDER BY within aggregate, same column used to order
explain (verbose, costs off)
select array_agg(c1 order by c1) from ft1 where c1 < 100 group by c2 order by 1;
- QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------
+ QUERY PLAN
+---------------------------------------------------------------------------------------------------------------------------------
Sort
Output: (array_agg(c1 ORDER BY c1)), c2
Sort Key: (array_agg(ft1.c1 ORDER BY ft1.c1))
-> Foreign Scan
Output: (array_agg(c1 ORDER BY c1)), c2
Relations: Aggregate on (public.ft1)
- Remote SQL: SELECT array_agg("C 1" ORDER BY "C 1" ASC NULLS LAST), c2 FROM "S 1"."T 1" WHERE (("C 1" < 100)) GROUP BY c2
+ Remote SQL: SELECT array_agg("C 1" ORDER BY "C 1" ASC NULLS LAST), c2 FROM "S 1"."T 1" WHERE (("C 1" < 100)) GROUP BY 2
(7 rows)
select array_agg(c1 order by c1) from ft1 where c1 < 100 group by c2 order by 1;
@@ -2756,15 +2867,15 @@ select array_agg(c5 order by c1 desc) from ft2 where c2 = 6 and c1 < 50;
-- DISTINCT within aggregate
explain (verbose, costs off)
select array_agg(distinct (t1.c1)%5) from ft4 t1 full join ft5 t2 on (t1.c1 = t2.c1) where t1.c1 < 20 or (t1.c1 is null and t2.c1 < 5) group by (t2.c1)%3 order by 1;
- QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ QUERY PLAN
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Sort
Output: (array_agg(DISTINCT (t1.c1 % 5))), ((t2.c1 % 3))
Sort Key: (array_agg(DISTINCT (t1.c1 % 5)))
-> Foreign Scan
Output: (array_agg(DISTINCT (t1.c1 % 5))), ((t2.c1 % 3))
Relations: Aggregate on ((public.ft4 t1) FULL JOIN (public.ft5 t2))
- Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5)), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE (((r1.c1 < 20) OR ((r1.c1 IS NULL) AND (r2.c1 < 5)))) GROUP BY ((r2.c1 % 3))
+ Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5)), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE (((r1.c1 < 20) OR ((r1.c1 IS NULL) AND (r2.c1 < 5)))) GROUP BY 2
(7 rows)
select array_agg(distinct (t1.c1)%5) from ft4 t1 full join ft5 t2 on (t1.c1 = t2.c1) where t1.c1 < 20 or (t1.c1 is null and t2.c1 < 5) group by (t2.c1)%3 order by 1;
@@ -2777,15 +2888,15 @@ select array_agg(distinct (t1.c1)%5) from ft4 t1 full join ft5 t2 on (t1.c1 = t2
-- DISTINCT combined with ORDER BY within aggregate
explain (verbose, costs off)
select array_agg(distinct (t1.c1)%5 order by (t1.c1)%5) from ft4 t1 full join ft5 t2 on (t1.c1 = t2.c1) where t1.c1 < 20 or (t1.c1 is null and t2.c1 < 5) group by (t2.c1)%3 order by 1;
- QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ QUERY PLAN
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Sort
Output: (array_agg(DISTINCT (t1.c1 % 5) ORDER BY (t1.c1 % 5))), ((t2.c1 % 3))
Sort Key: (array_agg(DISTINCT (t1.c1 % 5) ORDER BY (t1.c1 % 5)))
-> Foreign Scan
Output: (array_agg(DISTINCT (t1.c1 % 5) ORDER BY (t1.c1 % 5))), ((t2.c1 % 3))
Relations: Aggregate on ((public.ft4 t1) FULL JOIN (public.ft5 t2))
- Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) ASC NULLS LAST), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE (((r1.c1 < 20) OR ((r1.c1 IS NULL) AND (r2.c1 < 5)))) GROUP BY ((r2.c1 % 3))
+ Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) ASC NULLS LAST), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE (((r1.c1 < 20) OR ((r1.c1 IS NULL) AND (r2.c1 < 5)))) GROUP BY 2
(7 rows)
select array_agg(distinct (t1.c1)%5 order by (t1.c1)%5) from ft4 t1 full join ft5 t2 on (t1.c1 = t2.c1) where t1.c1 < 20 or (t1.c1 is null and t2.c1 < 5) group by (t2.c1)%3 order by 1;
@@ -2797,15 +2908,15 @@ select array_agg(distinct (t1.c1)%5 order by (t1.c1)%5) from ft4 t1 full join ft
explain (verbose, costs off)
select array_agg(distinct (t1.c1)%5 order by (t1.c1)%5 desc nulls last) from ft4 t1 full join ft5 t2 on (t1.c1 = t2.c1) where t1.c1 < 20 or (t1.c1 is null and t2.c1 < 5) group by (t2.c1)%3 order by 1;
- QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ QUERY PLAN
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Sort
Output: (array_agg(DISTINCT (t1.c1 % 5) ORDER BY (t1.c1 % 5) DESC NULLS LAST)), ((t2.c1 % 3))
Sort Key: (array_agg(DISTINCT (t1.c1 % 5) ORDER BY (t1.c1 % 5) DESC NULLS LAST))
-> Foreign Scan
Output: (array_agg(DISTINCT (t1.c1 % 5) ORDER BY (t1.c1 % 5) DESC NULLS LAST)), ((t2.c1 % 3))
Relations: Aggregate on ((public.ft4 t1) FULL JOIN (public.ft5 t2))
- Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) DESC NULLS LAST), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE (((r1.c1 < 20) OR ((r1.c1 IS NULL) AND (r2.c1 < 5)))) GROUP BY ((r2.c1 % 3))
+ Remote SQL: SELECT array_agg(DISTINCT (r1.c1 % 5) ORDER BY ((r1.c1 % 5)) DESC NULLS LAST), (r2.c1 % 3) FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) WHERE (((r1.c1 < 20) OR ((r1.c1 IS NULL) AND (r2.c1 < 5)))) GROUP BY 2
(7 rows)
select array_agg(distinct (t1.c1)%5 order by (t1.c1)%5 desc nulls last) from ft4 t1 full join ft5 t2 on (t1.c1 = t2.c1) where t1.c1 < 20 or (t1.c1 is null and t2.c1 < 5) group by (t2.c1)%3 order by 1;
@@ -2818,15 +2929,15 @@ select array_agg(distinct (t1.c1)%5 order by (t1.c1)%5 desc nulls last) from ft4
-- FILTER within aggregate
explain (verbose, costs off)
select sum(c1) filter (where c1 < 100 and c2 > 5) from ft1 group by c2 order by 1 nulls last;
- QUERY PLAN
---------------------------------------------------------------------------------------------------------------------
+ QUERY PLAN
+-------------------------------------------------------------------------------------------------------------------
Sort
Output: (sum(c1) FILTER (WHERE ((c1 < 100) AND (c2 > 5)))), c2
Sort Key: (sum(ft1.c1) FILTER (WHERE ((ft1.c1 < 100) AND (ft1.c2 > 5))))
-> Foreign Scan
Output: (sum(c1) FILTER (WHERE ((c1 < 100) AND (c2 > 5)))), c2
Relations: Aggregate on (public.ft1)
- Remote SQL: SELECT sum("C 1") FILTER (WHERE (("C 1" < 100) AND (c2 > 5))), c2 FROM "S 1"."T 1" GROUP BY c2
+ Remote SQL: SELECT sum("C 1") FILTER (WHERE (("C 1" < 100) AND (c2 > 5))), c2 FROM "S 1"."T 1" GROUP BY 2
(7 rows)
select sum(c1) filter (where c1 < 100 and c2 > 5) from ft1 group by c2 order by 1 nulls last;
@@ -2847,12 +2958,12 @@ select sum(c1) filter (where c1 < 100 and c2 > 5) from ft1 group by c2 order by
-- DISTINCT, ORDER BY and FILTER within aggregate
explain (verbose, costs off)
select sum(c1%3), sum(distinct c1%3 order by c1%3) filter (where c1%3 < 2), c2 from ft1 where c2 = 6 group by c2;
- QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ QUERY PLAN
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Foreign Scan
Output: (sum((c1 % 3))), (sum(DISTINCT (c1 % 3) ORDER BY (c1 % 3)) FILTER (WHERE ((c1 % 3) < 2))), c2
Relations: Aggregate on (public.ft1)
- Remote SQL: SELECT sum(("C 1" % 3)), sum(DISTINCT ("C 1" % 3) ORDER BY (("C 1" % 3)) ASC NULLS LAST) FILTER (WHERE (("C 1" % 3) < 2)), c2 FROM "S 1"."T 1" WHERE ((c2 = 6)) GROUP BY c2
+ Remote SQL: SELECT sum(("C 1" % 3)), sum(DISTINCT ("C 1" % 3) ORDER BY (("C 1" % 3)) ASC NULLS LAST) FILTER (WHERE (("C 1" % 3) < 2)), c2 FROM "S 1"."T 1" WHERE ((c2 = 6)) GROUP BY 3
(4 rows)
select sum(c1%3), sum(distinct c1%3 order by c1%3) filter (where c1%3 < 2), c2 from ft1 where c2 = 6 group by c2;
@@ -2948,15 +3059,15 @@ select sum(c2) filter (where c2 in (select c2 from ft1 where c2 < 5)) from ft1;
-- Ordered-sets within aggregate
explain (verbose, costs off)
select c2, rank('10'::varchar) within group (order by c6), percentile_cont(c2/10::numeric) within group (order by c1) from ft1 where c2 < 10 group by c2 having percentile_cont(c2/10::numeric) within group (order by c1) < 500 order by c2;
- QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ QUERY PLAN
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Sort
Output: c2, (rank('10'::character varying) WITHIN GROUP (ORDER BY c6)), (percentile_cont((((c2)::numeric / '10'::numeric))::double precision) WITHIN GROUP (ORDER BY ((c1)::double precision)))
Sort Key: ft1.c2
-> Foreign Scan
Output: c2, (rank('10'::character varying) WITHIN GROUP (ORDER BY c6)), (percentile_cont((((c2)::numeric / '10'::numeric))::double precision) WITHIN GROUP (ORDER BY ((c1)::double precision)))
Relations: Aggregate on (public.ft1)
- Remote SQL: SELECT c2, rank('10'::character varying) WITHIN GROUP (ORDER BY c6 ASC NULLS LAST), percentile_cont((c2 / 10::numeric)) WITHIN GROUP (ORDER BY ("C 1") ASC NULLS LAST) FROM "S 1"."T 1" WHERE ((c2 < 10)) GROUP BY c2 HAVING ((percentile_cont((c2 / 10::numeric)) WITHIN GROUP (ORDER BY ("C 1") ASC NULLS LAST) < 500::double precision))
+ Remote SQL: SELECT c2, rank('10'::character varying) WITHIN GROUP (ORDER BY c6 ASC NULLS LAST), percentile_cont((c2 / 10::numeric)) WITHIN GROUP (ORDER BY ("C 1") ASC NULLS LAST) FROM "S 1"."T 1" WHERE ((c2 < 10)) GROUP BY 1 HAVING ((percentile_cont((c2 / 10::numeric)) WITHIN GROUP (ORDER BY ("C 1") ASC NULLS LAST) < 500::double precision))
(7 rows)
select c2, rank('10'::varchar) within group (order by c6), percentile_cont(c2/10::numeric) within group (order by c1) from ft1 where c2 < 10 group by c2 having percentile_cont(c2/10::numeric) within group (order by c1) < 500 order by c2;
@@ -2972,12 +3083,12 @@ select c2, rank('10'::varchar) within group (order by c6), percentile_cont(c2/10
-- Using multiple arguments within aggregates
explain (verbose, costs off)
select c1, rank(c1, c2) within group (order by c1, c2) from ft1 group by c1, c2 having c1 = 6 order by 1;
- QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ QUERY PLAN
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------
Foreign Scan
Output: c1, (rank(c1, c2) WITHIN GROUP (ORDER BY c1, c2)), c2
Relations: Aggregate on (public.ft1)
- Remote SQL: SELECT "C 1", rank("C 1", c2) WITHIN GROUP (ORDER BY "C 1" ASC NULLS LAST, c2 ASC NULLS LAST), c2 FROM "S 1"."T 1" WHERE (("C 1" = 6)) GROUP BY "C 1", c2
+ Remote SQL: SELECT "C 1", rank("C 1", c2) WITHIN GROUP (ORDER BY "C 1" ASC NULLS LAST, c2 ASC NULLS LAST), c2 FROM "S 1"."T 1" WHERE (("C 1" = 6)) GROUP BY 1, 3
(4 rows)
select c1, rank(c1, c2) within group (order by c1, c2) from ft1 group by c1, c2 having c1 = 6 order by 1;
@@ -3015,15 +3126,15 @@ alter server loopback options (set extensions 'postgres_fdw');
-- Now aggregate will be pushed. Aggregate will display VARIADIC argument.
explain (verbose, costs off)
select c2, least_agg(c1) from ft1 where c2 < 100 group by c2 order by c2;
- QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------
+ QUERY PLAN
+-----------------------------------------------------------------------------------------------------------------------
Sort
Output: c2, (least_agg(VARIADIC ARRAY[c1]))
Sort Key: ft1.c2
-> Foreign Scan
Output: c2, (least_agg(VARIADIC ARRAY[c1]))
Relations: Aggregate on (public.ft1)
- Remote SQL: SELECT c2, public.least_agg(VARIADIC ARRAY["C 1"]) FROM "S 1"."T 1" WHERE ((c2 < 100)) GROUP BY c2
+ Remote SQL: SELECT c2, public.least_agg(VARIADIC ARRAY["C 1"]) FROM "S 1"."T 1" WHERE ((c2 < 100)) GROUP BY 1
(7 rows)
select c2, least_agg(c1) from ft1 where c2 < 100 group by c2 order by c2;
@@ -3115,12 +3226,12 @@ alter server loopback options (set extensions 'postgres_fdw');
-- Now this will be pushed as sort operator is part of the extension.
explain (verbose, costs off)
select array_agg(c1 order by c1 using operator(public.<^)) from ft2 where c2 = 6 and c1 < 100 group by c2;
- QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ QUERY PLAN
+----------------------------------------------------------------------------------------------------------------------------------------------------------------
Foreign Scan
Output: (array_agg(c1 ORDER BY c1 USING <^ NULLS LAST)), c2
Relations: Aggregate on (public.ft2)
- Remote SQL: SELECT array_agg("C 1" ORDER BY "C 1" USING OPERATOR(public.<^) NULLS LAST), c2 FROM "S 1"."T 1" WHERE (("C 1" < 100)) AND ((c2 = 6)) GROUP BY c2
+ Remote SQL: SELECT array_agg("C 1" ORDER BY "C 1" USING OPERATOR(public.<^) NULLS LAST), c2 FROM "S 1"."T 1" WHERE (("C 1" < 100)) AND ((c2 = 6)) GROUP BY 2
(4 rows)
select array_agg(c1 order by c1 using operator(public.<^)) from ft2 where c2 = 6 and c1 < 100 group by c2;
@@ -3160,27 +3271,29 @@ drop operator public.<^(int, int);
-- Input relation to aggregate push down hook is not safe to pushdown and thus
-- the aggregate cannot be pushed down to foreign server.
explain (verbose, costs off)
-select count(t1.c3) from ft1 t1, ft1 t2 where t1.c1 = postgres_fdw_abs(t1.c2);
- QUERY PLAN
-----------------------------------------------------------------------------------------------------------
+select count(t1.c3) from ft2 t1 left join ft2 t2 on (t1.c1 = random() * t2.c2);
+ QUERY PLAN
+-------------------------------------------------------------------------------------------
Aggregate
Output: count(t1.c3)
- -> Nested Loop
+ -> Nested Loop Left Join
Output: t1.c3
- -> Foreign Scan on public.ft1 t2
- Remote SQL: SELECT NULL FROM "S 1"."T 1"
+ Join Filter: ((t1.c1)::double precision = (random() * (t2.c2)::double precision))
+ -> Foreign Scan on public.ft2 t1
+ Output: t1.c3, t1.c1
+ Remote SQL: SELECT "C 1", c3 FROM "S 1"."T 1"
-> Materialize
- Output: t1.c3
- -> Foreign Scan on public.ft1 t1
- Output: t1.c3
- Remote SQL: SELECT c3 FROM "S 1"."T 1" WHERE (("C 1" = public.postgres_fdw_abs(c2)))
-(11 rows)
+ Output: t2.c2
+ -> Foreign Scan on public.ft2 t2
+ Output: t2.c2
+ Remote SQL: SELECT c2 FROM "S 1"."T 1"
+(13 rows)
-- Subquery in FROM clause having aggregate
explain (verbose, costs off)
select count(*), x.b from ft1, (select c2 a, sum(c1) b from ft1 group by c2) x where ft1.c2 = x.a group by x.b order by 1, 2;
- QUERY PLAN
-------------------------------------------------------------------------------------------------
+ QUERY PLAN
+-----------------------------------------------------------------------------------------------
Sort
Output: (count(*)), x.b
Sort Key: (count(*)), x.b
@@ -3201,7 +3314,7 @@ select count(*), x.b from ft1, (select c2 a, sum(c1) b from ft1 group by c2) x w
-> Foreign Scan
Output: ft1_1.c2, (sum(ft1_1.c1))
Relations: Aggregate on (public.ft1)
- Remote SQL: SELECT c2, sum("C 1") FROM "S 1"."T 1" GROUP BY c2
+ Remote SQL: SELECT c2, sum("C 1") FROM "S 1"."T 1" GROUP BY 1
(21 rows)
select count(*), x.b from ft1, (select c2 a, sum(c1) b from ft1 group by c2) x where ft1.c2 = x.a group by x.b order by 1, 2;
@@ -3222,15 +3335,15 @@ select count(*), x.b from ft1, (select c2 a, sum(c1) b from ft1 group by c2) x w
-- FULL join with IS NULL check in HAVING
explain (verbose, costs off)
select avg(t1.c1), sum(t2.c1) from ft4 t1 full join ft5 t2 on (t1.c1 = t2.c1) group by t2.c1 having (avg(t1.c1) is null and sum(t2.c1) < 10) or sum(t2.c1) is null order by 1 nulls last, 2;
- QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ QUERY PLAN
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Sort
Output: (avg(t1.c1)), (sum(t2.c1)), t2.c1
Sort Key: (avg(t1.c1)), (sum(t2.c1))
-> Foreign Scan
Output: (avg(t1.c1)), (sum(t2.c1)), t2.c1
Relations: Aggregate on ((public.ft4 t1) FULL JOIN (public.ft5 t2))
- Remote SQL: SELECT avg(r1.c1), sum(r2.c1), r2.c1 FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) GROUP BY r2.c1 HAVING ((((avg(r1.c1) IS NULL) AND (sum(r2.c1) < 10)) OR (sum(r2.c1) IS NULL)))
+ Remote SQL: SELECT avg(r1.c1), sum(r2.c1), r2.c1 FROM ("S 1"."T 3" r1 FULL JOIN "S 1"."T 4" r2 ON (((r1.c1 = r2.c1)))) GROUP BY 3 HAVING ((((avg(r1.c1) IS NULL) AND (sum(r2.c1) < 10)) OR (sum(r2.c1) IS NULL)))
(7 rows)
select avg(t1.c1), sum(t2.c1) from ft4 t1 full join ft5 t2 on (t1.c1 = t2.c1) group by t2.c1 having (avg(t1.c1) is null and sum(t2.c1) < 10) or sum(t2.c1) is null order by 1 nulls last, 2;
@@ -3284,8 +3397,8 @@ select sum(c2) * (random() <= 1)::int as sum from ft1 order by 1;
set enable_hashagg to false;
explain (verbose, costs off)
select c2, sum from "S 1"."T 1" t1, lateral (select sum(t2.c1 + t1."C 1") sum from ft2 t2 group by t2.c1) qry where t1.c2 * 2 = qry.sum and t1.c2 < 3 and t1."C 1" < 100 order by 1;
- QUERY PLAN
-----------------------------------------------------------------------------------------------------------
+ QUERY PLAN
+------------------------------------------------------------------------------------------------------
Sort
Output: t1.c2, qry.sum
Sort Key: t1.c2
@@ -3301,7 +3414,7 @@ select c2, sum from "S 1"."T 1" t1, lateral (select sum(t2.c1 + t1."C 1") sum fr
-> Foreign Scan
Output: (sum((t2.c1 + t1."C 1"))), t2.c1
Relations: Aggregate on (public.ft2 t2)
- Remote SQL: SELECT sum(("C 1" + $1::integer)), "C 1" FROM "S 1"."T 1" GROUP BY "C 1"
+ Remote SQL: SELECT sum(("C 1" + $1::integer)), "C 1" FROM "S 1"."T 1" GROUP BY 2
(16 rows)
select c2, sum from "S 1"."T 1" t1, lateral (select sum(t2.c1 + t1."C 1") sum from ft2 t2 group by t2.c1) qry where t1.c2 * 2 = qry.sum and t1.c2 < 3 and t1."C 1" < 100 order by 1;
@@ -3447,8 +3560,8 @@ select c2, sum(c1), grouping(c2) from ft1 where c2 < 3 group by c2 order by 1 nu
-- DISTINCT itself is not pushed down, whereas underneath aggregate is pushed
explain (verbose, costs off)
select distinct sum(c1)/1000 s from ft2 where c2 < 6 group by c2 order by 1;
- QUERY PLAN
---------------------------------------------------------------------------------------------------------
+ QUERY PLAN
+-------------------------------------------------------------------------------------------------------
Unique
Output: ((sum(c1) / 1000)), c2
-> Sort
@@ -3457,7 +3570,7 @@ select distinct sum(c1)/1000 s from ft2 where c2 < 6 group by c2 order by 1;
-> Foreign Scan
Output: ((sum(c1) / 1000)), c2
Relations: Aggregate on (public.ft2)
- Remote SQL: SELECT (sum("C 1") / 1000), c2 FROM "S 1"."T 1" WHERE ((c2 < 6)) GROUP BY c2
+ Remote SQL: SELECT (sum("C 1") / 1000), c2 FROM "S 1"."T 1" WHERE ((c2 < 6)) GROUP BY 2
(9 rows)
select distinct sum(c1)/1000 s from ft2 where c2 < 6 group by c2 order by 1;
@@ -3470,8 +3583,8 @@ select distinct sum(c1)/1000 s from ft2 where c2 < 6 group by c2 order by 1;
-- WindowAgg
explain (verbose, costs off)
select c2, sum(c2), count(c2) over (partition by c2%2) from ft2 where c2 < 10 group by c2 order by 1;
- QUERY PLAN
--------------------------------------------------------------------------------------------------------------
+ QUERY PLAN
+------------------------------------------------------------------------------------------------------------
Sort
Output: c2, (sum(c2)), (count(c2) OVER (?)), ((c2 % 2))
Sort Key: ft2.c2
@@ -3483,7 +3596,7 @@ select c2, sum(c2), count(c2) over (partition by c2%2) from ft2 where c2 < 10 gr
-> Foreign Scan
Output: c2, ((c2 % 2)), (sum(c2))
Relations: Aggregate on (public.ft2)
- Remote SQL: SELECT c2, (c2 % 2), sum(c2) FROM "S 1"."T 1" WHERE ((c2 < 10)) GROUP BY c2
+ Remote SQL: SELECT c2, (c2 % 2), sum(c2) FROM "S 1"."T 1" WHERE ((c2 < 10)) GROUP BY 1
(12 rows)
select c2, sum(c2), count(c2) over (partition by c2%2) from ft2 where c2 < 10 group by c2 order by 1;
@@ -3503,8 +3616,8 @@ select c2, sum(c2), count(c2) over (partition by c2%2) from ft2 where c2 < 10 gr
explain (verbose, costs off)
select c2, array_agg(c2) over (partition by c2%2 order by c2 desc) from ft1 where c2 < 10 group by c2 order by 1;
- QUERY PLAN
-----------------------------------------------------------------------------------------------------
+ QUERY PLAN
+---------------------------------------------------------------------------------------------------
Sort
Output: c2, (array_agg(c2) OVER (?)), ((c2 % 2))
Sort Key: ft1.c2
@@ -3516,7 +3629,7 @@ select c2, array_agg(c2) over (partition by c2%2 order by c2 desc) from ft1 wher
-> Foreign Scan
Output: c2, ((c2 % 2))
Relations: Aggregate on (public.ft1)
- Remote SQL: SELECT c2, (c2 % 2) FROM "S 1"."T 1" WHERE ((c2 < 10)) GROUP BY c2
+ Remote SQL: SELECT c2, (c2 % 2) FROM "S 1"."T 1" WHERE ((c2 < 10)) GROUP BY 1
(12 rows)
select c2, array_agg(c2) over (partition by c2%2 order by c2 desc) from ft1 where c2 < 10 group by c2 order by 1;
@@ -3536,8 +3649,8 @@ select c2, array_agg(c2) over (partition by c2%2 order by c2 desc) from ft1 wher
explain (verbose, costs off)
select c2, array_agg(c2) over (partition by c2%2 order by c2 range between current row and unbounded following) from ft1 where c2 < 10 group by c2 order by 1;
- QUERY PLAN
-----------------------------------------------------------------------------------------------------
+ QUERY PLAN
+---------------------------------------------------------------------------------------------------
Sort
Output: c2, (array_agg(c2) OVER (?)), ((c2 % 2))
Sort Key: ft1.c2
@@ -3549,7 +3662,7 @@ select c2, array_agg(c2) over (partition by c2%2 order by c2 range between curre
-> Foreign Scan
Output: c2, ((c2 % 2))
Relations: Aggregate on (public.ft1)
- Remote SQL: SELECT c2, (c2 % 2) FROM "S 1"."T 1" WHERE ((c2 < 10)) GROUP BY c2
+ Remote SQL: SELECT c2, (c2 % 2) FROM "S 1"."T 1" WHERE ((c2 < 10)) GROUP BY 1
(12 rows)
select c2, array_agg(c2) over (partition by c2%2 order by c2 range between current row and unbounded following) from ft1 where c2 < 10 group by c2 order by 1;
@@ -4289,27 +4402,13 @@ UPDATE ft2 SET c2 = c2 + 400, c3 = c3 || '_update7' WHERE c1 % 10 = 7 RETURNING
EXPLAIN (verbose, costs off)
UPDATE ft2 SET c2 = ft2.c2 + 500, c3 = ft2.c3 || '_update9', c7 = DEFAULT
- FROM ft1 WHERE ft1.c1 = ft2.c2 AND ft1.c1 % 10 = 9; -- can't be pushed down
- QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ FROM ft1 WHERE ft1.c1 = ft2.c2 AND ft1.c1 % 10 = 9; -- can be pushed down
+ QUERY PLAN
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Update on public.ft2
- Remote SQL: UPDATE "S 1"."T 1" SET c2 = $2, c3 = $3, c7 = $4 WHERE ctid = $1
- -> Foreign Scan
- Output: ft2.c1, (ft2.c2 + 500), NULL::integer, (ft2.c3 || '_update9'::text), ft2.c4, ft2.c5, ft2.c6, 'ft2 '::character(10), ft2.c8, ft2.ctid, ft1.*
- Relations: (public.ft2) INNER JOIN (public.ft1)
- Remote SQL: SELECT r1."C 1", r1.c2, r1.c3, r1.c4, r1.c5, r1.c6, r1.c8, r1.ctid, CASE WHEN (r2.*)::text IS NOT NULL THEN ROW(r2."C 1", r2.c2, r2.c3, r2.c4, r2.c5, r2.c6, r2.c7, r2.c8) END FROM ("S 1"."T 1" r1 INNER JOIN "S 1"."T 1" r2 ON (((r1.c2 = r2."C 1")) AND (((r2."C 1" % 10) = 9)))) FOR UPDATE OF r1
- -> Hash Join
- Output: ft2.c1, ft2.c2, ft2.c3, ft2.c4, ft2.c5, ft2.c6, ft2.c8, ft2.ctid, ft1.*
- Hash Cond: (ft2.c2 = ft1.c1)
- -> Foreign Scan on public.ft2
- Output: ft2.c1, ft2.c2, ft2.c3, ft2.c4, ft2.c5, ft2.c6, ft2.c8, ft2.ctid
- Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c8, ctid FROM "S 1"."T 1" FOR UPDATE
- -> Hash
- Output: ft1.*, ft1.c1
- -> Foreign Scan on public.ft1
- Output: ft1.*, ft1.c1
- Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c7, c8 FROM "S 1"."T 1" WHERE ((("C 1" % 10) = 9))
-(17 rows)
+ -> Foreign Update
+ Remote SQL: UPDATE "S 1"."T 1" r1 SET c2 = (r1.c2 + 500), c3 = (r1.c3 || '_update9'::text), c7 = 'ft2 '::character(10) FROM "S 1"."T 1" r2 WHERE ((r1.c2 = r2."C 1")) AND (((r2."C 1" % 10) = 9))
+(3 rows)
UPDATE ft2 SET c2 = ft2.c2 + 500, c3 = ft2.c3 || '_update9', c7 = DEFAULT
FROM ft1 WHERE ft1.c1 = ft2.c2 AND ft1.c1 % 10 = 9;
@@ -4432,27 +4531,13 @@ DELETE FROM ft2 WHERE c1 % 10 = 5 RETURNING c1, c4;
(103 rows)
EXPLAIN (verbose, costs off)
-DELETE FROM ft2 USING ft1 WHERE ft1.c1 = ft2.c2 AND ft1.c1 % 10 = 2; -- can't be pushed down
- QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+DELETE FROM ft2 USING ft1 WHERE ft1.c1 = ft2.c2 AND ft1.c1 % 10 = 2; -- can be pushed down
+ QUERY PLAN
+----------------------------------------------------------------------------------------------------------------------------
Delete on public.ft2
- Remote SQL: DELETE FROM "S 1"."T 1" WHERE ctid = $1
- -> Foreign Scan
- Output: ft2.ctid, ft1.*
- Relations: (public.ft2) INNER JOIN (public.ft1)
- Remote SQL: SELECT r1.ctid, CASE WHEN (r2.*)::text IS NOT NULL THEN ROW(r2."C 1", r2.c2, r2.c3, r2.c4, r2.c5, r2.c6, r2.c7, r2.c8) END FROM ("S 1"."T 1" r1 INNER JOIN "S 1"."T 1" r2 ON (((r1.c2 = r2."C 1")) AND (((r2."C 1" % 10) = 2)))) FOR UPDATE OF r1
- -> Hash Join
- Output: ft2.ctid, ft1.*
- Hash Cond: (ft2.c2 = ft1.c1)
- -> Foreign Scan on public.ft2
- Output: ft2.ctid, ft2.c2
- Remote SQL: SELECT c2, ctid FROM "S 1"."T 1" FOR UPDATE
- -> Hash
- Output: ft1.*, ft1.c1
- -> Foreign Scan on public.ft1
- Output: ft1.*, ft1.c1
- Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c7, c8 FROM "S 1"."T 1" WHERE ((("C 1" % 10) = 2))
-(17 rows)
+ -> Foreign Delete
+ Remote SQL: DELETE FROM "S 1"."T 1" r1 USING "S 1"."T 1" r2 WHERE ((r1.c2 = r2."C 1")) AND (((r2."C 1" % 10) = 2))
+(3 rows)
DELETE FROM ft2 USING ft1 WHERE ft1.c1 = ft2.c2 AND ft1.c1 % 10 = 2;
SELECT c1,c2,c3,c4 FROM ft2 ORDER BY c1;
@@ -5328,6 +5413,195 @@ DELETE FROM ft2 WHERE c1 = 9999 RETURNING tableoid::regclass;
ft2
(1 row)
+-- Test UPDATE/DELETE with RETURNING on a three-table join
+INSERT INTO ft2 (c1,c2,c3)
+ SELECT id, id - 1200, to_char(id, 'FM00000') FROM generate_series(1201, 1300) id;
+EXPLAIN (verbose, costs off)
+UPDATE ft2 SET c3 = 'foo'
+ FROM ft4 INNER JOIN ft5 ON (ft4.c1 = ft5.c1)
+ WHERE ft2.c1 > 1200 AND ft2.c2 = ft4.c1
+ RETURNING ft2, ft2.*, ft4, ft4.*; -- can be pushed down
+ QUERY PLAN
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Update on public.ft2
+ Output: ft2.*, ft2.c1, ft2.c2, ft2.c3, ft2.c4, ft2.c5, ft2.c6, ft2.c7, ft2.c8, ft4.*, ft4.c1, ft4.c2, ft4.c3
+ -> Foreign Update
+ Remote SQL: UPDATE "S 1"."T 1" r1 SET c3 = 'foo'::text FROM ("S 1"."T 3" r2 INNER JOIN "S 1"."T 4" r3 ON (TRUE)) WHERE ((r2.c1 = r3.c1)) AND ((r1.c2 = r2.c1)) AND ((r1."C 1" > 1200)) RETURNING r1."C 1", r1.c2, r1.c3, r1.c4, r1.c5, r1.c6, r1.c7, r1.c8, CASE WHEN (r2.*)::text IS NOT NULL THEN ROW(r2.c1, r2.c2, r2.c3) END, r2.c1, r2.c2, r2.c3
+(4 rows)
+
+UPDATE ft2 SET c3 = 'foo'
+ FROM ft4 INNER JOIN ft5 ON (ft4.c1 = ft5.c1)
+ WHERE ft2.c1 > 1200 AND ft2.c2 = ft4.c1
+ RETURNING ft2, ft2.*, ft4, ft4.*;
+ ft2 | c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8 | ft4 | c1 | c2 | c3
+--------------------------------+------+----+-----+----+----+----+------------+----+----------------+----+----+--------
+ (1206,6,foo,,,,"ft2 ",) | 1206 | 6 | foo | | | | ft2 | | (6,7,AAA006) | 6 | 7 | AAA006
+ (1212,12,foo,,,,"ft2 ",) | 1212 | 12 | foo | | | | ft2 | | (12,13,AAA012) | 12 | 13 | AAA012
+ (1218,18,foo,,,,"ft2 ",) | 1218 | 18 | foo | | | | ft2 | | (18,19,AAA018) | 18 | 19 | AAA018
+ (1224,24,foo,,,,"ft2 ",) | 1224 | 24 | foo | | | | ft2 | | (24,25,AAA024) | 24 | 25 | AAA024
+ (1230,30,foo,,,,"ft2 ",) | 1230 | 30 | foo | | | | ft2 | | (30,31,AAA030) | 30 | 31 | AAA030
+ (1236,36,foo,,,,"ft2 ",) | 1236 | 36 | foo | | | | ft2 | | (36,37,AAA036) | 36 | 37 | AAA036
+ (1242,42,foo,,,,"ft2 ",) | 1242 | 42 | foo | | | | ft2 | | (42,43,AAA042) | 42 | 43 | AAA042
+ (1248,48,foo,,,,"ft2 ",) | 1248 | 48 | foo | | | | ft2 | | (48,49,AAA048) | 48 | 49 | AAA048
+ (1254,54,foo,,,,"ft2 ",) | 1254 | 54 | foo | | | | ft2 | | (54,55,AAA054) | 54 | 55 | AAA054
+ (1260,60,foo,,,,"ft2 ",) | 1260 | 60 | foo | | | | ft2 | | (60,61,AAA060) | 60 | 61 | AAA060
+ (1266,66,foo,,,,"ft2 ",) | 1266 | 66 | foo | | | | ft2 | | (66,67,AAA066) | 66 | 67 | AAA066
+ (1272,72,foo,,,,"ft2 ",) | 1272 | 72 | foo | | | | ft2 | | (72,73,AAA072) | 72 | 73 | AAA072
+ (1278,78,foo,,,,"ft2 ",) | 1278 | 78 | foo | | | | ft2 | | (78,79,AAA078) | 78 | 79 | AAA078
+ (1284,84,foo,,,,"ft2 ",) | 1284 | 84 | foo | | | | ft2 | | (84,85,AAA084) | 84 | 85 | AAA084
+ (1290,90,foo,,,,"ft2 ",) | 1290 | 90 | foo | | | | ft2 | | (90,91,AAA090) | 90 | 91 | AAA090
+ (1296,96,foo,,,,"ft2 ",) | 1296 | 96 | foo | | | | ft2 | | (96,97,AAA096) | 96 | 97 | AAA096
+(16 rows)
+
+EXPLAIN (verbose, costs off)
+DELETE FROM ft2
+ USING ft4 LEFT JOIN ft5 ON (ft4.c1 = ft5.c1)
+ WHERE ft2.c1 > 1200 AND ft2.c1 % 10 = 0 AND ft2.c2 = ft4.c1
+ RETURNING 100; -- can be pushed down
+ QUERY PLAN
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Delete on public.ft2
+ Output: 100
+ -> Foreign Delete
+ Remote SQL: DELETE FROM "S 1"."T 1" r1 USING ("S 1"."T 3" r2 LEFT JOIN "S 1"."T 4" r3 ON (((r2.c1 = r3.c1)))) WHERE ((r1.c2 = r2.c1)) AND ((r1."C 1" > 1200)) AND (((r1."C 1" % 10) = 0))
+(4 rows)
+
+DELETE FROM ft2
+ USING ft4 LEFT JOIN ft5 ON (ft4.c1 = ft5.c1)
+ WHERE ft2.c1 > 1200 AND ft2.c1 % 10 = 0 AND ft2.c2 = ft4.c1
+ RETURNING 100;
+ ?column?
+----------
+ 100
+ 100
+ 100
+ 100
+ 100
+ 100
+ 100
+ 100
+ 100
+ 100
+(10 rows)
+
+DELETE FROM ft2 WHERE ft2.c1 > 1200;
+-- Test UPDATE/DELETE with WHERE or JOIN/ON conditions containing
+-- user-defined operators/functions
+ALTER SERVER loopback OPTIONS (DROP extensions);
+INSERT INTO ft2 (c1,c2,c3)
+ SELECT id, id % 10, to_char(id, 'FM00000') FROM generate_series(2001, 2010) id;
+EXPLAIN (verbose, costs off)
+UPDATE ft2 SET c3 = 'bar' WHERE postgres_fdw_abs(c1) > 2000 RETURNING *; -- can't be pushed down
+ QUERY PLAN
+----------------------------------------------------------------------------------------------------------
+ Update on public.ft2
+ Output: c1, c2, c3, c4, c5, c6, c7, c8
+ Remote SQL: UPDATE "S 1"."T 1" SET c3 = $2 WHERE ctid = $1 RETURNING "C 1", c2, c3, c4, c5, c6, c7, c8
+ -> Foreign Scan on public.ft2
+ Output: c1, c2, NULL::integer, 'bar'::text, c4, c5, c6, c7, c8, ctid
+ Filter: (postgres_fdw_abs(ft2.c1) > 2000)
+ Remote SQL: SELECT "C 1", c2, c4, c5, c6, c7, c8, ctid FROM "S 1"."T 1" FOR UPDATE
+(7 rows)
+
+UPDATE ft2 SET c3 = 'bar' WHERE postgres_fdw_abs(c1) > 2000 RETURNING *;
+ c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8
+------+----+-----+----+----+----+------------+----
+ 2001 | 1 | bar | | | | ft2 |
+ 2002 | 2 | bar | | | | ft2 |
+ 2003 | 3 | bar | | | | ft2 |
+ 2004 | 4 | bar | | | | ft2 |
+ 2005 | 5 | bar | | | | ft2 |
+ 2006 | 6 | bar | | | | ft2 |
+ 2007 | 7 | bar | | | | ft2 |
+ 2008 | 8 | bar | | | | ft2 |
+ 2009 | 9 | bar | | | | ft2 |
+ 2010 | 0 | bar | | | | ft2 |
+(10 rows)
+
+EXPLAIN (verbose, costs off)
+UPDATE ft2 SET c3 = 'baz'
+ FROM ft4 INNER JOIN ft5 ON (ft4.c1 = ft5.c1)
+ WHERE ft2.c1 > 2000 AND ft2.c2 === ft4.c1
+ RETURNING ft2.*, ft4.*, ft5.*; -- can't be pushed down
+ QUERY PLAN
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Update on public.ft2
+ Output: ft2.c1, ft2.c2, ft2.c3, ft2.c4, ft2.c5, ft2.c6, ft2.c7, ft2.c8, ft4.c1, ft4.c2, ft4.c3, ft5.c1, ft5.c2, ft5.c3
+ Remote SQL: UPDATE "S 1"."T 1" SET c3 = $2 WHERE ctid = $1 RETURNING "C 1", c2, c3, c4, c5, c6, c7, c8
+ -> Nested Loop
+ Output: ft2.c1, ft2.c2, NULL::integer, 'baz'::text, ft2.c4, ft2.c5, ft2.c6, ft2.c7, ft2.c8, ft2.ctid, ft4.*, ft5.*, ft4.c1, ft4.c2, ft4.c3, ft5.c1, ft5.c2, ft5.c3
+ Join Filter: (ft2.c2 === ft4.c1)
+ -> Foreign Scan on public.ft2
+ Output: ft2.c1, ft2.c2, ft2.c4, ft2.c5, ft2.c6, ft2.c7, ft2.c8, ft2.ctid
+ Remote SQL: SELECT "C 1", c2, c4, c5, c6, c7, c8, ctid FROM "S 1"."T 1" WHERE (("C 1" > 2000)) FOR UPDATE
+ -> Foreign Scan
+ Output: ft4.*, ft4.c1, ft4.c2, ft4.c3, ft5.*, ft5.c1, ft5.c2, ft5.c3
+ Relations: (public.ft4) INNER JOIN (public.ft5)
+ Remote SQL: SELECT CASE WHEN (r2.*)::text IS NOT NULL THEN ROW(r2.c1, r2.c2, r2.c3) END, r2.c1, r2.c2, r2.c3, CASE WHEN (r3.*)::text IS NOT NULL THEN ROW(r3.c1, r3.c2, r3.c3) END, r3.c1, r3.c2, r3.c3 FROM ("S 1"."T 3" r2 INNER JOIN "S 1"."T 4" r3 ON (((r2.c1 = r3.c1))))
+ -> Hash Join
+ Output: ft4.*, ft4.c1, ft4.c2, ft4.c3, ft5.*, ft5.c1, ft5.c2, ft5.c3
+ Hash Cond: (ft4.c1 = ft5.c1)
+ -> Foreign Scan on public.ft4
+ Output: ft4.*, ft4.c1, ft4.c2, ft4.c3
+ Remote SQL: SELECT c1, c2, c3 FROM "S 1"."T 3"
+ -> Hash
+ Output: ft5.*, ft5.c1, ft5.c2, ft5.c3
+ -> Foreign Scan on public.ft5
+ Output: ft5.*, ft5.c1, ft5.c2, ft5.c3
+ Remote SQL: SELECT c1, c2, c3 FROM "S 1"."T 4"
+(24 rows)
+
+UPDATE ft2 SET c3 = 'baz'
+ FROM ft4 INNER JOIN ft5 ON (ft4.c1 = ft5.c1)
+ WHERE ft2.c1 > 2000 AND ft2.c2 === ft4.c1
+ RETURNING ft2.*, ft4.*, ft5.*;
+ c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8 | c1 | c2 | c3 | c1 | c2 | c3
+------+----+-----+----+----+----+------------+----+----+----+--------+----+----+--------
+ 2006 | 6 | baz | | | | ft2 | | 6 | 7 | AAA006 | 6 | 7 | AAA006
+(1 row)
+
+EXPLAIN (verbose, costs off)
+DELETE FROM ft2
+ USING ft4 INNER JOIN ft5 ON (ft4.c1 === ft5.c1)
+ WHERE ft2.c1 > 2000 AND ft2.c2 = ft4.c1
+ RETURNING ft2.c1, ft2.c2, ft2.c3; -- can't be pushed down
+ QUERY PLAN
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Delete on public.ft2
+ Output: ft2.c1, ft2.c2, ft2.c3
+ Remote SQL: DELETE FROM "S 1"."T 1" WHERE ctid = $1 RETURNING "C 1", c2, c3
+ -> Foreign Scan
+ Output: ft2.ctid, ft4.*, ft5.*
+ Filter: (ft4.c1 === ft5.c1)
+ Relations: ((public.ft2) INNER JOIN (public.ft4)) INNER JOIN (public.ft5)
+ Remote SQL: SELECT r1.ctid, CASE WHEN (r2.*)::text IS NOT NULL THEN ROW(r2.c1, r2.c2, r2.c3) END, CASE WHEN (r3.*)::text IS NOT NULL THEN ROW(r3.c1, r3.c2, r3.c3) END, r2.c1, r3.c1 FROM (("S 1"."T 1" r1 INNER JOIN "S 1"."T 3" r2 ON (((r1.c2 = r2.c1)) AND ((r1."C 1" > 2000)))) INNER JOIN "S 1"."T 4" r3 ON (TRUE)) FOR UPDATE OF r1
+ -> Nested Loop
+ Output: ft2.ctid, ft4.*, ft5.*, ft4.c1, ft5.c1
+ -> Nested Loop
+ Output: ft2.ctid, ft4.*, ft4.c1
+ Join Filter: (ft2.c2 = ft4.c1)
+ -> Foreign Scan on public.ft2
+ Output: ft2.ctid, ft2.c2
+ Remote SQL: SELECT c2, ctid FROM "S 1"."T 1" WHERE (("C 1" > 2000)) FOR UPDATE
+ -> Foreign Scan on public.ft4
+ Output: ft4.*, ft4.c1
+ Remote SQL: SELECT c1, c2, c3 FROM "S 1"."T 3"
+ -> Foreign Scan on public.ft5
+ Output: ft5.*, ft5.c1
+ Remote SQL: SELECT c1, c2, c3 FROM "S 1"."T 4"
+(22 rows)
+
+DELETE FROM ft2
+ USING ft4 INNER JOIN ft5 ON (ft4.c1 === ft5.c1)
+ WHERE ft2.c1 > 2000 AND ft2.c2 = ft4.c1
+ RETURNING ft2.c1, ft2.c2, ft2.c3;
+ c1 | c2 | c3
+------+----+-----
+ 2006 | 6 | baz
+(1 row)
+
+DELETE FROM ft2 WHERE ft2.c1 > 2000;
+ALTER SERVER loopback OPTIONS (ADD extensions 'postgres_fdw');
-- Test that trigger on remote table works as expected
CREATE OR REPLACE FUNCTION "S 1".F_BRTRIG() RETURNS trigger AS $$
BEGIN
@@ -5728,6 +6002,7 @@ select c2, count(*) from "S 1"."T 1" where c2 < 500 group by 1 order by 1;
407 | 100
(13 rows)
+VACUUM ANALYZE "S 1"."T 1";
-- Above DMLs add data with c6 as NULL in ft1, so test ORDER BY NULLS LAST and NULLs
-- FIRST behavior here.
-- ORDER BY DESC NULLS LAST options
@@ -7022,6 +7297,63 @@ update bar set f2 = f2 + 100 returning *;
7 | 277
(6 rows)
+-- Test that UPDATE/DELETE with inherited target works with row-level triggers
+CREATE TRIGGER trig_row_before
+BEFORE UPDATE OR DELETE ON bar2
+FOR EACH ROW EXECUTE PROCEDURE trigger_data(23,'skidoo');
+CREATE TRIGGER trig_row_after
+AFTER UPDATE OR DELETE ON bar2
+FOR EACH ROW EXECUTE PROCEDURE trigger_data(23,'skidoo');
+explain (verbose, costs off)
+update bar set f2 = f2 + 100;
+ QUERY PLAN
+--------------------------------------------------------------------------------------
+ Update on public.bar
+ Update on public.bar
+ Foreign Update on public.bar2
+ Remote SQL: UPDATE public.loct2 SET f2 = $2 WHERE ctid = $1 RETURNING f1, f2, f3
+ -> Seq Scan on public.bar
+ Output: bar.f1, (bar.f2 + 100), bar.ctid
+ -> Foreign Scan on public.bar2
+ Output: bar2.f1, (bar2.f2 + 100), bar2.f3, bar2.ctid, bar2.*
+ Remote SQL: SELECT f1, f2, f3, ctid FROM public.loct2 FOR UPDATE
+(9 rows)
+
+update bar set f2 = f2 + 100;
+NOTICE: trig_row_before(23, skidoo) BEFORE ROW UPDATE ON bar2
+NOTICE: OLD: (3,333,33),NEW: (3,433,33)
+NOTICE: trig_row_before(23, skidoo) BEFORE ROW UPDATE ON bar2
+NOTICE: OLD: (4,344,44),NEW: (4,444,44)
+NOTICE: trig_row_before(23, skidoo) BEFORE ROW UPDATE ON bar2
+NOTICE: OLD: (7,277,77),NEW: (7,377,77)
+NOTICE: trig_row_after(23, skidoo) AFTER ROW UPDATE ON bar2
+NOTICE: OLD: (3,333,33),NEW: (3,433,33)
+NOTICE: trig_row_after(23, skidoo) AFTER ROW UPDATE ON bar2
+NOTICE: OLD: (4,344,44),NEW: (4,444,44)
+NOTICE: trig_row_after(23, skidoo) AFTER ROW UPDATE ON bar2
+NOTICE: OLD: (7,277,77),NEW: (7,377,77)
+explain (verbose, costs off)
+delete from bar where f2 < 400;
+ QUERY PLAN
+---------------------------------------------------------------------------------------------
+ Delete on public.bar
+ Delete on public.bar
+ Foreign Delete on public.bar2
+ Remote SQL: DELETE FROM public.loct2 WHERE ctid = $1 RETURNING f1, f2, f3
+ -> Seq Scan on public.bar
+ Output: bar.ctid
+ Filter: (bar.f2 < 400)
+ -> Foreign Scan on public.bar2
+ Output: bar2.ctid, bar2.*
+ Remote SQL: SELECT f1, f2, f3, ctid FROM public.loct2 WHERE ((f2 < 400)) FOR UPDATE
+(10 rows)
+
+delete from bar where f2 < 400;
+NOTICE: trig_row_before(23, skidoo) BEFORE ROW DELETE ON bar2
+NOTICE: OLD: (7,377,77)
+NOTICE: trig_row_after(23, skidoo) AFTER ROW DELETE ON bar2
+NOTICE: OLD: (7,377,77)
+-- cleanup
drop table foo cascade;
NOTICE: drop cascades to foreign table foo2
drop table bar cascade;
@@ -7346,3 +7678,163 @@ AND ftoptions @> array['fetch_size=60000'];
(1 row)
ROLLBACK;
+-- ===================================================================
+-- test partitionwise joins
+-- ===================================================================
+SET enable_partitionwise_join=on;
+CREATE TABLE fprt1 (a int, b int, c varchar) PARTITION BY RANGE(a);
+CREATE TABLE fprt1_p1 (LIKE fprt1);
+CREATE TABLE fprt1_p2 (LIKE fprt1);
+INSERT INTO fprt1_p1 SELECT i, i, to_char(i/50, 'FM0000') FROM generate_series(0, 249, 2) i;
+INSERT INTO fprt1_p2 SELECT i, i, to_char(i/50, 'FM0000') FROM generate_series(250, 499, 2) i;
+CREATE FOREIGN TABLE ftprt1_p1 PARTITION OF fprt1 FOR VALUES FROM (0) TO (250)
+ SERVER loopback OPTIONS (table_name 'fprt1_p1', use_remote_estimate 'true');
+CREATE FOREIGN TABLE ftprt1_p2 PARTITION OF fprt1 FOR VALUES FROM (250) TO (500)
+ SERVER loopback OPTIONS (TABLE_NAME 'fprt1_p2');
+ANALYZE fprt1;
+ANALYZE fprt1_p1;
+ANALYZE fprt1_p2;
+CREATE TABLE fprt2 (a int, b int, c varchar) PARTITION BY RANGE(b);
+CREATE TABLE fprt2_p1 (LIKE fprt2);
+CREATE TABLE fprt2_p2 (LIKE fprt2);
+INSERT INTO fprt2_p1 SELECT i, i, to_char(i/50, 'FM0000') FROM generate_series(0, 249, 3) i;
+INSERT INTO fprt2_p2 SELECT i, i, to_char(i/50, 'FM0000') FROM generate_series(250, 499, 3) i;
+CREATE FOREIGN TABLE ftprt2_p1 PARTITION OF fprt2 FOR VALUES FROM (0) TO (250)
+ SERVER loopback OPTIONS (table_name 'fprt2_p1', use_remote_estimate 'true');
+CREATE FOREIGN TABLE ftprt2_p2 PARTITION OF fprt2 FOR VALUES FROM (250) TO (500)
+ SERVER loopback OPTIONS (table_name 'fprt2_p2', use_remote_estimate 'true');
+ANALYZE fprt2;
+ANALYZE fprt2_p1;
+ANALYZE fprt2_p2;
+-- inner join three tables
+EXPLAIN (COSTS OFF)
+SELECT t1.a,t2.b,t3.c FROM fprt1 t1 INNER JOIN fprt2 t2 ON (t1.a = t2.b) INNER JOIN fprt1 t3 ON (t2.b = t3.a) WHERE t1.a % 25 =0 ORDER BY 1,2,3;
+ QUERY PLAN
+--------------------------------------------------------------------------------------------------------------------
+ Sort
+ Sort Key: t1.a, t3.c
+ -> Append
+ -> Foreign Scan
+ Relations: ((public.ftprt1_p1 t1) INNER JOIN (public.ftprt2_p1 t2)) INNER JOIN (public.ftprt1_p1 t3)
+ -> Foreign Scan
+ Relations: ((public.ftprt1_p2 t1) INNER JOIN (public.ftprt2_p2 t2)) INNER JOIN (public.ftprt1_p2 t3)
+(7 rows)
+
+SELECT t1.a,t2.b,t3.c FROM fprt1 t1 INNER JOIN fprt2 t2 ON (t1.a = t2.b) INNER JOIN fprt1 t3 ON (t2.b = t3.a) WHERE t1.a % 25 =0 ORDER BY 1,2,3;
+ a | b | c
+-----+-----+------
+ 0 | 0 | 0000
+ 150 | 150 | 0003
+ 250 | 250 | 0005
+ 400 | 400 | 0008
+(4 rows)
+
+-- left outer join + nullable clasue
+EXPLAIN (COSTS OFF)
+SELECT t1.a,t2.b,t2.c FROM fprt1 t1 LEFT JOIN (SELECT * FROM fprt2 WHERE a < 10) t2 ON (t1.a = t2.b and t1.b = t2.a) WHERE t1.a < 10 ORDER BY 1,2,3;
+ QUERY PLAN
+-----------------------------------------------------------------------------------
+ Sort
+ Sort Key: t1.a, ftprt2_p1.b, ftprt2_p1.c
+ -> Append
+ -> Foreign Scan
+ Relations: (public.ftprt1_p1 t1) LEFT JOIN (public.ftprt2_p1 fprt2)
+(5 rows)
+
+SELECT t1.a,t2.b,t2.c FROM fprt1 t1 LEFT JOIN (SELECT * FROM fprt2 WHERE a < 10) t2 ON (t1.a = t2.b and t1.b = t2.a) WHERE t1.a < 10 ORDER BY 1,2,3;
+ a | b | c
+---+---+------
+ 0 | 0 | 0000
+ 2 | |
+ 4 | |
+ 6 | 6 | 0000
+ 8 | |
+(5 rows)
+
+-- with whole-row reference
+EXPLAIN (COSTS OFF)
+SELECT t1,t2 FROM fprt1 t1 JOIN fprt2 t2 ON (t1.a = t2.b and t1.b = t2.a) WHERE t1.a % 25 =0 ORDER BY 1,2;
+ QUERY PLAN
+---------------------------------------------------------------------------------
+ Sort
+ Sort Key: ((t1.*)::fprt1), ((t2.*)::fprt2)
+ -> Append
+ -> Foreign Scan
+ Relations: (public.ftprt1_p1 t1) INNER JOIN (public.ftprt2_p1 t2)
+ -> Foreign Scan
+ Relations: (public.ftprt1_p2 t1) INNER JOIN (public.ftprt2_p2 t2)
+(7 rows)
+
+SELECT t1,t2 FROM fprt1 t1 JOIN fprt2 t2 ON (t1.a = t2.b and t1.b = t2.a) WHERE t1.a % 25 =0 ORDER BY 1,2;
+ t1 | t2
+----------------+----------------
+ (0,0,0000) | (0,0,0000)
+ (150,150,0003) | (150,150,0003)
+ (250,250,0005) | (250,250,0005)
+ (400,400,0008) | (400,400,0008)
+(4 rows)
+
+-- join with lateral reference
+EXPLAIN (COSTS OFF)
+SELECT t1.a,t1.b FROM fprt1 t1, LATERAL (SELECT t2.a, t2.b FROM fprt2 t2 WHERE t1.a = t2.b AND t1.b = t2.a) q WHERE t1.a%25 = 0 ORDER BY 1,2;
+ QUERY PLAN
+---------------------------------------------------------------------------------
+ Sort
+ Sort Key: t1.a, t1.b
+ -> Append
+ -> Foreign Scan
+ Relations: (public.ftprt1_p1 t1) INNER JOIN (public.ftprt2_p1 t2)
+ -> Foreign Scan
+ Relations: (public.ftprt1_p2 t1) INNER JOIN (public.ftprt2_p2 t2)
+(7 rows)
+
+SELECT t1.a,t1.b FROM fprt1 t1, LATERAL (SELECT t2.a, t2.b FROM fprt2 t2 WHERE t1.a = t2.b AND t1.b = t2.a) q WHERE t1.a%25 = 0 ORDER BY 1,2;
+ a | b
+-----+-----
+ 0 | 0
+ 150 | 150
+ 250 | 250
+ 400 | 400
+(4 rows)
+
+-- with PHVs, partition-wise join selected but no join pushdown
+EXPLAIN (COSTS OFF)
+SELECT t1.a, t1.phv, t2.b, t2.phv FROM (SELECT 't1_phv' phv, * FROM fprt1 WHERE a % 25 = 0) t1 FULL JOIN (SELECT 't2_phv' phv, * FROM fprt2 WHERE b % 25 = 0) t2 ON (t1.a = t2.b) ORDER BY t1.a, t2.b;
+ QUERY PLAN
+------------------------------------------------------------
+ Sort
+ Sort Key: ftprt1_p1.a, ftprt2_p1.b
+ -> Result
+ -> Append
+ -> Hash Full Join
+ Hash Cond: (ftprt1_p1.a = ftprt2_p1.b)
+ -> Foreign Scan on ftprt1_p1
+ -> Hash
+ -> Foreign Scan on ftprt2_p1
+ -> Hash Full Join
+ Hash Cond: (ftprt1_p2.a = ftprt2_p2.b)
+ -> Foreign Scan on ftprt1_p2
+ -> Hash
+ -> Foreign Scan on ftprt2_p2
+(14 rows)
+
+SELECT t1.a, t1.phv, t2.b, t2.phv FROM (SELECT 't1_phv' phv, * FROM fprt1 WHERE a % 25 = 0) t1 FULL JOIN (SELECT 't2_phv' phv, * FROM fprt2 WHERE b % 25 = 0) t2 ON (t1.a = t2.b) ORDER BY t1.a, t2.b;
+ a | phv | b | phv
+-----+--------+-----+--------
+ 0 | t1_phv | 0 | t2_phv
+ 50 | t1_phv | |
+ 100 | t1_phv | |
+ 150 | t1_phv | 150 | t2_phv
+ 200 | t1_phv | |
+ 250 | t1_phv | 250 | t2_phv
+ 300 | t1_phv | |
+ 350 | t1_phv | |
+ 400 | t1_phv | 400 | t2_phv
+ 450 | t1_phv | |
+ | | 75 | t2_phv
+ | | 225 | t2_phv
+ | | 325 | t2_phv
+ | | 475 | t2_phv
+(14 rows)
+
+RESET enable_partitionwise_join;
diff --git a/contrib/postgres_fdw/option.c b/contrib/postgres_fdw/option.c
index 67e1c59951..082f79ae04 100644
--- a/contrib/postgres_fdw/option.c
+++ b/contrib/postgres_fdw/option.c
@@ -3,7 +3,7 @@
* option.c
* FDW option handling for postgres_fdw
*
- * Portions Copyright (c) 2012-2017, PostgreSQL Global Development Group
+ * Portions Copyright (c) 2012-2018, PostgreSQL Global Development Group
*
* IDENTIFICATION
* contrib/postgres_fdw/option.c
diff --git a/contrib/postgres_fdw/postgres_fdw.c b/contrib/postgres_fdw/postgres_fdw.c
index d77c2a70e4..e8a0d5482a 100644
--- a/contrib/postgres_fdw/postgres_fdw.c
+++ b/contrib/postgres_fdw/postgres_fdw.c
@@ -3,7 +3,7 @@
* postgres_fdw.c
* Foreign-data wrapper for remote PostgreSQL servers
*
- * Portions Copyright (c) 2012-2017, PostgreSQL Global Development Group
+ * Portions Copyright (c) 2012-2018, PostgreSQL Global Development Group
*
* IDENTIFICATION
* contrib/postgres_fdw/postgres_fdw.c
@@ -210,6 +210,11 @@ typedef struct PgFdwDirectModifyState
PGresult *result; /* result for query */
int num_tuples; /* # of result tuples */
int next_tuple; /* index of next one to return */
+ Relation resultRel; /* relcache entry for the target relation */
+ AttrNumber *attnoMap; /* array of attnums of input user columns */
+ AttrNumber ctidAttno; /* attnum of input ctid column */
+ AttrNumber oidAttno; /* attnum of input oid column */
+ bool hasSystemCols; /* are there system columns of resultRel? */
/* working memory context */
MemoryContext temp_cxt; /* context for per-tuple temporary data */
@@ -278,7 +283,7 @@ static void postgresGetForeignPaths(PlannerInfo *root,
RelOptInfo *baserel,
Oid foreigntableid);
static ForeignScan *postgresGetForeignPlan(PlannerInfo *root,
- RelOptInfo *baserel,
+ RelOptInfo *foreignrel,
Oid foreigntableid,
ForeignPath *best_path,
List *tlist,
@@ -353,8 +358,8 @@ static void postgresGetForeignUpperPaths(PlannerInfo *root,
* Helper functions
*/
static void estimate_path_cost_size(PlannerInfo *root,
- RelOptInfo *baserel,
- List *join_conds,
+ RelOptInfo *foreignrel,
+ List *param_join_conds,
List *pathkeys,
double *p_rows, int *p_width,
Cost *p_startup_cost, Cost *p_total_cost);
@@ -376,8 +381,17 @@ static const char **convert_prep_stmt_params(PgFdwModifyState *fmstate,
TupleTableSlot *slot);
static void store_returning_result(PgFdwModifyState *fmstate,
TupleTableSlot *slot, PGresult *res);
+static List *build_remote_returning(Index rtindex, Relation rel,
+ List *returningList);
+static void rebuild_fdw_scan_tlist(ForeignScan *fscan, List *tlist);
static void execute_dml_stmt(ForeignScanState *node);
static TupleTableSlot *get_returning_data(ForeignScanState *node);
+static void init_returning_filter(PgFdwDirectModifyState *dmstate,
+ List *fdw_scan_tlist,
+ Index rtindex);
+static TupleTableSlot *apply_returning_filter(PgFdwDirectModifyState *dmstate,
+ TupleTableSlot *slot,
+ EState *estate);
static void prepare_query_params(PlanState *node,
List *fdw_exprs,
int numParams,
@@ -1575,7 +1589,7 @@ postgresPlanForeignModify(PlannerInfo *root,
for (attnum = 1; attnum <= tupdesc->natts; attnum++)
{
- Form_pg_attribute attr = tupdesc->attrs[attnum - 1];
+ Form_pg_attribute attr = TupleDescAttr(tupdesc, attnum - 1);
if (!attr->attisdropped)
targetAttrs = lappend_int(targetAttrs, attnum);
@@ -1675,6 +1689,7 @@ postgresBeginForeignModify(ModifyTableState *mtstate,
Oid typefnoid;
bool isvarlena;
ListCell *lc;
+ TupleDesc tupdesc = RelationGetDescr(rel);
/*
* Do nothing in EXPLAIN (no ANALYZE) case. resultRelInfo->ri_FdwState
@@ -1719,7 +1734,7 @@ postgresBeginForeignModify(ModifyTableState *mtstate,
/* Prepare for input conversion of RETURNING results. */
if (fmstate->has_returning)
- fmstate->attinmeta = TupleDescGetAttInMetadata(RelationGetDescr(rel));
+ fmstate->attinmeta = TupleDescGetAttInMetadata(tupdesc);
/* Prepare for output conversion of parameters used in prepared stmt. */
n_params = list_length(fmstate->target_attrs) + 1;
@@ -1748,7 +1763,7 @@ postgresBeginForeignModify(ModifyTableState *mtstate,
foreach(lc, fmstate->target_attrs)
{
int attnum = lfirst_int(lc);
- Form_pg_attribute attr = RelationGetDescr(rel)->attrs[attnum - 1];
+ Form_pg_attribute attr = TupleDescAttr(tupdesc, attnum - 1);
Assert(!attr->attisdropped);
@@ -2143,14 +2158,15 @@ postgresPlanDirectModify(PlannerInfo *root,
if (subplan->qual != NIL)
return false;
- /*
- * We can't handle an UPDATE or DELETE on a foreign join for now.
- */
- if (fscan->scan.scanrelid == 0)
- return false;
-
/* Safe to fetch data about the target foreign rel */
- foreignrel = root->simple_rel_array[resultRelation];
+ if (fscan->scan.scanrelid == 0)
+ {
+ foreignrel = find_join_rel(root, fscan->fs_relids);
+ /* We should have a rel for this foreign join. */
+ Assert(foreignrel);
+ }
+ else
+ foreignrel = root->simple_rel_array[resultRelation];
rte = root->simple_rte_array[resultRelation];
fpinfo = (PgFdwRelationInfo *) foreignrel->fdw_private;
@@ -2211,8 +2227,23 @@ postgresPlanDirectModify(PlannerInfo *root,
* Extract the relevant RETURNING list if any.
*/
if (plan->returningLists)
+ {
returningList = (List *) list_nth(plan->returningLists, subplan_index);
+ /*
+ * When performing an UPDATE/DELETE .. RETURNING on a join directly,
+ * we fetch from the foreign server any Vars specified in RETURNING
+ * that refer not only to the target relation but to non-target
+ * relations. So we'll deparse them into the RETURNING clause of the
+ * remote query; use a targetlist consisting of them instead, which
+ * will be adjusted to be new fdw_scan_tlist of the foreign-scan plan
+ * node below.
+ */
+ if (fscan->scan.scanrelid == 0)
+ returningList = build_remote_returning(resultRelation, rel,
+ returningList);
+ }
+
/*
* Construct the SQL command string.
*/
@@ -2220,6 +2251,7 @@ postgresPlanDirectModify(PlannerInfo *root,
{
case CMD_UPDATE:
deparseDirectUpdateSql(&sql, root, resultRelation, rel,
+ foreignrel,
((Plan *) fscan)->targetlist,
targetAttrs,
remote_exprs, ¶ms_list,
@@ -2227,6 +2259,7 @@ postgresPlanDirectModify(PlannerInfo *root,
break;
case CMD_DELETE:
deparseDirectDeleteSql(&sql, root, resultRelation, rel,
+ foreignrel,
remote_exprs, ¶ms_list,
returningList, &retrieved_attrs);
break;
@@ -2254,6 +2287,19 @@ postgresPlanDirectModify(PlannerInfo *root,
retrieved_attrs,
makeInteger(plan->canSetTag));
+ /*
+ * Update the foreign-join-related fields.
+ */
+ if (fscan->scan.scanrelid == 0)
+ {
+ /* No need for the outer subplan. */
+ fscan->scan.plan.lefttree = NULL;
+
+ /* Build new fdw_scan_tlist if UPDATE/DELETE .. RETURNING. */
+ if (returningList)
+ rebuild_fdw_scan_tlist(fscan, returningList);
+ }
+
heap_close(rel, NoLock);
return true;
}
@@ -2268,6 +2314,7 @@ postgresBeginDirectModify(ForeignScanState *node, int eflags)
ForeignScan *fsplan = (ForeignScan *) node->ss.ps.plan;
EState *estate = node->ss.ps.state;
PgFdwDirectModifyState *dmstate;
+ Index rtindex;
RangeTblEntry *rte;
Oid userid;
ForeignTable *table;
@@ -2290,11 +2337,15 @@ postgresBeginDirectModify(ForeignScanState *node, int eflags)
* Identify which user to do the remote access as. This should match what
* ExecCheckRTEPerms() does.
*/
- rte = rt_fetch(fsplan->scan.scanrelid, estate->es_range_table);
+ rtindex = estate->es_result_relation_info->ri_RangeTableIndex;
+ rte = rt_fetch(rtindex, estate->es_range_table);
userid = rte->checkAsUser ? rte->checkAsUser : GetUserId();
/* Get info about foreign table. */
- dmstate->rel = node->ss.ss_currentRelation;
+ if (fsplan->scan.scanrelid == 0)
+ dmstate->rel = ExecOpenScanRelation(estate, rtindex, eflags);
+ else
+ dmstate->rel = node->ss.ss_currentRelation;
table = GetForeignTable(RelationGetRelid(dmstate->rel));
user = GetUserMapping(userid, table->serverid);
@@ -2304,6 +2355,21 @@ postgresBeginDirectModify(ForeignScanState *node, int eflags)
*/
dmstate->conn = GetConnection(user, false);
+ /* Update the foreign-join-related fields. */
+ if (fsplan->scan.scanrelid == 0)
+ {
+ /* Save info about foreign table. */
+ dmstate->resultRel = dmstate->rel;
+
+ /*
+ * Set dmstate->rel to NULL to teach get_returning_data() and
+ * make_tuple_from_result_row() that columns fetched from the remote
+ * server are described by fdw_scan_tlist of the foreign-scan plan
+ * node, not the tuple descriptor for the target relation.
+ */
+ dmstate->rel = NULL;
+ }
+
/* Initialize state variable */
dmstate->num_tuples = -1; /* -1 means not set yet */
@@ -2324,7 +2390,24 @@ postgresBeginDirectModify(ForeignScanState *node, int eflags)
/* Prepare for input conversion of RETURNING results. */
if (dmstate->has_returning)
- dmstate->attinmeta = TupleDescGetAttInMetadata(RelationGetDescr(dmstate->rel));
+ {
+ TupleDesc tupdesc;
+
+ if (fsplan->scan.scanrelid == 0)
+ tupdesc = node->ss.ss_ScanTupleSlot->tts_tupleDescriptor;
+ else
+ tupdesc = RelationGetDescr(dmstate->rel);
+
+ dmstate->attinmeta = TupleDescGetAttInMetadata(tupdesc);
+
+ /*
+ * When performing an UPDATE/DELETE .. RETURNING on a join directly,
+ * initialize a filter to extract an updated/deleted tuple from a scan
+ * tuple.
+ */
+ if (fsplan->scan.scanrelid == 0)
+ init_returning_filter(dmstate, fsplan->fdw_scan_tlist, rtindex);
+ }
/*
* Prepare for processing of parameters used in remote query, if any.
@@ -2405,6 +2488,10 @@ postgresEndDirectModify(ForeignScanState *node)
ReleaseConnection(dmstate->conn);
dmstate->conn = NULL;
+ /* close the target relation. */
+ if (dmstate->resultRel)
+ ExecCloseScanRelation(dmstate->resultRel);
+
/* MemoryContext will be deleted automatically. */
}
@@ -3271,6 +3358,136 @@ store_returning_result(PgFdwModifyState *fmstate,
PG_END_TRY();
}
+/*
+ * build_remote_returning
+ * Build a RETURNING targetlist of a remote query for performing an
+ * UPDATE/DELETE .. RETURNING on a join directly
+ */
+static List *
+build_remote_returning(Index rtindex, Relation rel, List *returningList)
+{
+ bool have_wholerow = false;
+ List *tlist = NIL;
+ List *vars;
+ ListCell *lc;
+
+ Assert(returningList);
+
+ vars = pull_var_clause((Node *) returningList, PVC_INCLUDE_PLACEHOLDERS);
+
+ /*
+ * If there's a whole-row reference to the target relation, then we'll
+ * need all the columns of the relation.
+ */
+ foreach(lc, vars)
+ {
+ Var *var = (Var *) lfirst(lc);
+
+ if (IsA(var, Var) &&
+ var->varno == rtindex &&
+ var->varattno == InvalidAttrNumber)
+ {
+ have_wholerow = true;
+ break;
+ }
+ }
+
+ if (have_wholerow)
+ {
+ TupleDesc tupdesc = RelationGetDescr(rel);
+ int i;
+
+ for (i = 1; i <= tupdesc->natts; i++)
+ {
+ Form_pg_attribute attr = TupleDescAttr(tupdesc, i - 1);
+ Var *var;
+
+ /* Ignore dropped attributes. */
+ if (attr->attisdropped)
+ continue;
+
+ var = makeVar(rtindex,
+ i,
+ attr->atttypid,
+ attr->atttypmod,
+ attr->attcollation,
+ 0);
+
+ tlist = lappend(tlist,
+ makeTargetEntry((Expr *) var,
+ list_length(tlist) + 1,
+ NULL,
+ false));
+ }
+ }
+
+ /* Now add any remaining columns to tlist. */
+ foreach(lc, vars)
+ {
+ Var *var = (Var *) lfirst(lc);
+
+ /*
+ * No need for whole-row references to the target relation. We don't
+ * need system columns other than ctid and oid either, since those are
+ * set locally.
+ */
+ if (IsA(var, Var) &&
+ var->varno == rtindex &&
+ var->varattno <= InvalidAttrNumber &&
+ var->varattno != SelfItemPointerAttributeNumber &&
+ var->varattno != ObjectIdAttributeNumber)
+ continue; /* don't need it */
+
+ if (tlist_member((Expr *) var, tlist))
+ continue; /* already got it */
+
+ tlist = lappend(tlist,
+ makeTargetEntry((Expr *) var,
+ list_length(tlist) + 1,
+ NULL,
+ false));
+ }
+
+ list_free(vars);
+
+ return tlist;
+}
+
+/*
+ * rebuild_fdw_scan_tlist
+ * Build new fdw_scan_tlist of given foreign-scan plan node from given
+ * tlist
+ *
+ * There might be columns that the fdw_scan_tlist of the given foreign-scan
+ * plan node contains that the given tlist doesn't. The fdw_scan_tlist would
+ * have contained resjunk columns such as 'ctid' of the target relation and
+ * 'wholerow' of non-target relations, but the tlist might not contain them,
+ * for example. So, adjust the tlist so it contains all the columns specified
+ * in the fdw_scan_tlist; else setrefs.c will get confused.
+ */
+static void
+rebuild_fdw_scan_tlist(ForeignScan *fscan, List *tlist)
+{
+ List *new_tlist = tlist;
+ List *old_tlist = fscan->fdw_scan_tlist;
+ ListCell *lc;
+
+ foreach(lc, old_tlist)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(lc);
+
+ if (tlist_member(tle->expr, new_tlist))
+ continue; /* already got it */
+
+ new_tlist = lappend(new_tlist,
+ makeTargetEntry(tle->expr,
+ list_length(new_tlist) + 1,
+ NULL,
+ false));
+ }
+ fscan->fdw_scan_tlist = new_tlist;
+}
+
/*
* Execute a direct UPDATE/DELETE statement.
*/
@@ -3331,6 +3548,7 @@ get_returning_data(ForeignScanState *node)
EState *estate = node->ss.ps.state;
ResultRelInfo *resultRelInfo = estate->es_result_relation_info;
TupleTableSlot *slot = node->ss.ss_ScanTupleSlot;
+ TupleTableSlot *resultSlot;
Assert(resultRelInfo->ri_projectReturning);
@@ -3348,7 +3566,10 @@ get_returning_data(ForeignScanState *node)
* "UPDATE/DELETE .. RETURNING 1" for example.)
*/
if (!dmstate->has_returning)
+ {
ExecStoreAllNullTuple(slot);
+ resultSlot = slot;
+ }
else
{
/*
@@ -3364,7 +3585,7 @@ get_returning_data(ForeignScanState *node)
dmstate->rel,
dmstate->attinmeta,
dmstate->retrieved_attrs,
- NULL,
+ node,
dmstate->temp_cxt);
ExecStoreTuple(newtup, slot, InvalidBuffer, false);
}
@@ -3375,15 +3596,204 @@ get_returning_data(ForeignScanState *node)
PG_RE_THROW();
}
PG_END_TRY();
+
+ /* Get the updated/deleted tuple. */
+ if (dmstate->rel)
+ resultSlot = slot;
+ else
+ resultSlot = apply_returning_filter(dmstate, slot, estate);
}
dmstate->next_tuple++;
/* Make slot available for evaluation of the local query RETURNING list. */
- resultRelInfo->ri_projectReturning->pi_exprContext->ecxt_scantuple = slot;
+ resultRelInfo->ri_projectReturning->pi_exprContext->ecxt_scantuple =
+ resultSlot;
return slot;
}
+/*
+ * Initialize a filter to extract an updated/deleted tuple from a scan tuple.
+ */
+static void
+init_returning_filter(PgFdwDirectModifyState *dmstate,
+ List *fdw_scan_tlist,
+ Index rtindex)
+{
+ TupleDesc resultTupType = RelationGetDescr(dmstate->resultRel);
+ ListCell *lc;
+ int i;
+
+ /*
+ * Calculate the mapping between the fdw_scan_tlist's entries and the
+ * result tuple's attributes.
+ *
+ * The "map" is an array of indexes of the result tuple's attributes in
+ * fdw_scan_tlist, i.e., one entry for every attribute of the result
+ * tuple. We store zero for any attributes that don't have the
+ * corresponding entries in that list, marking that a NULL is needed in
+ * the result tuple.
+ *
+ * Also get the indexes of the entries for ctid and oid if any.
+ */
+ dmstate->attnoMap = (AttrNumber *)
+ palloc0(resultTupType->natts * sizeof(AttrNumber));
+
+ dmstate->ctidAttno = dmstate->oidAttno = 0;
+
+ i = 1;
+ dmstate->hasSystemCols = false;
+ foreach(lc, fdw_scan_tlist)
+ {
+ TargetEntry *tle = (TargetEntry *) lfirst(lc);
+ Var *var = (Var *) tle->expr;
+
+ Assert(IsA(var, Var));
+
+ /*
+ * If the Var is a column of the target relation to be retrieved from
+ * the foreign server, get the index of the entry.
+ */
+ if (var->varno == rtindex &&
+ list_member_int(dmstate->retrieved_attrs, i))
+ {
+ int attrno = var->varattno;
+
+ if (attrno < 0)
+ {
+ /*
+ * We don't retrieve system columns other than ctid and oid.
+ */
+ if (attrno == SelfItemPointerAttributeNumber)
+ dmstate->ctidAttno = i;
+ else if (attrno == ObjectIdAttributeNumber)
+ dmstate->oidAttno = i;
+ else
+ Assert(false);
+ dmstate->hasSystemCols = true;
+ }
+ else
+ {
+ /*
+ * We don't retrieve whole-row references to the target
+ * relation either.
+ */
+ Assert(attrno > 0);
+
+ dmstate->attnoMap[attrno - 1] = i;
+ }
+ }
+ i++;
+ }
+}
+
+/*
+ * Extract and return an updated/deleted tuple from a scan tuple.
+ */
+static TupleTableSlot *
+apply_returning_filter(PgFdwDirectModifyState *dmstate,
+ TupleTableSlot *slot,
+ EState *estate)
+{
+ TupleDesc resultTupType = RelationGetDescr(dmstate->resultRel);
+ TupleTableSlot *resultSlot;
+ Datum *values;
+ bool *isnull;
+ Datum *old_values;
+ bool *old_isnull;
+ int i;
+
+ /*
+ * Use the trigger tuple slot as a place to store the result tuple.
+ */
+ resultSlot = estate->es_trig_tuple_slot;
+ if (resultSlot->tts_tupleDescriptor != resultTupType)
+ ExecSetSlotDescriptor(resultSlot, resultTupType);
+
+ /*
+ * Extract all the values of the scan tuple.
+ */
+ slot_getallattrs(slot);
+ old_values = slot->tts_values;
+ old_isnull = slot->tts_isnull;
+
+ /*
+ * Prepare to build the result tuple.
+ */
+ ExecClearTuple(resultSlot);
+ values = resultSlot->tts_values;
+ isnull = resultSlot->tts_isnull;
+
+ /*
+ * Transpose data into proper fields of the result tuple.
+ */
+ for (i = 0; i < resultTupType->natts; i++)
+ {
+ int j = dmstate->attnoMap[i];
+
+ if (j == 0)
+ {
+ values[i] = (Datum) 0;
+ isnull[i] = true;
+ }
+ else
+ {
+ values[i] = old_values[j - 1];
+ isnull[i] = old_isnull[j - 1];
+ }
+ }
+
+ /*
+ * Build the virtual tuple.
+ */
+ ExecStoreVirtualTuple(resultSlot);
+
+ /*
+ * If we have any system columns to return, install them.
+ */
+ if (dmstate->hasSystemCols)
+ {
+ HeapTuple resultTup = ExecMaterializeSlot(resultSlot);
+
+ /* ctid */
+ if (dmstate->ctidAttno)
+ {
+ ItemPointer ctid = NULL;
+
+ ctid = (ItemPointer) DatumGetPointer(old_values[dmstate->ctidAttno - 1]);
+ resultTup->t_self = *ctid;
+ }
+
+ /* oid */
+ if (dmstate->oidAttno)
+ {
+ Oid oid = InvalidOid;
+
+ oid = DatumGetObjectId(old_values[dmstate->oidAttno - 1]);
+ HeapTupleSetOid(resultTup, oid);
+ }
+
+ /*
+ * And remaining columns
+ *
+ * Note: since we currently don't allow the target relation to appear
+ * on the nullable side of an outer join, any system columns wouldn't
+ * go to NULL.
+ *
+ * Note: no need to care about tableoid here because it will be
+ * initialized in ExecProcessReturning().
+ */
+ HeapTupleHeaderSetXmin(resultTup->t_data, InvalidTransactionId);
+ HeapTupleHeaderSetXmax(resultTup->t_data, InvalidTransactionId);
+ HeapTupleHeaderSetCmin(resultTup->t_data, InvalidTransactionId);
+ }
+
+ /*
+ * And return the result tuple.
+ */
+ return resultSlot;
+}
+
/*
* Prepare for processing of parameters used in remote query.
*/
@@ -4155,7 +4565,11 @@ foreign_join_ok(PlannerInfo *root, RelOptInfo *joinrel, JoinType jointype,
foreach(lc, root->placeholder_list)
{
PlaceHolderInfo *phinfo = lfirst(lc);
- Relids relids = joinrel->relids;
+ Relids relids;
+
+ /* PlaceHolderInfo refers to parent relids, not child relids. */
+ relids = IS_OTHER_REL(joinrel) ?
+ joinrel->top_parent_relids : joinrel->relids;
if (bms_is_subset(phinfo->ph_eval_at, relids) &&
bms_nonempty_difference(relids, phinfo->ph_eval_at))
@@ -4329,10 +4743,26 @@ add_paths_with_pathkeys_for_rel(PlannerInfo *root, RelOptInfo *rel,
Cost startup_cost;
Cost total_cost;
List *useful_pathkeys = lfirst(lc);
+ Path *sorted_epq_path;
estimate_path_cost_size(root, rel, NIL, useful_pathkeys,
&rows, &width, &startup_cost, &total_cost);
+ /*
+ * The EPQ path must be at least as well sorted as the path itself,
+ * in case it gets used as input to a mergejoin.
+ */
+ sorted_epq_path = epq_path;
+ if (sorted_epq_path != NULL &&
+ !pathkeys_contained_in(useful_pathkeys,
+ sorted_epq_path->pathkeys))
+ sorted_epq_path = (Path *)
+ create_sort_path(root,
+ rel,
+ sorted_epq_path,
+ useful_pathkeys,
+ -1.0);
+
add_path(rel, (Path *)
create_foreignscan_path(root, rel,
NULL,
@@ -4341,7 +4771,7 @@ add_paths_with_pathkeys_for_rel(PlannerInfo *root, RelOptInfo *rel,
total_cost,
useful_pathkeys,
NULL,
- epq_path,
+ sorted_epq_path,
NIL));
}
}
@@ -4497,7 +4927,6 @@ postgresGetForeignJoinPaths(PlannerInfo *root,
* the path list of the joinrel, if one exists. We must be careful to
* call it before adding any ForeignPath, since the ForeignPath might
* dominate the only suitable local path available. We also do it before
- * reconstruct the row for EvalPlanQual(). Find an alternative local path
* calling foreign_join_ok(), since that function updates fpinfo and marks
* it as pushable if the join is found to be pushable.
*/
@@ -4591,7 +5020,7 @@ static bool
foreign_grouping_ok(PlannerInfo *root, RelOptInfo *grouped_rel)
{
Query *query = root->parse;
- PathTarget *grouping_target;
+ PathTarget *grouping_target = root->upper_targets[UPPERREL_GROUP_AGG];
PgFdwRelationInfo *fpinfo = (PgFdwRelationInfo *) grouped_rel->fdw_private;
PgFdwRelationInfo *ofpinfo;
List *aggvars;
@@ -4599,7 +5028,7 @@ foreign_grouping_ok(PlannerInfo *root, RelOptInfo *grouped_rel)
int i;
List *tlist = NIL;
- /* Grouping Sets are not pushable */
+ /* We currently don't support pushing Grouping Sets. */
if (query->groupingSets)
return false;
@@ -4607,7 +5036,7 @@ foreign_grouping_ok(PlannerInfo *root, RelOptInfo *grouped_rel)
ofpinfo = (PgFdwRelationInfo *) fpinfo->outerrel->fdw_private;
/*
- * If underneath input relation has any local conditions, those conditions
+ * If underlying scan relation has any local conditions, those conditions
* are required to be applied before performing aggregation. Hence the
* aggregate cannot be pushed down.
*/
@@ -4615,21 +5044,11 @@ foreign_grouping_ok(PlannerInfo *root, RelOptInfo *grouped_rel)
return false;
/*
- * The targetlist expected from this node and the targetlist pushed down
- * to the foreign server may be different. The latter requires
- * sortgrouprefs to be set to push down GROUP BY clause, but should not
- * have those arising from ORDER BY clause. These sortgrouprefs may be
- * different from those in the plan's targetlist. Use a copy of path
- * target to record the new sortgrouprefs.
- */
- grouping_target = copy_pathtarget(root->upper_targets[UPPERREL_GROUP_AGG]);
-
- /*
- * Evaluate grouping targets and check whether they are safe to push down
- * to the foreign side. All GROUP BY expressions will be part of the
- * grouping target and thus there is no need to evaluate it separately.
- * While doing so, add required expressions into target list which can
- * then be used to pass to foreign server.
+ * Examine grouping expressions, as well as other expressions we'd need to
+ * compute, and check whether they are safe to push down to the foreign
+ * server. All GROUP BY expressions will be part of the grouping target
+ * and thus there is no need to search for them separately. Add grouping
+ * expressions into target list which will be passed to foreign server.
*/
i = 0;
foreach(lc, grouping_target->exprs)
@@ -4641,51 +5060,59 @@ foreign_grouping_ok(PlannerInfo *root, RelOptInfo *grouped_rel)
/* Check whether this expression is part of GROUP BY clause */
if (sgref && get_sortgroupref_clause_noerr(sgref, query->groupClause))
{
+ TargetEntry *tle;
+
/*
- * If any of the GROUP BY expression is not shippable we can not
+ * If any GROUP BY expression is not shippable, then we cannot
* push down aggregation to the foreign server.
*/
if (!is_foreign_expr(root, grouped_rel, expr))
return false;
- /* Pushable, add to tlist */
- tlist = add_to_flat_tlist(tlist, list_make1(expr));
+ /*
+ * Pushable, so add to tlist. We need to create a TLE for this
+ * expression and apply the sortgroupref to it. We cannot use
+ * add_to_flat_tlist() here because that avoids making duplicate
+ * entries in the tlist. If there are duplicate entries with
+ * distinct sortgrouprefs, we have to duplicate that situation in
+ * the output tlist.
+ */
+ tle = makeTargetEntry(expr, list_length(tlist) + 1, NULL, false);
+ tle->ressortgroupref = sgref;
+ tlist = lappend(tlist, tle);
}
else
{
- /* Check entire expression whether it is pushable or not */
+ /*
+ * Non-grouping expression we need to compute. Is it shippable?
+ */
if (is_foreign_expr(root, grouped_rel, expr))
{
- /* Pushable, add to tlist */
+ /* Yes, so add to tlist as-is; OK to suppress duplicates */
tlist = add_to_flat_tlist(tlist, list_make1(expr));
}
else
{
- /*
- * If we have sortgroupref set, then it means that we have an
- * ORDER BY entry pointing to this expression. Since we are
- * not pushing ORDER BY with GROUP BY, clear it.
- */
- if (sgref)
- grouping_target->sortgrouprefs[i] = 0;
-
- /* Not matched exactly, pull the var with aggregates then */
+ /* Not pushable as a whole; extract its Vars and aggregates */
aggvars = pull_var_clause((Node *) expr,
PVC_INCLUDE_AGGREGATES);
+ /*
+ * If any aggregate expression is not shippable, then we
+ * cannot push down aggregation to the foreign server.
+ */
if (!is_foreign_expr(root, grouped_rel, (Expr *) aggvars))
return false;
/*
- * Add aggregates, if any, into the targetlist. Plain var
- * nodes should be either same as some GROUP BY expression or
- * part of some GROUP BY expression. In later case, the query
- * cannot refer plain var nodes without the surrounding
- * expression. In both the cases, they are already part of
+ * Add aggregates, if any, into the targetlist. Plain Vars
+ * outside an aggregate can be ignored, because they should be
+ * either same as some GROUP BY column or part of some GROUP
+ * BY expression. In either case, they are already part of
* the targetlist and thus no need to add them again. In fact
- * adding pulled plain var nodes in SELECT clause will cause
- * an error on the foreign server if they are not same as some
- * GROUP BY expression.
+ * including plain Vars in the tlist when they do not match a
+ * GROUP BY column would cause the foreign server to complain
+ * that the shipped query is invalid.
*/
foreach(l, aggvars)
{
@@ -4701,7 +5128,7 @@ foreign_grouping_ok(PlannerInfo *root, RelOptInfo *grouped_rel)
}
/*
- * Classify the pushable and non-pushable having clauses and save them in
+ * Classify the pushable and non-pushable HAVING clauses and save them in
* remote_conds and local_conds of the grouped rel's fpinfo.
*/
if (root->hasHavingQual && query->havingQual)
@@ -4771,9 +5198,6 @@ foreign_grouping_ok(PlannerInfo *root, RelOptInfo *grouped_rel)
}
}
- /* Transfer any sortgroupref data to the replacement tlist */
- apply_pathtarget_labeling_to_tlist(tlist, grouping_target);
-
/* Store generated targetlist */
fpinfo->grouped_tlist = tlist;
@@ -4943,11 +5367,8 @@ make_tuple_from_result_row(PGresult *res,
tupdesc = RelationGetDescr(rel);
else
{
- PgFdwScanState *fdw_sstate;
-
Assert(fsstate);
- fdw_sstate = (PgFdwScanState *) fsstate->fdw_state;
- tupdesc = fdw_sstate->tupdesc;
+ tupdesc = fsstate->ss.ss_ScanTupleSlot->tts_tupleDescriptor;
}
values = (Datum *) palloc0(tupdesc->natts * sizeof(Datum));
@@ -5091,9 +5512,10 @@ conversion_error_callback(void *arg)
{
/* error occurred in a scan against a foreign table */
TupleDesc tupdesc = RelationGetDescr(errpos->rel);
+ Form_pg_attribute attr = TupleDescAttr(tupdesc, errpos->cur_attno - 1);
if (errpos->cur_attno > 0 && errpos->cur_attno <= tupdesc->natts)
- attname = NameStr(tupdesc->attrs[errpos->cur_attno - 1]->attname);
+ attname = NameStr(attr->attname);
else if (errpos->cur_attno == SelfItemPointerAttributeNumber)
attname = "ctid";
else if (errpos->cur_attno == ObjectIdAttributeNumber)
@@ -5114,7 +5536,7 @@ conversion_error_callback(void *arg)
/*
* Target list can have Vars and expressions. For Vars, we can get
- * it's relation, however for expressions we can't. Thus for
+ * its relation, however for expressions we can't. Thus for
* expressions, just show generic context message.
*/
if (IsA(tle->expr, Var))
@@ -5127,7 +5549,7 @@ conversion_error_callback(void *arg)
if (var->varattno == 0)
is_wholerow = true;
else
- attname = get_relid_attribute_name(rte->relid, var->varattno);
+ attname = get_attname(rte->relid, var->varattno, false);
relname = get_rel_name(rte->relid);
}
@@ -5149,7 +5571,7 @@ conversion_error_callback(void *arg)
* Find an equivalence class member expression, all of whose Vars, come from
* the indicated relation.
*/
-extern Expr *
+Expr *
find_em_expr_for_rel(EquivalenceClass *ec, RelOptInfo *rel)
{
ListCell *lc_em;
diff --git a/contrib/postgres_fdw/postgres_fdw.h b/contrib/postgres_fdw/postgres_fdw.h
index 788b003650..d37cc88b6e 100644
--- a/contrib/postgres_fdw/postgres_fdw.h
+++ b/contrib/postgres_fdw/postgres_fdw.h
@@ -3,7 +3,7 @@
* postgres_fdw.h
* Foreign-data wrapper for remote PostgreSQL servers
*
- * Portions Copyright (c) 2012-2017, PostgreSQL Global Development Group
+ * Portions Copyright (c) 2012-2018, PostgreSQL Global Development Group
*
* IDENTIFICATION
* contrib/postgres_fdw/postgres_fdw.h
@@ -150,6 +150,7 @@ extern void deparseUpdateSql(StringInfo buf, PlannerInfo *root,
List **retrieved_attrs);
extern void deparseDirectUpdateSql(StringInfo buf, PlannerInfo *root,
Index rtindex, Relation rel,
+ RelOptInfo *foreignrel,
List *targetlist,
List *targetAttrs,
List *remote_conds,
@@ -162,6 +163,7 @@ extern void deparseDeleteSql(StringInfo buf, PlannerInfo *root,
List **retrieved_attrs);
extern void deparseDirectDeleteSql(StringInfo buf, PlannerInfo *root,
Index rtindex, Relation rel,
+ RelOptInfo *foreignrel,
List *remote_conds,
List **params_list,
List *returningList,
diff --git a/contrib/postgres_fdw/shippable.c b/contrib/postgres_fdw/shippable.c
index 2ac0873caa..7f2ed0499c 100644
--- a/contrib/postgres_fdw/shippable.c
+++ b/contrib/postgres_fdw/shippable.c
@@ -13,7 +13,7 @@
* functions or functions using nonportable collations. Those considerations
* need not be accounted for here.
*
- * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
*
* IDENTIFICATION
* contrib/postgres_fdw/shippable.c
diff --git a/contrib/postgres_fdw/sql/postgres_fdw.sql b/contrib/postgres_fdw/sql/postgres_fdw.sql
index 5f65d9d966..7f4d0dab25 100644
--- a/contrib/postgres_fdw/sql/postgres_fdw.sql
+++ b/contrib/postgres_fdw/sql/postgres_fdw.sql
@@ -39,6 +39,9 @@ CREATE TABLE "S 1"."T 1" (
c8 user_enum,
CONSTRAINT t1_pkey PRIMARY KEY ("C 1")
);
+-- "S 1"."T 1" will be heavily updated below, so disable autovacuum for
+-- the table to avoid unexpected effects of that
+ALTER TABLE "S 1"."T 1" SET (autovacuum_enabled = 'false');
CREATE TABLE "S 1"."T 2" (
c1 int NOT NULL,
c2 text,
@@ -559,8 +562,20 @@ EXPLAIN (VERBOSE, COSTS OFF)
SELECT ft5, ft5.c1, ft5.c2, ft5.c3, ft4.c1, ft4.c2 FROM ft5 left join ft4 on ft5.c1 = ft4.c1 WHERE ft4.c1 BETWEEN 10 and 30 ORDER BY ft5.c1, ft4.c1;
SELECT ft5, ft5.c1, ft5.c2, ft5.c3, ft4.c1, ft4.c2 FROM ft5 left join ft4 on ft5.c1 = ft4.c1 WHERE ft4.c1 BETWEEN 10 and 30 ORDER BY ft5.c1, ft4.c1;
+-- multi-way join involving multiple merge joins
+-- (this case used to have EPQ-related planning problems)
+SET enable_nestloop TO false;
+SET enable_hashjoin TO false;
+EXPLAIN (VERBOSE, COSTS OFF)
+SELECT * FROM ft1, ft2, ft4, ft5 WHERE ft1.c1 = ft2.c1 AND ft1.c2 = ft4.c1
+ AND ft1.c2 = ft5.c1 AND ft1.c1 < 100 AND ft2.c1 < 100 FOR UPDATE;
+SELECT * FROM ft1, ft2, ft4, ft5 WHERE ft1.c1 = ft2.c1 AND ft1.c2 = ft4.c1
+ AND ft1.c2 = ft5.c1 AND ft1.c1 < 100 AND ft2.c1 < 100 FOR UPDATE;
+RESET enable_nestloop;
+RESET enable_hashjoin;
+
-- check join pushdown in situations where multiple userids are involved
-CREATE ROLE regress_view_owner;
+CREATE ROLE regress_view_owner SUPERUSER;
CREATE USER MAPPING FOR regress_view_owner SERVER loopback;
GRANT SELECT ON ft4 TO regress_view_owner;
GRANT SELECT ON ft5 TO regress_view_owner;
@@ -636,6 +651,12 @@ explain (verbose, costs off)
select count(c2) w, c2 x, 5 y, 7.0 z from ft1 group by 2, y, 9.0::int order by 2;
select count(c2) w, c2 x, 5 y, 7.0 z from ft1 group by 2, y, 9.0::int order by 2;
+-- GROUP BY clause referring to same column multiple times
+-- Also, ORDER BY contains an aggregate function
+explain (verbose, costs off)
+select c2, c2 from ft1 where c2 > 6 group by 1, 2 order by sum(c1);
+select c2, c2 from ft1 where c2 > 6 group by 1, 2 order by sum(c1);
+
-- Testing HAVING clause shippability
explain (verbose, costs off)
select c2, sum(c1) from ft2 group by c2 having avg(c1) < 500 and sum(c1) < 49800 order by c2;
@@ -829,7 +850,7 @@ drop operator public.<^(int, int);
-- Input relation to aggregate push down hook is not safe to pushdown and thus
-- the aggregate cannot be pushed down to foreign server.
explain (verbose, costs off)
-select count(t1.c3) from ft1 t1, ft1 t2 where t1.c1 = postgres_fdw_abs(t1.c2);
+select count(t1.c3) from ft2 t1 left join ft2 t2 on (t1.c1 = random() * t2.c2);
-- Subquery in FROM clause having aggregate
explain (verbose, costs off)
@@ -1064,14 +1085,14 @@ UPDATE ft2 SET c2 = c2 + 400, c3 = c3 || '_update7' WHERE c1 % 10 = 7 RETURNING
UPDATE ft2 SET c2 = c2 + 400, c3 = c3 || '_update7' WHERE c1 % 10 = 7 RETURNING *;
EXPLAIN (verbose, costs off)
UPDATE ft2 SET c2 = ft2.c2 + 500, c3 = ft2.c3 || '_update9', c7 = DEFAULT
- FROM ft1 WHERE ft1.c1 = ft2.c2 AND ft1.c1 % 10 = 9; -- can't be pushed down
+ FROM ft1 WHERE ft1.c1 = ft2.c2 AND ft1.c1 % 10 = 9; -- can be pushed down
UPDATE ft2 SET c2 = ft2.c2 + 500, c3 = ft2.c3 || '_update9', c7 = DEFAULT
FROM ft1 WHERE ft1.c1 = ft2.c2 AND ft1.c1 % 10 = 9;
EXPLAIN (verbose, costs off)
DELETE FROM ft2 WHERE c1 % 10 = 5 RETURNING c1, c4; -- can be pushed down
DELETE FROM ft2 WHERE c1 % 10 = 5 RETURNING c1, c4;
EXPLAIN (verbose, costs off)
-DELETE FROM ft2 USING ft1 WHERE ft1.c1 = ft2.c2 AND ft1.c1 % 10 = 2; -- can't be pushed down
+DELETE FROM ft2 USING ft1 WHERE ft1.c1 = ft2.c2 AND ft1.c1 % 10 = 2; -- can be pushed down
DELETE FROM ft2 USING ft1 WHERE ft1.c1 = ft2.c2 AND ft1.c1 % 10 = 2;
SELECT c1,c2,c3,c4 FROM ft2 ORDER BY c1;
EXPLAIN (verbose, costs off)
@@ -1084,6 +1105,58 @@ EXPLAIN (verbose, costs off)
DELETE FROM ft2 WHERE c1 = 9999 RETURNING tableoid::regclass; -- can be pushed down
DELETE FROM ft2 WHERE c1 = 9999 RETURNING tableoid::regclass;
+-- Test UPDATE/DELETE with RETURNING on a three-table join
+INSERT INTO ft2 (c1,c2,c3)
+ SELECT id, id - 1200, to_char(id, 'FM00000') FROM generate_series(1201, 1300) id;
+EXPLAIN (verbose, costs off)
+UPDATE ft2 SET c3 = 'foo'
+ FROM ft4 INNER JOIN ft5 ON (ft4.c1 = ft5.c1)
+ WHERE ft2.c1 > 1200 AND ft2.c2 = ft4.c1
+ RETURNING ft2, ft2.*, ft4, ft4.*; -- can be pushed down
+UPDATE ft2 SET c3 = 'foo'
+ FROM ft4 INNER JOIN ft5 ON (ft4.c1 = ft5.c1)
+ WHERE ft2.c1 > 1200 AND ft2.c2 = ft4.c1
+ RETURNING ft2, ft2.*, ft4, ft4.*;
+EXPLAIN (verbose, costs off)
+DELETE FROM ft2
+ USING ft4 LEFT JOIN ft5 ON (ft4.c1 = ft5.c1)
+ WHERE ft2.c1 > 1200 AND ft2.c1 % 10 = 0 AND ft2.c2 = ft4.c1
+ RETURNING 100; -- can be pushed down
+DELETE FROM ft2
+ USING ft4 LEFT JOIN ft5 ON (ft4.c1 = ft5.c1)
+ WHERE ft2.c1 > 1200 AND ft2.c1 % 10 = 0 AND ft2.c2 = ft4.c1
+ RETURNING 100;
+DELETE FROM ft2 WHERE ft2.c1 > 1200;
+
+-- Test UPDATE/DELETE with WHERE or JOIN/ON conditions containing
+-- user-defined operators/functions
+ALTER SERVER loopback OPTIONS (DROP extensions);
+INSERT INTO ft2 (c1,c2,c3)
+ SELECT id, id % 10, to_char(id, 'FM00000') FROM generate_series(2001, 2010) id;
+EXPLAIN (verbose, costs off)
+UPDATE ft2 SET c3 = 'bar' WHERE postgres_fdw_abs(c1) > 2000 RETURNING *; -- can't be pushed down
+UPDATE ft2 SET c3 = 'bar' WHERE postgres_fdw_abs(c1) > 2000 RETURNING *;
+EXPLAIN (verbose, costs off)
+UPDATE ft2 SET c3 = 'baz'
+ FROM ft4 INNER JOIN ft5 ON (ft4.c1 = ft5.c1)
+ WHERE ft2.c1 > 2000 AND ft2.c2 === ft4.c1
+ RETURNING ft2.*, ft4.*, ft5.*; -- can't be pushed down
+UPDATE ft2 SET c3 = 'baz'
+ FROM ft4 INNER JOIN ft5 ON (ft4.c1 = ft5.c1)
+ WHERE ft2.c1 > 2000 AND ft2.c2 === ft4.c1
+ RETURNING ft2.*, ft4.*, ft5.*;
+EXPLAIN (verbose, costs off)
+DELETE FROM ft2
+ USING ft4 INNER JOIN ft5 ON (ft4.c1 === ft5.c1)
+ WHERE ft2.c1 > 2000 AND ft2.c2 = ft4.c1
+ RETURNING ft2.c1, ft2.c2, ft2.c3; -- can't be pushed down
+DELETE FROM ft2
+ USING ft4 INNER JOIN ft5 ON (ft4.c1 === ft5.c1)
+ WHERE ft2.c1 > 2000 AND ft2.c2 = ft4.c1
+ RETURNING ft2.c1, ft2.c2, ft2.c3;
+DELETE FROM ft2 WHERE ft2.c1 > 2000;
+ALTER SERVER loopback OPTIONS (ADD extensions 'postgres_fdw');
+
-- Test that trigger on remote table works as expected
CREATE OR REPLACE FUNCTION "S 1".F_BRTRIG() RETURNS trigger AS $$
BEGIN
@@ -1138,6 +1211,8 @@ commit;
select c2, count(*) from ft2 where c2 < 500 group by 1 order by 1;
select c2, count(*) from "S 1"."T 1" where c2 < 500 group by 1 order by 1;
+VACUUM ANALYZE "S 1"."T 1";
+
-- Above DMLs add data with c6 as NULL in ft1, so test ORDER BY NULLS LAST and NULLs
-- FIRST behavior here.
-- ORDER BY DESC NULLS LAST options
@@ -1656,6 +1731,24 @@ explain (verbose, costs off)
update bar set f2 = f2 + 100 returning *;
update bar set f2 = f2 + 100 returning *;
+-- Test that UPDATE/DELETE with inherited target works with row-level triggers
+CREATE TRIGGER trig_row_before
+BEFORE UPDATE OR DELETE ON bar2
+FOR EACH ROW EXECUTE PROCEDURE trigger_data(23,'skidoo');
+
+CREATE TRIGGER trig_row_after
+AFTER UPDATE OR DELETE ON bar2
+FOR EACH ROW EXECUTE PROCEDURE trigger_data(23,'skidoo');
+
+explain (verbose, costs off)
+update bar set f2 = f2 + 100;
+update bar set f2 = f2 + 100;
+
+explain (verbose, costs off)
+delete from bar where f2 < 400;
+delete from bar where f2 < 400;
+
+-- cleanup
drop table foo cascade;
drop table bar cascade;
drop table loct1;
@@ -1764,3 +1857,61 @@ WHERE ftrelid = 'table30000'::regclass
AND ftoptions @> array['fetch_size=60000'];
ROLLBACK;
+
+-- ===================================================================
+-- test partitionwise joins
+-- ===================================================================
+SET enable_partitionwise_join=on;
+
+CREATE TABLE fprt1 (a int, b int, c varchar) PARTITION BY RANGE(a);
+CREATE TABLE fprt1_p1 (LIKE fprt1);
+CREATE TABLE fprt1_p2 (LIKE fprt1);
+INSERT INTO fprt1_p1 SELECT i, i, to_char(i/50, 'FM0000') FROM generate_series(0, 249, 2) i;
+INSERT INTO fprt1_p2 SELECT i, i, to_char(i/50, 'FM0000') FROM generate_series(250, 499, 2) i;
+CREATE FOREIGN TABLE ftprt1_p1 PARTITION OF fprt1 FOR VALUES FROM (0) TO (250)
+ SERVER loopback OPTIONS (table_name 'fprt1_p1', use_remote_estimate 'true');
+CREATE FOREIGN TABLE ftprt1_p2 PARTITION OF fprt1 FOR VALUES FROM (250) TO (500)
+ SERVER loopback OPTIONS (TABLE_NAME 'fprt1_p2');
+ANALYZE fprt1;
+ANALYZE fprt1_p1;
+ANALYZE fprt1_p2;
+
+CREATE TABLE fprt2 (a int, b int, c varchar) PARTITION BY RANGE(b);
+CREATE TABLE fprt2_p1 (LIKE fprt2);
+CREATE TABLE fprt2_p2 (LIKE fprt2);
+INSERT INTO fprt2_p1 SELECT i, i, to_char(i/50, 'FM0000') FROM generate_series(0, 249, 3) i;
+INSERT INTO fprt2_p2 SELECT i, i, to_char(i/50, 'FM0000') FROM generate_series(250, 499, 3) i;
+CREATE FOREIGN TABLE ftprt2_p1 PARTITION OF fprt2 FOR VALUES FROM (0) TO (250)
+ SERVER loopback OPTIONS (table_name 'fprt2_p1', use_remote_estimate 'true');
+CREATE FOREIGN TABLE ftprt2_p2 PARTITION OF fprt2 FOR VALUES FROM (250) TO (500)
+ SERVER loopback OPTIONS (table_name 'fprt2_p2', use_remote_estimate 'true');
+ANALYZE fprt2;
+ANALYZE fprt2_p1;
+ANALYZE fprt2_p2;
+
+-- inner join three tables
+EXPLAIN (COSTS OFF)
+SELECT t1.a,t2.b,t3.c FROM fprt1 t1 INNER JOIN fprt2 t2 ON (t1.a = t2.b) INNER JOIN fprt1 t3 ON (t2.b = t3.a) WHERE t1.a % 25 =0 ORDER BY 1,2,3;
+SELECT t1.a,t2.b,t3.c FROM fprt1 t1 INNER JOIN fprt2 t2 ON (t1.a = t2.b) INNER JOIN fprt1 t3 ON (t2.b = t3.a) WHERE t1.a % 25 =0 ORDER BY 1,2,3;
+
+-- left outer join + nullable clasue
+EXPLAIN (COSTS OFF)
+SELECT t1.a,t2.b,t2.c FROM fprt1 t1 LEFT JOIN (SELECT * FROM fprt2 WHERE a < 10) t2 ON (t1.a = t2.b and t1.b = t2.a) WHERE t1.a < 10 ORDER BY 1,2,3;
+SELECT t1.a,t2.b,t2.c FROM fprt1 t1 LEFT JOIN (SELECT * FROM fprt2 WHERE a < 10) t2 ON (t1.a = t2.b and t1.b = t2.a) WHERE t1.a < 10 ORDER BY 1,2,3;
+
+-- with whole-row reference
+EXPLAIN (COSTS OFF)
+SELECT t1,t2 FROM fprt1 t1 JOIN fprt2 t2 ON (t1.a = t2.b and t1.b = t2.a) WHERE t1.a % 25 =0 ORDER BY 1,2;
+SELECT t1,t2 FROM fprt1 t1 JOIN fprt2 t2 ON (t1.a = t2.b and t1.b = t2.a) WHERE t1.a % 25 =0 ORDER BY 1,2;
+
+-- join with lateral reference
+EXPLAIN (COSTS OFF)
+SELECT t1.a,t1.b FROM fprt1 t1, LATERAL (SELECT t2.a, t2.b FROM fprt2 t2 WHERE t1.a = t2.b AND t1.b = t2.a) q WHERE t1.a%25 = 0 ORDER BY 1,2;
+SELECT t1.a,t1.b FROM fprt1 t1, LATERAL (SELECT t2.a, t2.b FROM fprt2 t2 WHERE t1.a = t2.b AND t1.b = t2.a) q WHERE t1.a%25 = 0 ORDER BY 1,2;
+
+-- with PHVs, partition-wise join selected but no join pushdown
+EXPLAIN (COSTS OFF)
+SELECT t1.a, t1.phv, t2.b, t2.phv FROM (SELECT 't1_phv' phv, * FROM fprt1 WHERE a % 25 = 0) t1 FULL JOIN (SELECT 't2_phv' phv, * FROM fprt2 WHERE b % 25 = 0) t2 ON (t1.a = t2.b) ORDER BY t1.a, t2.b;
+SELECT t1.a, t1.phv, t2.b, t2.phv FROM (SELECT 't1_phv' phv, * FROM fprt1 WHERE a % 25 = 0) t1 FULL JOIN (SELECT 't2_phv' phv, * FROM fprt2 WHERE b % 25 = 0) t2 ON (t1.a = t2.b) ORDER BY t1.a, t2.b;
+
+RESET enable_partitionwise_join;
diff --git a/contrib/seg/CMakeLists.txt b/contrib/seg/CMakeLists.txt
index c07a1e6718..e656298adc 100644
--- a/contrib/seg/CMakeLists.txt
+++ b/contrib/seg/CMakeLists.txt
@@ -27,6 +27,8 @@ install(FILES
${extension_name}.control
${extension_name}--1.1.sql
${extension_name}--1.0--1.1.sql
+ ${extension_name}--1.1--1.2.sql
+ ${extension_name}--1.2--1.3.sql
${extension_name}--unpackaged--1.0.sql
DESTINATION ${PGSHAREDIR}/extension)
diff --git a/contrib/seg/Makefile b/contrib/seg/Makefile
index c8f0f8b9a2..41270f84f6 100644
--- a/contrib/seg/Makefile
+++ b/contrib/seg/Makefile
@@ -4,7 +4,8 @@ MODULE_big = seg
OBJS = seg.o segparse.o $(WIN32RES)
EXTENSION = seg
-DATA = seg--1.1.sql seg--1.0--1.1.sql seg--unpackaged--1.0.sql
+DATA = seg--1.1.sql seg--1.1--1.2.sql seg--1.2--1.3.sql \
+ seg--1.0--1.1.sql seg--unpackaged--1.0.sql
PGFILEDESC = "seg - line segment data type"
REGRESS = seg
diff --git a/contrib/seg/expected/seg.out b/contrib/seg/expected/seg.out
index 18010c4d5c..a289dbe5f9 100644
--- a/contrib/seg/expected/seg.out
+++ b/contrib/seg/expected/seg.out
@@ -930,12 +930,40 @@ SELECT '1'::seg <@ '-1 .. 1'::seg AS bool;
CREATE TABLE test_seg (s seg);
\copy test_seg from 'data/test_seg.data'
CREATE INDEX test_seg_ix ON test_seg USING gist (s);
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM test_seg WHERE s @> '11..11.3';
+ QUERY PLAN
+-------------------------------------------------------
+ Aggregate
+ -> Bitmap Heap Scan on test_seg
+ Recheck Cond: (s @> '1.1e1 .. 11.3'::seg)
+ -> Bitmap Index Scan on test_seg_ix
+ Index Cond: (s @> '1.1e1 .. 11.3'::seg)
+(5 rows)
+
+SELECT count(*) FROM test_seg WHERE s @> '11..11.3';
+ count
+-------
+ 143
+(1 row)
+
+SET enable_bitmapscan = false;
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM test_seg WHERE s @> '11..11.3';
+ QUERY PLAN
+-----------------------------------------------------
+ Aggregate
+ -> Index Only Scan using test_seg_ix on test_seg
+ Index Cond: (s @> '1.1e1 .. 11.3'::seg)
+(3 rows)
+
SELECT count(*) FROM test_seg WHERE s @> '11..11.3';
count
-------
143
(1 row)
+RESET enable_bitmapscan;
-- Test sorting
SELECT * FROM test_seg WHERE s @> '11..11.3' GROUP BY s;
s
diff --git a/contrib/seg/expected/seg_1.out b/contrib/seg/expected/seg_1.out
index 566ce394ed..48abb65bb0 100644
--- a/contrib/seg/expected/seg_1.out
+++ b/contrib/seg/expected/seg_1.out
@@ -930,12 +930,40 @@ SELECT '1'::seg <@ '-1 .. 1'::seg AS bool;
CREATE TABLE test_seg (s seg);
\copy test_seg from 'data/test_seg.data'
CREATE INDEX test_seg_ix ON test_seg USING gist (s);
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM test_seg WHERE s @> '11..11.3';
+ QUERY PLAN
+-------------------------------------------------------
+ Aggregate
+ -> Bitmap Heap Scan on test_seg
+ Recheck Cond: (s @> '1.1e1 .. 11.3'::seg)
+ -> Bitmap Index Scan on test_seg_ix
+ Index Cond: (s @> '1.1e1 .. 11.3'::seg)
+(5 rows)
+
+SELECT count(*) FROM test_seg WHERE s @> '11..11.3';
+ count
+-------
+ 143
+(1 row)
+
+SET enable_bitmapscan = false;
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM test_seg WHERE s @> '11..11.3';
+ QUERY PLAN
+-----------------------------------------------------
+ Aggregate
+ -> Index Only Scan using test_seg_ix on test_seg
+ Index Cond: (s @> '1.1e1 .. 11.3'::seg)
+(3 rows)
+
SELECT count(*) FROM test_seg WHERE s @> '11..11.3';
count
-------
143
(1 row)
+RESET enable_bitmapscan;
-- Test sorting
SELECT * FROM test_seg WHERE s @> '11..11.3' GROUP BY s;
s
diff --git a/contrib/seg/seg--1.1--1.2.sql b/contrib/seg/seg--1.1--1.2.sql
new file mode 100644
index 0000000000..a6e4456f07
--- /dev/null
+++ b/contrib/seg/seg--1.1--1.2.sql
@@ -0,0 +1,14 @@
+/* contrib/seg/seg--1.1--1.2.sql */
+
+-- complain if script is sourced in psql, rather than via ALTER EXTENSION
+\echo Use "ALTER EXTENSION seg UPDATE TO '1.2'" to load this file. \quit
+
+ALTER OPERATOR <= (seg, seg) SET (
+ RESTRICT = scalarlesel,
+ JOIN = scalarlejoinsel
+);
+
+ALTER OPERATOR >= (seg, seg) SET (
+ RESTRICT = scalargesel,
+ JOIN = scalargejoinsel
+);
diff --git a/contrib/seg/seg--1.2--1.3.sql b/contrib/seg/seg--1.2--1.3.sql
new file mode 100644
index 0000000000..cd71a300f6
--- /dev/null
+++ b/contrib/seg/seg--1.2--1.3.sql
@@ -0,0 +1,45 @@
+/* contrib/seg/seg--1.2--1.3.sql */
+
+-- complain if script is sourced in psql, rather than via ALTER EXTENSION
+\echo Use "ALTER EXTENSION seg UPDATE TO '1.3'" to load this file. \quit
+
+--
+-- Get rid of unnecessary compress and decompress support functions.
+--
+-- To be allowed to drop the opclass entry for a support function,
+-- we must change the entry's dependency type from 'internal' to 'auto',
+-- as though it were a loose member of the opfamily rather than being
+-- bound into a particular opclass. There's no SQL command for that,
+-- so fake it with a manual update on pg_depend.
+--
+UPDATE pg_catalog.pg_depend
+SET deptype = 'a'
+WHERE classid = 'pg_catalog.pg_amproc'::pg_catalog.regclass
+ AND objid =
+ (SELECT objid
+ FROM pg_catalog.pg_depend
+ WHERE classid = 'pg_catalog.pg_amproc'::pg_catalog.regclass
+ AND refclassid = 'pg_catalog.pg_proc'::pg_catalog.regclass
+ AND (refobjid = 'gseg_compress(pg_catalog.internal)'::pg_catalog.regprocedure))
+ AND refclassid = 'pg_catalog.pg_opclass'::pg_catalog.regclass
+ AND deptype = 'i';
+
+ALTER OPERATOR FAMILY gist_seg_ops USING gist drop function 3 (seg);
+ALTER EXTENSION seg DROP function gseg_compress(pg_catalog.internal);
+DROP function gseg_compress(pg_catalog.internal);
+
+UPDATE pg_catalog.pg_depend
+SET deptype = 'a'
+WHERE classid = 'pg_catalog.pg_amproc'::pg_catalog.regclass
+ AND objid =
+ (SELECT objid
+ FROM pg_catalog.pg_depend
+ WHERE classid = 'pg_catalog.pg_amproc'::pg_catalog.regclass
+ AND refclassid = 'pg_catalog.pg_proc'::pg_catalog.regclass
+ AND (refobjid = 'gseg_decompress(pg_catalog.internal)'::pg_catalog.regprocedure))
+ AND refclassid = 'pg_catalog.pg_opclass'::pg_catalog.regclass
+ AND deptype = 'i';
+
+ALTER OPERATOR FAMILY gist_seg_ops USING gist drop function 4 (seg);
+ALTER EXTENSION seg DROP function gseg_decompress(pg_catalog.internal);
+DROP function gseg_decompress(pg_catalog.internal);
diff --git a/contrib/seg/seg.c b/contrib/seg/seg.c
index 4fc18130e1..4e34fba7c7 100644
--- a/contrib/seg/seg.c
+++ b/contrib/seg/seg.c
@@ -188,7 +188,7 @@ seg_upper(PG_FUNCTION_ARGS)
/*
** The GiST Consistent method for segments
** Should return false if for all data items x below entry,
-** the predicate x op query == FALSE, where op is the oper
+** the predicate x op query == false, where op is the oper
** corresponding to strategy in the pg_amop table.
*/
Datum
@@ -413,9 +413,9 @@ gseg_same(PG_FUNCTION_ARGS)
bool *result = (bool *) PG_GETARG_POINTER(2);
if (DirectFunctionCall2(seg_same, PG_GETARG_DATUM(0), PG_GETARG_DATUM(1)))
- *result = TRUE;
+ *result = true;
else
- *result = FALSE;
+ *result = false;
#ifdef GIST_DEBUG
fprintf(stderr, "same: %s\n", (*result ? "TRUE" : "FALSE"));
@@ -465,7 +465,7 @@ gseg_leaf_consistent(Datum key, Datum query, StrategyNumber strategy)
retval = DirectFunctionCall2(seg_contained, key, query);
break;
default:
- retval = FALSE;
+ retval = false;
}
PG_RETURN_DATUM(retval);
@@ -514,7 +514,7 @@ gseg_internal_consistent(Datum key, Datum query, StrategyNumber strategy)
DatumGetBool(DirectFunctionCall2(seg_overlap, key, query));
break;
default:
- retval = FALSE;
+ retval = false;
}
PG_RETURN_BOOL(retval);
@@ -528,7 +528,7 @@ gseg_binary_union(Datum r1, Datum r2, int *sizep)
retval = DirectFunctionCall2(seg_union, r1, r2);
*sizep = sizeof(SEG);
- return (retval);
+ return retval;
}
@@ -1040,7 +1040,7 @@ restore(char *result, float val, int n)
/* ... this is not done yet. */
}
- return (strlen(result));
+ return strlen(result);
}
@@ -1052,9 +1052,9 @@ restore(char *result, float val, int n)
* a floating point number
*/
int
-significant_digits(char *s)
+significant_digits(const char *s)
{
- char *p = s;
+ const char *p = s;
int n,
c,
zeroes;
@@ -1080,7 +1080,7 @@ significant_digits(char *s)
}
if (!n)
- return (zeroes);
+ return zeroes;
- return (n);
+ return n;
}
diff --git a/contrib/seg/seg.control b/contrib/seg/seg.control
index f210cf5e04..d697cd6c2a 100644
--- a/contrib/seg/seg.control
+++ b/contrib/seg/seg.control
@@ -1,5 +1,5 @@
# seg extension
comment = 'data type for representing line segments or floating-point intervals'
-default_version = '1.1'
+default_version = '1.3'
module_pathname = '$libdir/seg'
relocatable = true
diff --git a/contrib/seg/segdata.h b/contrib/seg/segdata.h
index cac68ee2b2..9488bf3a81 100644
--- a/contrib/seg/segdata.h
+++ b/contrib/seg/segdata.h
@@ -12,7 +12,7 @@ typedef struct SEG
} SEG;
/* in seg.c */
-extern int significant_digits(char *str);
+extern int significant_digits(const char *str);
/* in segscan.l */
extern int seg_yylex(void);
diff --git a/contrib/seg/segparse.y b/contrib/seg/segparse.y
index 045ff91f3e..040cab3904 100644
--- a/contrib/seg/segparse.y
+++ b/contrib/seg/segparse.y
@@ -21,7 +21,7 @@
#define YYMALLOC palloc
#define YYFREE pfree
-static float seg_atof(char *value);
+static float seg_atof(const char *value);
static char strbuf[25] = {
'0', '0', '0', '0', '0',
@@ -151,7 +151,7 @@ deviation: SEGFLOAT
static float
-seg_atof(char *value)
+seg_atof(const char *value)
{
Datum datum;
diff --git a/contrib/seg/segscan.l b/contrib/seg/segscan.l
index 6db24fdd1f..5f6595e9eb 100644
--- a/contrib/seg/segscan.l
+++ b/contrib/seg/segscan.l
@@ -3,6 +3,8 @@
* A scanner for EMP-style numeric ranges
*/
+/* LCOV_EXCL_START */
+
/* No reason to constrain amount of data slurped */
#define YY_READ_BUF_SIZE 16777216
@@ -51,6 +53,8 @@ float ({integer}|{real})([eE]{integer})?
%%
+/* LCOV_EXCL_STOP */
+
void
yyerror(SEG *result, const char *message)
{
diff --git a/contrib/seg/sql/seg.sql b/contrib/seg/sql/seg.sql
index aa91931474..1d7bad7c37 100644
--- a/contrib/seg/sql/seg.sql
+++ b/contrib/seg/sql/seg.sql
@@ -216,7 +216,16 @@ CREATE TABLE test_seg (s seg);
\copy test_seg from 'data/test_seg.data'
CREATE INDEX test_seg_ix ON test_seg USING gist (s);
+
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM test_seg WHERE s @> '11..11.3';
+SELECT count(*) FROM test_seg WHERE s @> '11..11.3';
+
+SET enable_bitmapscan = false;
+EXPLAIN (COSTS OFF)
+SELECT count(*) FROM test_seg WHERE s @> '11..11.3';
SELECT count(*) FROM test_seg WHERE s @> '11..11.3';
+RESET enable_bitmapscan;
-- Test sorting
SELECT * FROM test_seg WHERE s @> '11..11.3' GROUP BY s;
diff --git a/contrib/sepgsql/database.c b/contrib/sepgsql/database.c
index 8fc5a87e00..c641ec3565 100644
--- a/contrib/sepgsql/database.c
+++ b/contrib/sepgsql/database.c
@@ -4,7 +4,7 @@
*
* Routines corresponding to database objects
*
- * Copyright (c) 2010-2017, PostgreSQL Global Development Group
+ * Copyright (c) 2010-2018, PostgreSQL Global Development Group
*
* -------------------------------------------------------------------------
*/
diff --git a/contrib/sepgsql/dml.c b/contrib/sepgsql/dml.c
index b643720e36..c1fa320eb4 100644
--- a/contrib/sepgsql/dml.c
+++ b/contrib/sepgsql/dml.c
@@ -4,7 +4,7 @@
*
* Routines to handle DML permission checks
*
- * Copyright (c) 2010-2017, PostgreSQL Global Development Group
+ * Copyright (c) 2010-2018, PostgreSQL Global Development Group
*
* -------------------------------------------------------------------------
*/
@@ -118,10 +118,7 @@ fixup_inherited_columns(Oid parentId, Oid childId, Bitmapset *columns)
continue;
}
- attname = get_attname(parentId, attno);
- if (!attname)
- elog(ERROR, "cache lookup failed for attribute %d of relation %u",
- attno, parentId);
+ attname = get_attname(parentId, attno, false);
attno = get_attnum(childId, attname);
if (attno == InvalidAttrNumber)
elog(ERROR, "cache lookup failed for attribute %s of relation %u",
diff --git a/contrib/sepgsql/expected/misc.out b/contrib/sepgsql/expected/misc.out
index 98f8005a60..fdf07298bb 100644
--- a/contrib/sepgsql/expected/misc.out
+++ b/contrib/sepgsql/expected/misc.out
@@ -143,6 +143,7 @@ LOG: SELinux: allowed { select } scontext=unconfined_u:unconfined_r:sepgsql_reg
LOG: SELinux: allowed { select } scontext=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0-s0:c0.c255 tcontext=unconfined_u:object_r:sepgsql_table_t:s0 tclass=db_column name="table t1 column x"
LOG: SELinux: allowed { select } scontext=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0-s0:c0.c255 tcontext=unconfined_u:object_r:sepgsql_table_t:s0 tclass=db_column name="table t1 column y"
LOG: SELinux: allowed { execute } scontext=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0-s0:c0.c255 tcontext=system_u:object_r:sepgsql_proc_exec_t:s0 tclass=db_procedure name="pg_catalog.textlike(pg_catalog.text,pg_catalog.text)"
+LOG: SELinux: allowed { execute } scontext=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0-s0:c0.c255 tcontext=system_u:object_r:sepgsql_proc_exec_t:s0 tclass=db_procedure name="pg_catalog.int4eq(integer,integer)"
LOG: SELinux: allowed { execute } scontext=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0-s0:c0.c255 tcontext=system_u:object_r:sepgsql_proc_exec_t:s0 tclass=db_procedure name="pg_catalog.row_number()"
row_number | x | y
------------+----+----------------------------------
@@ -172,6 +173,7 @@ LOG: SELinux: allowed { select } scontext=unconfined_u:unconfined_r:sepgsql_reg
LOG: SELinux: allowed { select } scontext=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0-s0:c0.c255 tcontext=unconfined_u:object_r:sepgsql_table_t:s0 tclass=db_column name="table t1p_tens column p"
LOG: SELinux: allowed { execute } scontext=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0-s0:c0.c255 tcontext=system_u:object_r:sepgsql_proc_exec_t:s0 tclass=db_procedure name="pg_catalog.textlike(pg_catalog.text,pg_catalog.text)"
LOG: SELinux: allowed { execute } scontext=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0-s0:c0.c255 tcontext=system_u:object_r:sepgsql_proc_exec_t:s0 tclass=db_procedure name="pg_catalog.textlike(pg_catalog.text,pg_catalog.text)"
+LOG: SELinux: allowed { execute } scontext=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0-s0:c0.c255 tcontext=system_u:object_r:sepgsql_proc_exec_t:s0 tclass=db_procedure name="pg_catalog.int4eq(integer,integer)"
LOG: SELinux: allowed { execute } scontext=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0-s0:c0.c255 tcontext=system_u:object_r:sepgsql_proc_exec_t:s0 tclass=db_procedure name="pg_catalog.row_number()"
row_number | o | p
------------+----+----------------------------------
@@ -194,6 +196,7 @@ LOG: SELinux: allowed { select } scontext=unconfined_u:unconfined_r:sepgsql_reg
LOG: SELinux: allowed { select } scontext=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0-s0:c0.c255 tcontext=unconfined_u:object_r:sepgsql_table_t:s0 tclass=db_column name="table t1p_ones column o"
LOG: SELinux: allowed { select } scontext=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0-s0:c0.c255 tcontext=unconfined_u:object_r:sepgsql_table_t:s0 tclass=db_column name="table t1p_ones column p"
LOG: SELinux: allowed { execute } scontext=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0-s0:c0.c255 tcontext=system_u:object_r:sepgsql_proc_exec_t:s0 tclass=db_procedure name="pg_catalog.textlike(pg_catalog.text,pg_catalog.text)"
+LOG: SELinux: allowed { execute } scontext=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0-s0:c0.c255 tcontext=system_u:object_r:sepgsql_proc_exec_t:s0 tclass=db_procedure name="pg_catalog.int4eq(integer,integer)"
LOG: SELinux: allowed { execute } scontext=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0-s0:c0.c255 tcontext=system_u:object_r:sepgsql_proc_exec_t:s0 tclass=db_procedure name="pg_catalog.row_number()"
row_number | o | p
------------+---+----------------------------------
@@ -205,6 +208,7 @@ LOG: SELinux: allowed { select } scontext=unconfined_u:unconfined_r:sepgsql_reg
LOG: SELinux: allowed { select } scontext=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0-s0:c0.c255 tcontext=unconfined_u:object_r:sepgsql_table_t:s0 tclass=db_column name="table t1p_tens column o"
LOG: SELinux: allowed { select } scontext=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0-s0:c0.c255 tcontext=unconfined_u:object_r:sepgsql_table_t:s0 tclass=db_column name="table t1p_tens column p"
LOG: SELinux: allowed { execute } scontext=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0-s0:c0.c255 tcontext=system_u:object_r:sepgsql_proc_exec_t:s0 tclass=db_procedure name="pg_catalog.textlike(pg_catalog.text,pg_catalog.text)"
+LOG: SELinux: allowed { execute } scontext=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0-s0:c0.c255 tcontext=system_u:object_r:sepgsql_proc_exec_t:s0 tclass=db_procedure name="pg_catalog.int4eq(integer,integer)"
LOG: SELinux: allowed { execute } scontext=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0-s0:c0.c255 tcontext=system_u:object_r:sepgsql_proc_exec_t:s0 tclass=db_procedure name="pg_catalog.row_number()"
row_number | o | p
------------+----+----------------------------------
diff --git a/contrib/sepgsql/hooks.c b/contrib/sepgsql/hooks.c
index 5daa60c412..4249ed552c 100644
--- a/contrib/sepgsql/hooks.c
+++ b/contrib/sepgsql/hooks.c
@@ -4,7 +4,7 @@
*
* Entrypoints of the hooks in PostgreSQL, and dispatches the callbacks.
*
- * Copyright (c) 2010-2017, PostgreSQL Global Development Group
+ * Copyright (c) 2010-2018, PostgreSQL Global Development Group
*
* -------------------------------------------------------------------------
*/
diff --git a/contrib/sepgsql/label.c b/contrib/sepgsql/label.c
index cbb9249be7..7554017923 100644
--- a/contrib/sepgsql/label.c
+++ b/contrib/sepgsql/label.c
@@ -4,7 +4,7 @@
*
* Routines to support SELinux labels (security context)
*
- * Copyright (c) 2010-2017, PostgreSQL Global Development Group
+ * Copyright (c) 2010-2018, PostgreSQL Global Development Group
*
* -------------------------------------------------------------------------
*/
diff --git a/contrib/sepgsql/launcher b/contrib/sepgsql/launcher
index 0fc96ea0d4..45139f3750 100755
--- a/contrib/sepgsql/launcher
+++ b/contrib/sepgsql/launcher
@@ -2,7 +2,7 @@
#
# A wrapper script to launch psql command in regression test
#
-# Copyright (c) 2010-2017, PostgreSQL Global Development Group
+# Copyright (c) 2010-2018, PostgreSQL Global Development Group
#
# -------------------------------------------------------------------------
diff --git a/contrib/sepgsql/proc.c b/contrib/sepgsql/proc.c
index 14faa5fac6..c6a817d7c5 100644
--- a/contrib/sepgsql/proc.c
+++ b/contrib/sepgsql/proc.c
@@ -4,7 +4,7 @@
*
* Routines corresponding to procedure objects
*
- * Copyright (c) 2010-2017, PostgreSQL Global Development Group
+ * Copyright (c) 2010-2018, PostgreSQL Global Development Group
*
* -------------------------------------------------------------------------
*/
diff --git a/contrib/sepgsql/relation.c b/contrib/sepgsql/relation.c
index 228869a520..f0c22715aa 100644
--- a/contrib/sepgsql/relation.c
+++ b/contrib/sepgsql/relation.c
@@ -4,7 +4,7 @@
*
* Routines corresponding to relation/attribute objects
*
- * Copyright (c) 2010-2017, PostgreSQL Global Development Group
+ * Copyright (c) 2010-2018, PostgreSQL Global Development Group
*
* -------------------------------------------------------------------------
*/
diff --git a/contrib/sepgsql/schema.c b/contrib/sepgsql/schema.c
index d418577b75..bc15a36a45 100644
--- a/contrib/sepgsql/schema.c
+++ b/contrib/sepgsql/schema.c
@@ -4,7 +4,7 @@
*
* Routines corresponding to schema objects
*
- * Copyright (c) 2010-2017, PostgreSQL Global Development Group
+ * Copyright (c) 2010-2018, PostgreSQL Global Development Group
*
* -------------------------------------------------------------------------
*/
diff --git a/contrib/sepgsql/selinux.c b/contrib/sepgsql/selinux.c
index bf89e83dd6..47def00a46 100644
--- a/contrib/sepgsql/selinux.c
+++ b/contrib/sepgsql/selinux.c
@@ -5,7 +5,7 @@
* Interactions between userspace and selinux in kernelspace,
* using libselinux api.
*
- * Copyright (c) 2010-2017, PostgreSQL Global Development Group
+ * Copyright (c) 2010-2018, PostgreSQL Global Development Group
*
* -------------------------------------------------------------------------
*/
diff --git a/contrib/sepgsql/sepgsql.h b/contrib/sepgsql/sepgsql.h
index d4bf0cd14a..99adfc522a 100644
--- a/contrib/sepgsql/sepgsql.h
+++ b/contrib/sepgsql/sepgsql.h
@@ -4,7 +4,7 @@
*
* Definitions corresponding to SE-PostgreSQL
*
- * Copyright (c) 2010-2017, PostgreSQL Global Development Group
+ * Copyright (c) 2010-2018, PostgreSQL Global Development Group
*
* -------------------------------------------------------------------------
*/
diff --git a/contrib/sepgsql/uavc.c b/contrib/sepgsql/uavc.c
index f0915918db..ea276ee0cc 100644
--- a/contrib/sepgsql/uavc.c
+++ b/contrib/sepgsql/uavc.c
@@ -6,7 +6,7 @@
* access control decisions recently used, and reduce number of kernel
* invocations to avoid unnecessary performance hit.
*
- * Copyright (c) 2011-2017, PostgreSQL Global Development Group
+ * Copyright (c) 2011-2018, PostgreSQL Global Development Group
*
* -------------------------------------------------------------------------
*/
diff --git a/contrib/spi/refint.c b/contrib/spi/refint.c
index 46205c7613..b065ffa400 100644
--- a/contrib/spi/refint.c
+++ b/contrib/spi/refint.c
@@ -182,7 +182,7 @@ check_primary_key(PG_FUNCTION_ARGS)
pplan = SPI_prepare(sql, nkeys, argtypes);
if (pplan == NULL)
/* internal error */
- elog(ERROR, "check_primary_key: SPI_prepare returned %d", SPI_result);
+ elog(ERROR, "check_primary_key: SPI_prepare returned %s", SPI_result_code_string(SPI_result));
/*
* Remember that SPI_prepare places plan in current memory context -
@@ -395,7 +395,7 @@ check_foreign_key(PG_FUNCTION_ARGS)
/* this shouldn't happen! SPI_ERROR_NOOUTFUNC ? */
if (oldval == NULL)
/* internal error */
- elog(ERROR, "check_foreign_key: SPI_getvalue returned %d", SPI_result);
+ elog(ERROR, "check_foreign_key: SPI_getvalue returned %s", SPI_result_code_string(SPI_result));
newval = SPI_getvalue(newtuple, tupdesc, fnumber);
if (newval == NULL || strcmp(oldval, newval) != 0)
isequal = false;
@@ -489,7 +489,6 @@ check_foreign_key(PG_FUNCTION_ARGS)
" %s = %s%s%s %s ",
args2[k], (is_char_type > 0) ? "'" : "",
nv, (is_char_type > 0) ? "'" : "", (k < nkeys) ? ", " : "");
- is_char_type = 0;
}
strcat(sql, " where ");
@@ -529,7 +528,7 @@ check_foreign_key(PG_FUNCTION_ARGS)
pplan = SPI_prepare(sql, nkeys, argtypes);
if (pplan == NULL)
/* internal error */
- elog(ERROR, "check_foreign_key: SPI_prepare returned %d", SPI_result);
+ elog(ERROR, "check_foreign_key: SPI_prepare returned %s", SPI_result_code_string(SPI_result));
/*
* Remember that SPI_prepare places plan in current memory context
@@ -636,5 +635,5 @@ find_plan(char *ident, EPlan **eplan, int *nplans)
newp->splan = NULL;
(*nplans)++;
- return (newp);
+ return newp;
}
diff --git a/contrib/spi/timetravel.c b/contrib/spi/timetravel.c
index f7905e20db..00f661e6b6 100644
--- a/contrib/spi/timetravel.c
+++ b/contrib/spi/timetravel.c
@@ -328,7 +328,7 @@ timetravel(PG_FUNCTION_ARGS)
for (i = 1; i <= natts; i++)
{
ctypes[i - 1] = SPI_gettypeid(tupdesc, i);
- if (!(tupdesc->attrs[i - 1]->attisdropped)) /* skip dropped columns */
+ if (!(TupleDescAttr(tupdesc, i - 1)->attisdropped)) /* skip dropped columns */
{
snprintf(sql + strlen(sql), sizeof(sql) - strlen(sql), "%c$%d", separ, i);
separ = ',';
@@ -341,7 +341,7 @@ timetravel(PG_FUNCTION_ARGS)
/* Prepare plan for query */
pplan = SPI_prepare(sql, natts, ctypes);
if (pplan == NULL)
- elog(ERROR, "timetravel (%s): SPI_prepare returned %d", relname, SPI_result);
+ elog(ERROR, "timetravel (%s): SPI_prepare returned %s", relname, SPI_result_code_string(SPI_result));
/*
* Remember that SPI_prepare places plan in current memory context -
@@ -517,7 +517,7 @@ findTTStatus(char *name)
AbsoluteTime
currabstime()
{
- return (GetCurrentAbsoluteTime());
+ return GetCurrentAbsoluteTime();
}
*/
@@ -549,5 +549,5 @@ find_plan(char *ident, EPlan **eplan, int *nplans)
newp->splan = NULL;
(*nplans)++;
- return (newp);
+ return newp;
}
diff --git a/contrib/start-scripts/freebsd b/contrib/start-scripts/freebsd
index c6ac8cd47a..3323237a54 100644
--- a/contrib/start-scripts/freebsd
+++ b/contrib/start-scripts/freebsd
@@ -43,7 +43,7 @@ test -x $DAEMON ||
case $1 in
start)
- su -l $PGUSER -c "$DAEMON -D '$PGDATA' &" >>$PGLOG 2>&1
+ su -l $PGUSER -c "$DAEMON -D '$PGDATA' >>$PGLOG 2>&1 &"
echo -n ' postgresql'
;;
stop)
@@ -51,7 +51,7 @@ case $1 in
;;
restart)
su -l $PGUSER -c "$PGCTL stop -D '$PGDATA' -s"
- su -l $PGUSER -c "$DAEMON -D '$PGDATA' &" >>$PGLOG 2>&1
+ su -l $PGUSER -c "$DAEMON -D '$PGDATA' >>$PGLOG 2>&1 &"
;;
status)
su -l $PGUSER -c "$PGCTL status -D '$PGDATA'"
diff --git a/contrib/start-scripts/linux b/contrib/start-scripts/linux
index 44a775b030..a7757162fc 100644
--- a/contrib/start-scripts/linux
+++ b/contrib/start-scripts/linux
@@ -91,7 +91,7 @@ case $1 in
start)
echo -n "Starting PostgreSQL: "
test -e "$PG_OOM_ADJUST_FILE" && echo "$PG_MASTER_OOM_SCORE_ADJ" > "$PG_OOM_ADJUST_FILE"
- su - $PGUSER -c "$DAEMON_ENV $DAEMON -D '$PGDATA' &" >>$PGLOG 2>&1
+ su - $PGUSER -c "$DAEMON_ENV $DAEMON -D '$PGDATA' >>$PGLOG 2>&1 &"
echo "ok"
;;
stop)
@@ -103,7 +103,7 @@ case $1 in
echo -n "Restarting PostgreSQL: "
su - $PGUSER -c "$PGCTL stop -D '$PGDATA' -s"
test -e "$PG_OOM_ADJUST_FILE" && echo "$PG_MASTER_OOM_SCORE_ADJ" > "$PG_OOM_ADJUST_FILE"
- su - $PGUSER -c "$DAEMON_ENV $DAEMON -D '$PGDATA' &" >>$PGLOG 2>&1
+ su - $PGUSER -c "$DAEMON_ENV $DAEMON -D '$PGDATA' >>$PGLOG 2>&1 &"
echo "ok"
;;
reload)
diff --git a/contrib/start-scripts/macos/README b/contrib/start-scripts/macos/README
new file mode 100644
index 0000000000..c4f2d9a270
--- /dev/null
+++ b/contrib/start-scripts/macos/README
@@ -0,0 +1,24 @@
+To make macOS automatically launch your PostgreSQL server at system start,
+do the following:
+
+1. Edit the postgres-wrapper.sh script and adjust the file path
+variables at its start to reflect where you have installed Postgres,
+if that's not /usr/local/pgsql.
+
+2. Copy the modified postgres-wrapper.sh script into some suitable
+installation directory. It can be, but doesn't have to be, where
+you keep the Postgres executables themselves.
+
+3. Edit the org.postgresql.postgres.plist file and adjust its path
+for postgres-wrapper.sh to match what you did in step 2. Also,
+if you plan to run the Postgres server under some user name other
+than "postgres", adjust the UserName parameter value for that.
+
+4. Copy the modified org.postgresql.postgres.plist file into
+/Library/LaunchDaemons/. You must do this as root:
+ sudo cp org.postgresql.postgres.plist /Library/LaunchDaemons
+because the file will be ignored if it is not root-owned.
+
+At this point a reboot should launch the server. But if you want
+to test it without rebooting, you can do
+ sudo launchctl load /Library/LaunchDaemons/org.postgresql.postgres.plist
diff --git a/contrib/start-scripts/macos/org.postgresql.postgres.plist b/contrib/start-scripts/macos/org.postgresql.postgres.plist
new file mode 100644
index 0000000000..fdbd74f27d
--- /dev/null
+++ b/contrib/start-scripts/macos/org.postgresql.postgres.plist
@@ -0,0 +1,17 @@
+
+
+
+
+ Label
+ org.postgresql.postgres
+ ProgramArguments
+
+ /bin/sh
+ /usr/local/pgsql/bin/postgres-wrapper.sh
+
+ UserName
+ postgres
+ KeepAlive
+
+
+
diff --git a/contrib/start-scripts/macos/postgres-wrapper.sh b/contrib/start-scripts/macos/postgres-wrapper.sh
new file mode 100644
index 0000000000..3a4ebdaf0f
--- /dev/null
+++ b/contrib/start-scripts/macos/postgres-wrapper.sh
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+# PostgreSQL server start script (launched by org.postgresql.postgres.plist)
+
+# edit these as needed:
+
+# directory containing postgres executable:
+PGBINDIR="/usr/local/pgsql/bin"
+# data directory:
+PGDATA="/usr/local/pgsql/data"
+# file to receive postmaster's initial log messages:
+PGLOGFILE="${PGDATA}/pgstart.log"
+
+# (it's recommendable to enable the Postgres logging_collector feature
+# so that PGLOGFILE doesn't grow without bound)
+
+
+# set umask to ensure PGLOGFILE is not created world-readable
+umask 077
+
+# wait for networking to be up (else server may not bind to desired ports)
+/usr/sbin/ipconfig waitall
+
+# and launch the server
+exec "$PGBINDIR"/postgres -D "$PGDATA" >>"$PGLOGFILE" 2>&1
diff --git a/contrib/start-scripts/osx/PostgreSQL b/contrib/start-scripts/osx/PostgreSQL
deleted file mode 100755
index 7ff1d0e377..0000000000
--- a/contrib/start-scripts/osx/PostgreSQL
+++ /dev/null
@@ -1,111 +0,0 @@
-#!/bin/sh
-
-##
-# PostgreSQL RDBMS Server
-##
-
-# PostgreSQL boot time startup script for OS X. To install, change
-# the "prefix", "PGDATA", "PGUSER", and "PGLOG" variables below as
-# necessary. Next, create a new directory, "/Library/StartupItems/PostgreSQL".
-# Then copy this script and the accompanying "StartupParameters.plist" file
-# into that directory. The name of this script file *must* be the same as the
-# directory it is in. So you'll end up with these two files:
-#
-# /Library/StartupItems/PostgreSQL/PostgreSQL
-# /Library/StartupItems/PostgreSQL/StartupParameters.plist
-#
-# Next, add this line to the /etc/hostconfig file:
-#
-# POSTGRESQL=-YES-
-#
-# The startup bundle will now be ready to go. To prevent this script from
-# starting PostgreSQL at system startup, simply change that line in
-# /etc/hostconfig back to:
-#
-# POSTGRESQL=-NO-
-#
-# Created by David Wheeler, 2002
-
-# modified by Ray Aspeitia 12-03-2003 :
-# added log rotation script to db startup
-# modified StartupParameters.plist "Provides" parameter to make it easier to
-# start and stop with the SystemStarter utility
-
-# use the below command in order to correctly start/stop/restart PG with log rotation script:
-# SystemStarter [start|stop|restart] PostgreSQL
-
-################################################################################
-## EDIT FROM HERE
-################################################################################
-
-# Installation prefix
-prefix="/usr/local/pgsql"
-
-# Data directory
-PGDATA="/usr/local/pgsql/data"
-
-# Who to run the postmaster as, usually "postgres". (NOT "root")
-PGUSER="postgres"
-
-# the logfile path and name (NEEDS to be writeable by PGUSER)
-PGLOG="${PGDATA}/logs/logfile"
-
-# do you want to rotate the log files, 1=true 0=false
-ROTATELOGS=1
-
-# logfile rotate in seconds
-ROTATESEC="604800"
-
-
-################################################################################
-## STOP EDITING HERE
-################################################################################
-
-# The path that is to be used for the script
-PATH="$prefix/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"
-
-# What to use to start up the postmaster. (If you want the script to wait
-# until the server has started, you could use "pg_ctl start" here.)
-DAEMON="$prefix/bin/postmaster"
-
-# What to use to shut down the postmaster
-PGCTL="$prefix/bin/pg_ctl"
-
-# The apache log rotation utility
-LOGUTIL="/usr/sbin/rotatelogs"
-
-. /etc/rc.common
-
-StartService () {
- if [ "${POSTGRESQL:=-NO-}" = "-YES-" ]; then
- ConsoleMessage "Starting PostgreSQL database server"
- if [ "${ROTATELOGS}" = "1" ]; then
- sudo -u $PGUSER sh -c "${DAEMON} -D '${PGDATA}' &" 2>&1 | ${LOGUTIL} "${PGLOG}" ${ROTATESEC} &
- else
- sudo -u $PGUSER sh -c "${DAEMON} -D '${PGDATA}' &" >>"$PGLOG" 2>&1
- fi
- fi
-}
-
-StopService () {
- ConsoleMessage "Stopping PostgreSQL database server"
- sudo -u $PGUSER sh -c "$PGCTL stop -D '${PGDATA}' -s"
-}
-
-RestartService () {
- if [ "${POSTGRESQL:=-NO-}" = "-YES-" ]; then
- ConsoleMessage "Restarting PostgreSQL database server"
- # should match StopService:
- sudo -u $PGUSER sh -c "$PGCTL stop -D '${PGDATA}' -s"
- # should match StartService:
- if [ "${ROTATELOGS}" = "1" ]; then
- sudo -u $PGUSER sh -c "${DAEMON} -D '${PGDATA}' &" 2>&1 | ${LOGUTIL} "${PGLOG}" ${ROTATESEC} &
- else
- sudo -u $PGUSER sh -c "${DAEMON} -D '${PGDATA}' &" >>"$PGLOG" 2>&1
- fi
- else
- StopService
- fi
-}
-
-RunService "$1"
diff --git a/contrib/start-scripts/osx/README b/contrib/start-scripts/osx/README
deleted file mode 100644
index 97e299f7da..0000000000
--- a/contrib/start-scripts/osx/README
+++ /dev/null
@@ -1,3 +0,0 @@
-To install execute the following:
-
-sudo /bin/sh ./install.sh
diff --git a/contrib/start-scripts/osx/StartupParameters.plist b/contrib/start-scripts/osx/StartupParameters.plist
deleted file mode 100644
index 6c788d0dda..0000000000
--- a/contrib/start-scripts/osx/StartupParameters.plist
+++ /dev/null
@@ -1,33 +0,0 @@
-
-
-
-
- Description
- PostgreSQL Database Server
- Messages
-
- start
- Starting PostgreSQL database server
- stop
- Stopping PostgreSQL database server
- restart
- Restarting PostgreSQL database server
-
- OrderPreference
- Late
- Provides
-
- PostgreSQL
-
- Requires
-
- Disks
- Resolver
-
- Uses
-
- NFS
- NetworkTime
-
-
-
diff --git a/contrib/start-scripts/osx/install.sh b/contrib/start-scripts/osx/install.sh
deleted file mode 100755
index bbc5ee3926..0000000000
--- a/contrib/start-scripts/osx/install.sh
+++ /dev/null
@@ -1,10 +0,0 @@
-sudo sh -c 'echo "POSTGRESQL=-YES-" >> /etc/hostconfig'
-sudo mkdir /Library/StartupItems/PostgreSQL
-sudo cp PostgreSQL /Library/StartupItems/PostgreSQL
-sudo cp StartupParameters.plist /Library/StartupItems/PostgreSQL
-if [ -e /Library/StartupItems/PostgreSQL/PostgreSQL ]
-then
- echo "Startup Item Installed Successfully . . . "
- echo "Starting PostgreSQL Server . . . "
- SystemStarter restart PostgreSQL
-fi
diff --git a/contrib/tablefunc/tablefunc.c b/contrib/tablefunc/tablefunc.c
index 0bc8177b61..59f90dc947 100644
--- a/contrib/tablefunc/tablefunc.c
+++ b/contrib/tablefunc/tablefunc.c
@@ -10,7 +10,7 @@
* And contributors:
* Nabil Sayegh
*
- * Copyright (c) 2002-2017, PostgreSQL Global Development Group
+ * Copyright (c) 2002-2018, PostgreSQL Global Development Group
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without a written agreement
@@ -1421,7 +1421,7 @@ build_tuplestore_recursively(char *key_fld,
* Check expected (query runtime) tupdesc suitable for Connectby
*/
static void
-validateConnectbyTupleDesc(TupleDesc tupdesc, bool show_branch, bool show_serial)
+validateConnectbyTupleDesc(TupleDesc td, bool show_branch, bool show_serial)
{
int serial_column = 0;
@@ -1431,7 +1431,7 @@ validateConnectbyTupleDesc(TupleDesc tupdesc, bool show_branch, bool show_serial
/* are there the correct number of columns */
if (show_branch)
{
- if (tupdesc->natts != (CONNECTBY_NCOLS + serial_column))
+ if (td->natts != (CONNECTBY_NCOLS + serial_column))
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("invalid return type"),
@@ -1440,7 +1440,7 @@ validateConnectbyTupleDesc(TupleDesc tupdesc, bool show_branch, bool show_serial
}
else
{
- if (tupdesc->natts != CONNECTBY_NCOLS_NOBRANCH + serial_column)
+ if (td->natts != CONNECTBY_NCOLS_NOBRANCH + serial_column)
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("invalid return type"),
@@ -1449,14 +1449,14 @@ validateConnectbyTupleDesc(TupleDesc tupdesc, bool show_branch, bool show_serial
}
/* check that the types of the first two columns match */
- if (tupdesc->attrs[0]->atttypid != tupdesc->attrs[1]->atttypid)
+ if (TupleDescAttr(td, 0)->atttypid != TupleDescAttr(td, 1)->atttypid)
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("invalid return type"),
errdetail("First two columns must be the same type.")));
/* check that the type of the third column is INT4 */
- if (tupdesc->attrs[2]->atttypid != INT4OID)
+ if (TupleDescAttr(td, 2)->atttypid != INT4OID)
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("invalid return type"),
@@ -1464,7 +1464,7 @@ validateConnectbyTupleDesc(TupleDesc tupdesc, bool show_branch, bool show_serial
format_type_be(INT4OID))));
/* check that the type of the fourth column is TEXT if applicable */
- if (show_branch && tupdesc->attrs[3]->atttypid != TEXTOID)
+ if (show_branch && TupleDescAttr(td, 3)->atttypid != TEXTOID)
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("invalid return type"),
@@ -1472,7 +1472,8 @@ validateConnectbyTupleDesc(TupleDesc tupdesc, bool show_branch, bool show_serial
format_type_be(TEXTOID))));
/* check that the type of the fifth column is INT4 */
- if (show_branch && show_serial && tupdesc->attrs[4]->atttypid != INT4OID)
+ if (show_branch && show_serial &&
+ TupleDescAttr(td, 4)->atttypid != INT4OID)
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("query-specified return tuple not valid for Connectby: "
@@ -1480,7 +1481,8 @@ validateConnectbyTupleDesc(TupleDesc tupdesc, bool show_branch, bool show_serial
format_type_be(INT4OID))));
/* check that the type of the fifth column is INT4 */
- if (!show_branch && show_serial && tupdesc->attrs[3]->atttypid != INT4OID)
+ if (!show_branch && show_serial &&
+ TupleDescAttr(td, 3)->atttypid != INT4OID)
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("query-specified return tuple not valid for Connectby: "
@@ -1514,10 +1516,10 @@ compatConnectbyTupleDescs(TupleDesc ret_tupdesc, TupleDesc sql_tupdesc)
* These columns must match the result type indicated by the calling
* query.
*/
- ret_atttypid = ret_tupdesc->attrs[0]->atttypid;
- sql_atttypid = sql_tupdesc->attrs[0]->atttypid;
- ret_atttypmod = ret_tupdesc->attrs[0]->atttypmod;
- sql_atttypmod = sql_tupdesc->attrs[0]->atttypmod;
+ ret_atttypid = TupleDescAttr(ret_tupdesc, 0)->atttypid;
+ sql_atttypid = TupleDescAttr(sql_tupdesc, 0)->atttypid;
+ ret_atttypmod = TupleDescAttr(ret_tupdesc, 0)->atttypmod;
+ sql_atttypmod = TupleDescAttr(sql_tupdesc, 0)->atttypmod;
if (ret_atttypid != sql_atttypid ||
(ret_atttypmod >= 0 && ret_atttypmod != sql_atttypmod))
ereport(ERROR,
@@ -1528,10 +1530,10 @@ compatConnectbyTupleDescs(TupleDesc ret_tupdesc, TupleDesc sql_tupdesc)
format_type_with_typemod(ret_atttypid, ret_atttypmod),
format_type_with_typemod(sql_atttypid, sql_atttypmod))));
- ret_atttypid = ret_tupdesc->attrs[1]->atttypid;
- sql_atttypid = sql_tupdesc->attrs[1]->atttypid;
- ret_atttypmod = ret_tupdesc->attrs[1]->atttypmod;
- sql_atttypmod = sql_tupdesc->attrs[1]->atttypmod;
+ ret_atttypid = TupleDescAttr(ret_tupdesc, 1)->atttypid;
+ sql_atttypid = TupleDescAttr(sql_tupdesc, 1)->atttypid;
+ ret_atttypmod = TupleDescAttr(ret_tupdesc, 1)->atttypmod;
+ sql_atttypmod = TupleDescAttr(sql_tupdesc, 1)->atttypmod;
if (ret_atttypid != sql_atttypid ||
(ret_atttypmod >= 0 && ret_atttypmod != sql_atttypmod))
ereport(ERROR,
@@ -1562,8 +1564,8 @@ compatCrosstabTupleDescs(TupleDesc ret_tupdesc, TupleDesc sql_tupdesc)
return false;
/* check the rowid types match */
- ret_atttypid = ret_tupdesc->attrs[0]->atttypid;
- sql_atttypid = sql_tupdesc->attrs[0]->atttypid;
+ ret_atttypid = TupleDescAttr(ret_tupdesc, 0)->atttypid;
+ sql_atttypid = TupleDescAttr(sql_tupdesc, 0)->atttypid;
if (ret_atttypid != sql_atttypid)
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
@@ -1576,10 +1578,10 @@ compatCrosstabTupleDescs(TupleDesc ret_tupdesc, TupleDesc sql_tupdesc)
* attribute [2] of the sql tuple should match attributes [1] to [natts]
* of the return tuple
*/
- sql_attr = sql_tupdesc->attrs[2];
+ sql_attr = TupleDescAttr(sql_tupdesc, 2);
for (i = 1; i < ret_tupdesc->natts; i++)
{
- ret_attr = ret_tupdesc->attrs[i];
+ ret_attr = TupleDescAttr(ret_tupdesc, i);
if (ret_attr->atttypid != sql_attr->atttypid)
return false;
diff --git a/contrib/tablefunc/tablefunc.h b/contrib/tablefunc/tablefunc.h
index e88a5720fa..7d0773f82f 100644
--- a/contrib/tablefunc/tablefunc.h
+++ b/contrib/tablefunc/tablefunc.h
@@ -10,7 +10,7 @@
* And contributors:
* Nabil Sayegh
*
- * Copyright (c) 2002-2017, PostgreSQL Global Development Group
+ * Copyright (c) 2002-2018, PostgreSQL Global Development Group
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without a written agreement
diff --git a/contrib/tcn/tcn.c b/contrib/tcn/tcn.c
index 0b9acbf848..41186fdd8f 100644
--- a/contrib/tcn/tcn.c
+++ b/contrib/tcn/tcn.c
@@ -3,7 +3,7 @@
* tcn.c
* triggered change notification support for PostgreSQL
*
- * Portions Copyright (c) 2011-2017, PostgreSQL Global Development Group
+ * Portions Copyright (c) 2011-2018, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
*
@@ -153,9 +153,10 @@ triggered_change_notification(PG_FUNCTION_ARGS)
for (i = 0; i < numatts; i++)
{
int colno = index->indkey.values[i];
+ Form_pg_attribute attr = TupleDescAttr(tupdesc, colno - 1);
appendStringInfoCharMacro(payload, ',');
- strcpy_quoted(payload, NameStr((tupdesc->attrs[colno - 1])->attname), '"');
+ strcpy_quoted(payload, NameStr(attr->attname), '"');
appendStringInfoCharMacro(payload, '=');
strcpy_quoted(payload, SPI_getvalue(trigtuple, tupdesc, colno), '\'');
}
diff --git a/contrib/test_decoding/expected/decoding_into_rel.out b/contrib/test_decoding/expected/decoding_into_rel.out
index be759caa31..8fd3390066 100644
--- a/contrib/test_decoding/expected/decoding_into_rel.out
+++ b/contrib/test_decoding/expected/decoding_into_rel.out
@@ -59,6 +59,31 @@ SELECT * FROM changeresult;
DROP TABLE changeresult;
DROP TABLE somechange;
+-- check calling logical decoding from pl/pgsql
+CREATE FUNCTION slot_changes_wrapper(slot_name name) RETURNS SETOF TEXT AS $$
+BEGIN
+ RETURN QUERY
+ SELECT data FROM pg_logical_slot_peek_changes(slot_name, NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
+END$$ LANGUAGE plpgsql;
+SELECT * FROM slot_changes_wrapper('regression_slot');
+ slot_changes_wrapper
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ BEGIN
+ table public.changeresult: INSERT: data[text]:'BEGIN'
+ table public.changeresult: INSERT: data[text]:'table public.changeresult: INSERT: data[text]:''BEGIN'''
+ table public.changeresult: INSERT: data[text]:'table public.changeresult: INSERT: data[text]:''table public.somechange: INSERT: id[integer]:1'''
+ table public.changeresult: INSERT: data[text]:'table public.changeresult: INSERT: data[text]:''COMMIT'''
+ table public.changeresult: INSERT: data[text]:'COMMIT'
+ table public.changeresult: INSERT: data[text]:'BEGIN'
+ table public.changeresult: INSERT: data[text]:'table public.changeresult: INSERT: data[text]:''BEGIN'''
+ table public.changeresult: INSERT: data[text]:'table public.changeresult: INSERT: data[text]:''table public.changeresult: INSERT: data[text]:''''BEGIN'''''''
+ table public.changeresult: INSERT: data[text]:'table public.changeresult: INSERT: data[text]:''table public.changeresult: INSERT: data[text]:''''table public.somechange: INSERT: id[integer]:1'''''''
+ table public.changeresult: INSERT: data[text]:'table public.changeresult: INSERT: data[text]:''table public.changeresult: INSERT: data[text]:''''COMMIT'''''''
+ table public.changeresult: INSERT: data[text]:'table public.changeresult: INSERT: data[text]:''COMMIT'''
+ table public.changeresult: INSERT: data[text]:'COMMIT'
+ COMMIT
+(14 rows)
+
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
data
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
diff --git a/contrib/test_decoding/expected/permissions.out b/contrib/test_decoding/expected/permissions.out
index 7175dcd5f6..ed97f81dda 100644
--- a/contrib/test_decoding/expected/permissions.out
+++ b/contrib/test_decoding/expected/permissions.out
@@ -38,7 +38,7 @@ SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'test_d
(1 row)
INSERT INTO lr_test VALUES('lr_superuser_init');
-ERROR: permission denied for relation lr_test
+ERROR: permission denied for table lr_test
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
data
------
@@ -56,7 +56,7 @@ SET ROLE regress_lr_normal;
SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'test_decoding');
ERROR: must be superuser or replication role to use replication slots
INSERT INTO lr_test VALUES('lr_superuser_init');
-ERROR: permission denied for relation lr_test
+ERROR: permission denied for table lr_test
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
ERROR: must be superuser or replication role to use replication slots
SELECT pg_drop_replication_slot('regression_slot');
diff --git a/contrib/test_decoding/expected/replorigin.out b/contrib/test_decoding/expected/replorigin.out
index 76d4ea986d..8ea4ddda97 100644
--- a/contrib/test_decoding/expected/replorigin.out
+++ b/contrib/test_decoding/expected/replorigin.out
@@ -26,7 +26,14 @@ SELECT pg_replication_origin_drop('test_decoding: temp');
(1 row)
SELECT pg_replication_origin_drop('test_decoding: temp');
-ERROR: cache lookup failed for replication origin 'test_decoding: temp'
+ERROR: replication origin "test_decoding: temp" does not exist
+-- various failure checks for undefined slots
+select pg_replication_origin_advance('test_decoding: temp', '0/1');
+ERROR: replication origin "test_decoding: temp" does not exist
+select pg_replication_origin_session_setup('test_decoding: temp');
+ERROR: replication origin "test_decoding: temp" does not exist
+select pg_replication_origin_progress('test_decoding: temp', true);
+ERROR: replication origin "test_decoding: temp" does not exist
SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'test_decoding');
?column?
----------
diff --git a/contrib/test_decoding/expected/slot.out b/contrib/test_decoding/expected/slot.out
index 9f5f8a9b76..21e9d56f73 100644
--- a/contrib/test_decoding/expected/slot.out
+++ b/contrib/test_decoding/expected/slot.out
@@ -92,6 +92,36 @@ SELECT data FROM pg_logical_slot_get_changes('regression_slot2', NULL, NULL, 'in
COMMIT
(3 rows)
+INSERT INTO replication_example(somedata, text) VALUES (1, 4);
+INSERT INTO replication_example(somedata, text) VALUES (1, 5);
+SELECT pg_current_wal_lsn() AS wal_lsn \gset
+INSERT INTO replication_example(somedata, text) VALUES (1, 6);
+SELECT end_lsn FROM pg_replication_slot_advance('regression_slot1', :'wal_lsn') \gset
+SELECT slot_name FROM pg_replication_slot_advance('regression_slot2', pg_current_wal_lsn());
+ slot_name
+------------------
+ regression_slot2
+(1 row)
+
+SELECT :'wal_lsn' = :'end_lsn';
+ ?column?
+----------
+ t
+(1 row)
+
+SELECT data FROM pg_logical_slot_get_changes('regression_slot1', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
+ data
+---------------------------------------------------------------------------------------------------------
+ BEGIN
+ table public.replication_example: INSERT: id[integer]:6 somedata[integer]:1 text[character varying]:'6'
+ COMMIT
+(3 rows)
+
+SELECT data FROM pg_logical_slot_get_changes('regression_slot2', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
+ data
+------
+(0 rows)
+
DROP TABLE replication_example;
-- error
SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot1', 'test_decoding', true);
diff --git a/contrib/test_decoding/sql/decoding_into_rel.sql b/contrib/test_decoding/sql/decoding_into_rel.sql
index 54670fd39e..1068cec588 100644
--- a/contrib/test_decoding/sql/decoding_into_rel.sql
+++ b/contrib/test_decoding/sql/decoding_into_rel.sql
@@ -27,5 +27,16 @@ INSERT INTO changeresult
SELECT * FROM changeresult;
DROP TABLE changeresult;
DROP TABLE somechange;
+
+-- check calling logical decoding from pl/pgsql
+CREATE FUNCTION slot_changes_wrapper(slot_name name) RETURNS SETOF TEXT AS $$
+BEGIN
+ RETURN QUERY
+ SELECT data FROM pg_logical_slot_peek_changes(slot_name, NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
+END$$ LANGUAGE plpgsql;
+
+SELECT * FROM slot_changes_wrapper('regression_slot');
+
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
+
SELECT 'stop' FROM pg_drop_replication_slot('regression_slot');
diff --git a/contrib/test_decoding/sql/replorigin.sql b/contrib/test_decoding/sql/replorigin.sql
index 7870f0ea32..451cd4bc3b 100644
--- a/contrib/test_decoding/sql/replorigin.sql
+++ b/contrib/test_decoding/sql/replorigin.sql
@@ -13,6 +13,11 @@ SELECT pg_replication_origin_create('test_decoding: temp');
SELECT pg_replication_origin_drop('test_decoding: temp');
SELECT pg_replication_origin_drop('test_decoding: temp');
+-- various failure checks for undefined slots
+select pg_replication_origin_advance('test_decoding: temp', '0/1');
+select pg_replication_origin_session_setup('test_decoding: temp');
+select pg_replication_origin_progress('test_decoding: temp', true);
+
SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'test_decoding');
-- origin tx
diff --git a/contrib/test_decoding/sql/slot.sql b/contrib/test_decoding/sql/slot.sql
index fa9561f54e..706340c1d8 100644
--- a/contrib/test_decoding/sql/slot.sql
+++ b/contrib/test_decoding/sql/slot.sql
@@ -45,6 +45,21 @@ INSERT INTO replication_example(somedata, text) VALUES (1, 3);
SELECT data FROM pg_logical_slot_get_changes('regression_slot1', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
SELECT data FROM pg_logical_slot_get_changes('regression_slot2', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
+INSERT INTO replication_example(somedata, text) VALUES (1, 4);
+INSERT INTO replication_example(somedata, text) VALUES (1, 5);
+
+SELECT pg_current_wal_lsn() AS wal_lsn \gset
+
+INSERT INTO replication_example(somedata, text) VALUES (1, 6);
+
+SELECT end_lsn FROM pg_replication_slot_advance('regression_slot1', :'wal_lsn') \gset
+SELECT slot_name FROM pg_replication_slot_advance('regression_slot2', pg_current_wal_lsn());
+
+SELECT :'wal_lsn' = :'end_lsn';
+
+SELECT data FROM pg_logical_slot_get_changes('regression_slot1', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
+SELECT data FROM pg_logical_slot_get_changes('regression_slot2', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
+
DROP TABLE replication_example;
-- error
diff --git a/contrib/test_decoding/test_decoding.c b/contrib/test_decoding/test_decoding.c
index a1a7c2ae0c..0f18afa852 100644
--- a/contrib/test_decoding/test_decoding.c
+++ b/contrib/test_decoding/test_decoding.c
@@ -3,7 +3,7 @@
* test_decoding.c
* example logical decoding output plugin
*
- * Copyright (c) 2012-2017, PostgreSQL Global Development Group
+ * Copyright (c) 2012-2018, PostgreSQL Global Development Group
*
* IDENTIFICATION
* contrib/test_decoding/test_decoding.c
@@ -330,7 +330,7 @@ tuple_to_stringinfo(StringInfo s, TupleDesc tupdesc, HeapTuple tuple, bool skip_
Datum origval; /* possibly toasted Datum */
bool isnull; /* column is null? */
- attr = tupdesc->attrs[natt];
+ attr = TupleDescAttr(tupdesc, natt);
/*
* don't print dropped columns, we can't be sure everything is
diff --git a/contrib/tsm_system_rows/tsm_system_rows.c b/contrib/tsm_system_rows/tsm_system_rows.c
index 544458ec91..83f841f0c2 100644
--- a/contrib/tsm_system_rows/tsm_system_rows.c
+++ b/contrib/tsm_system_rows/tsm_system_rows.c
@@ -17,7 +17,7 @@
* won't visit blocks added after the first scan, but that is fine since
* such blocks shouldn't contain any visible tuples anyway.
*
- * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
diff --git a/contrib/tsm_system_time/tsm_system_time.c b/contrib/tsm_system_time/tsm_system_time.c
index af8d025414..f0c220aa4a 100644
--- a/contrib/tsm_system_time/tsm_system_time.c
+++ b/contrib/tsm_system_time/tsm_system_time.c
@@ -13,7 +13,7 @@
* However, we do what we can to reduce surprising behavior by selecting
* the sampling pattern just once per query, much as in tsm_system_rows.
*
- * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
diff --git a/contrib/unaccent/unaccent.c b/contrib/unaccent/unaccent.c
index e08cca1707..247c202755 100644
--- a/contrib/unaccent/unaccent.c
+++ b/contrib/unaccent/unaccent.c
@@ -3,7 +3,7 @@
* unaccent.c
* Text search unaccent dictionary
*
- * Copyright (c) 2009-2017, PostgreSQL Global Development Group
+ * Copyright (c) 2009-2018, PostgreSQL Global Development Group
*
* IDENTIFICATION
* contrib/unaccent/unaccent.c
@@ -90,7 +90,7 @@ placeChar(TrieChar *node, const unsigned char *str, int lenstr,
* Function converts UTF8-encoded file into current encoding.
*/
static TrieChar *
-initTrie(char *filename)
+initTrie(const char *filename)
{
TrieChar *volatile rootTrie = NULL;
MemoryContext ccxt = CurrentMemoryContext;
@@ -276,7 +276,7 @@ unaccent_init(PG_FUNCTION_ARGS)
{
DefElem *defel = (DefElem *) lfirst(l);
- if (pg_strcasecmp("Rules", defel->defname) == 0)
+ if (strcmp(defel->defname, "rules") == 0)
{
if (fileloaded)
ereport(ERROR,
diff --git a/contrib/uuid-ossp/uuid-ossp.c b/contrib/uuid-ossp/uuid-ossp.c
index db1f6b2b2f..ce96c7c64f 100644
--- a/contrib/uuid-ossp/uuid-ossp.c
+++ b/contrib/uuid-ossp/uuid-ossp.c
@@ -2,7 +2,7 @@
*
* UUID generation functions using the BSD, E2FS or OSSP UUID library
*
- * Copyright (c) 2007-2017, PostgreSQL Global Development Group
+ * Copyright (c) 2007-2018, PostgreSQL Global Development Group
*
* Portions Copyright (c) 2009 Andrew Gierth
*
@@ -14,13 +14,10 @@
#include "postgres.h"
#include "fmgr.h"
+#include "port/pg_bswap.h"
#include "utils/builtins.h"
#include "utils/uuid.h"
-/* for ntohl/htonl */
-#include
-#include
-
/*
* It's possible that there's more than one uuid.h header file present.
* We expect configure to set the HAVE_ symbol for only the one we want.
@@ -81,16 +78,16 @@ typedef struct
#define UUID_TO_NETWORK(uu) \
do { \
- uu.time_low = htonl(uu.time_low); \
- uu.time_mid = htons(uu.time_mid); \
- uu.time_hi_and_version = htons(uu.time_hi_and_version); \
+ uu.time_low = pg_hton32(uu.time_low); \
+ uu.time_mid = pg_hton16(uu.time_mid); \
+ uu.time_hi_and_version = pg_hton16(uu.time_hi_and_version); \
} while (0)
#define UUID_TO_LOCAL(uu) \
do { \
- uu.time_low = ntohl(uu.time_low); \
- uu.time_mid = ntohs(uu.time_mid); \
- uu.time_hi_and_version = ntohs(uu.time_hi_and_version); \
+ uu.time_low = pg_ntoh32(uu.time_low); \
+ uu.time_mid = pg_ntoh16(uu.time_mid); \
+ uu.time_hi_and_version = pg_ntoh16(uu.time_hi_and_version); \
} while (0)
#define UUID_V3_OR_V5(uu, v) \
@@ -247,7 +244,7 @@ uuid_generate_v35_internal(int mode, pg_uuid_t *ns, text *name)
#else /* !HAVE_UUID_OSSP */
static Datum
-uuid_generate_internal(int v, unsigned char *ns, char *ptr, int len)
+uuid_generate_internal(int v, unsigned char *ns, const char *ptr, int len)
{
char strbuf[40];
diff --git a/contrib/vacuumlo/vacuumlo.c b/contrib/vacuumlo/vacuumlo.c
index a4d4553303..ab6b17c7f6 100644
--- a/contrib/vacuumlo/vacuumlo.c
+++ b/contrib/vacuumlo/vacuumlo.c
@@ -3,7 +3,7 @@
* vacuumlo.c
* This removes orphaned large objects from a database.
*
- * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
*
@@ -23,6 +23,7 @@
#include "catalog/pg_class.h"
+#include "fe_utils/connect.h"
#include "libpq-fe.h"
#include "pg_getopt.h"
@@ -140,11 +141,8 @@ vacuumlo(const char *database, const struct _param *param)
fprintf(stdout, "Test run: no large objects will be removed!\n");
}
- /*
- * Don't get fooled by any non-system catalogs
- */
- res = PQexec(conn, "SET search_path = pg_catalog");
- if (PQresultStatus(res) != PGRES_COMMAND_OK)
+ res = PQexec(conn, ALWAYS_SECURE_SEARCH_PATH_SQL);
+ if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
fprintf(stderr, "Failed to set search_path:\n");
fprintf(stderr, "%s", PQerrorMessage(conn));
diff --git a/doc/src/sgml/Makefile b/doc/src/sgml/Makefile
index 8a73cc796f..f122b4187f 100644
--- a/doc/src/sgml/Makefile
+++ b/doc/src/sgml/Makefile
@@ -37,15 +37,7 @@ ifndef FOP
FOP = $(missing) fop
endif
-SGMLINCLUDE = -D . -D $(srcdir)
-
-ifndef NSGMLS
-NSGMLS = $(missing) nsgmls
-endif
-
-ifndef OSX
-OSX = $(missing) osx
-endif
+XMLINCLUDE = --path .
ifndef XMLLINT
XMLLINT = $(missing) xmllint
@@ -63,14 +55,6 @@ GENERATED_SGML = version.sgml \
ALLSGML := $(wildcard $(srcdir)/*.sgml $(srcdir)/ref/*.sgml) $(GENERATED_SGML)
-# Enable some extra warnings
-# -wfully-tagged needed to throw a warning on missing tags
-# for older tool chains, 2007-08-31
-# Note: try "make SPFLAGS=-wxml" to catch a lot of other dubious constructs,
-# in particular < and & that haven't been made into entities. It's far too
-# noisy to turn on by default, unfortunately.
-override SPFLAGS += -wall -wno-unused-param -wno-empty -wfully-tagged
-
##
## Man pages
@@ -78,9 +62,9 @@ override SPFLAGS += -wall -wno-unused-param -wno-empty -wfully-tagged
man distprep-man: man-stamp
-man-stamp: stylesheet-man.xsl postgres.xml
- $(XMLLINT) --noout --valid postgres.xml
- $(XSLTPROC) $(XSLTPROCFLAGS) $(XSLTPROC_MAN_FLAGS) $^
+man-stamp: stylesheet-man.xsl postgres.sgml $(ALLSGML)
+ $(XMLLINT) $(XMLINCLUDE) --noout --valid $(word 2,$^)
+ $(XSLTPROC) $(XMLINCLUDE) $(XSLTPROCFLAGS) $(XSLTPROC_MAN_FLAGS) $(wordlist 1,2,$^)
touch $@
@@ -131,28 +115,8 @@ INSTALL.html: %.html : stylesheet-text.xsl %.xml
$(XMLLINT) --noout --valid $*.xml
$(XSLTPROC) $(XSLTPROCFLAGS) $(XSLTPROC_HTML_FLAGS) $^ >$@
-INSTALL.xml: standalone-install.sgml installation.sgml version.sgml
- $(OSX) $(SPFLAGS) $(SGMLINCLUDE) -x lower $(filter-out version.sgml,$^) >$@.tmp
- $(call mangle-xml,chapter)
-
-
-##
-## SGML->XML conversion
-##
-
-# For obscure reasons, GNU make 3.81 complains about circular dependencies
-# if we try to do "make all" in a VPATH build without the explicit
-# $(srcdir) on the postgres.sgml dependency in this rule. GNU make bug?
-postgres.xml: $(srcdir)/postgres.sgml $(ALLSGML)
- $(OSX) $(SPFLAGS) $(SGMLINCLUDE) -x lower $< >$@.tmp
- $(call mangle-xml,book)
-
-define mangle-xml
-$(PERL) -p -e 's/\[(aacute|acirc|aelig|agrave|amp|aring|atilde|auml|bull|copy|eacute|egrave|gt|iacute|lt|mdash|nbsp|ntilde|oacute|ocirc|oslash|ouml|pi|quot|scaron|uuml) *\]/\&\1;/gi;' \
- -e '$$_ .= qq{\n} if $$. == 1;' \
- <$@.tmp > $@
-rm $@.tmp
-endef
+INSTALL.xml: standalone-profile.xsl standalone-install.xml postgres.sgml $(ALLSGML)
+ $(XSLTPROC) $(XMLINCLUDE) $(XSLTPROCFLAGS) --xinclude $(wordlist 1,2,$^) >$@
##
@@ -165,20 +129,20 @@ endif
html: html-stamp
-html-stamp: stylesheet.xsl postgres.xml
- $(XMLLINT) --noout --valid postgres.xml
- $(XSLTPROC) $(XSLTPROCFLAGS) $(XSLTPROC_HTML_FLAGS) $^
+html-stamp: stylesheet.xsl postgres.sgml $(ALLSGML)
+ $(XMLLINT) $(XMLINCLUDE) --noout --valid $(word 2,$^)
+ $(XSLTPROC) $(XMLINCLUDE) $(XSLTPROCFLAGS) $(XSLTPROC_HTML_FLAGS) $(wordlist 1,2,$^)
cp $(srcdir)/stylesheet.css html/
touch $@
-htmlhelp: stylesheet-hh.xsl postgres.xml
- $(XMLLINT) --noout --valid postgres.xml
- $(XSLTPROC) $(XSLTPROCFLAGS) $^
+htmlhelp: stylesheet-hh.xsl postgres.sgml $(ALLSGML)
+ $(XMLLINT) $(XMLINCLUDE) --noout --valid $(word 2,$^)
+ $(XSLTPROC) $(XMLINCLUDE) $(XSLTPROCFLAGS) $(wordlist 1,2,$^)
# single-page HTML
-postgres.html: stylesheet-html-nochunk.xsl postgres.xml
- $(XMLLINT) --noout --valid postgres.xml
- $(XSLTPROC) $(XSLTPROCFLAGS) $(XSLTPROC_HTML_FLAGS) -o $@ $^
+postgres.html: stylesheet-html-nochunk.xsl postgres.sgml $(ALLSGML)
+ $(XMLLINT) $(XMLINCLUDE) --noout --valid $(word 2,$^)
+ $(XSLTPROC) $(XMLINCLUDE) $(XSLTPROCFLAGS) $(XSLTPROC_HTML_FLAGS) -o $@ $(wordlist 1,2,$^)
# single-page text
postgres.txt: postgres.html
@@ -192,13 +156,13 @@ postgres.txt: postgres.html
postgres.pdf:
$(error Invalid target; use postgres-A4.pdf or postgres-US.pdf as targets)
-%-A4.fo: stylesheet-fo.xsl %.xml
- $(XMLLINT) --noout --valid $*.xml
- $(XSLTPROC) $(XSLTPROCFLAGS) --stringparam paper.type A4 -o $@ $^
+%-A4.fo: stylesheet-fo.xsl %.sgml $(ALLSGML)
+ $(XMLLINT) $(XMLINCLUDE) --noout --valid $(word 2,$^)
+ $(XSLTPROC) $(XMLINCLUDE) $(XSLTPROCFLAGS) --stringparam paper.type A4 -o $@ $(wordlist 1,2,$^)
-%-US.fo: stylesheet-fo.xsl %.xml
- $(XMLLINT) --noout --valid $*.xml
- $(XSLTPROC) $(XSLTPROCFLAGS) --stringparam paper.type USletter -o $@ $^
+%-US.fo: stylesheet-fo.xsl %.sgml $(ALLSGML)
+ $(XMLLINT) $(XMLINCLUDE) --noout --valid $(word 2,$^)
+ $(XSLTPROC) $(XMLINCLUDE) $(XSLTPROCFLAGS) --stringparam paper.type USletter -o $@ $(wordlist 1,2,$^)
%.pdf: %.fo
$(FOP) -fo $< -pdf $@
@@ -209,7 +173,7 @@ postgres.pdf:
##
epub: postgres.epub
-postgres.epub: postgres.xml
+postgres.epub: postgres.sgml $(ALLSGML)
$(XMLLINT) --noout --valid $<
$(DBTOEPUB) $<
@@ -222,7 +186,8 @@ DB2X_TEXIXML = db2x_texixml
DB2X_XSLTPROC = db2x_xsltproc
MAKEINFO = makeinfo
-%.texixml: %.xml
+%.texixml: %.sgml $(ALLSGML)
+ $(XMLLINT) --noout --valid $<
$(DB2X_XSLTPROC) -s texi -g output-file=$(basename $@) $< -o $@
%.texi: %.texixml
@@ -238,7 +203,7 @@ MAKEINFO = makeinfo
# Quick syntax check without style processing
check: postgres.sgml $(ALLSGML) check-tabs
- $(NSGMLS) $(SPFLAGS) $(SGMLINCLUDE) -s $<
+ $(XMLLINT) $(XMLINCLUDE) --noout --valid $<
##
@@ -300,7 +265,7 @@ endif # sqlmansectnum != 7
# tabs are harmless, but it is best to avoid them in SGML files
check-tabs:
- @( ! grep ' ' $(wildcard $(srcdir)/*.sgml $(srcdir)/ref/*.sgml $(srcdir)/*.dsl $(srcdir)/*.xsl) ) || (echo "Tabs appear in SGML/XML files" 1>&2; exit 1)
+ @( ! grep ' ' $(wildcard $(srcdir)/*.sgml $(srcdir)/ref/*.sgml $(srcdir)/*.xsl) ) || (echo "Tabs appear in SGML/XML files" 1>&2; exit 1)
##
## Clean
@@ -308,7 +273,7 @@ check-tabs:
# This allows removing some files from the distribution tarballs while
# keeping the dependencies satisfied.
-.SECONDARY: postgres.xml $(GENERATED_SGML) HTML.index
+.SECONDARY: $(GENERATED_SGML)
.SECONDARY: INSTALL.html INSTALL.xml
.SECONDARY: postgres-A4.fo postgres-US.fo
@@ -322,8 +287,6 @@ clean:
rm -f *.fo *.pdf
# generated SGML files
rm -f $(GENERATED_SGML)
-# SGML->XML conversion
- rm -f postgres.xml *.tmp
# HTML Help
rm -f htmlhelp.hhp toc.hhc index.hhk
# EPUB
diff --git a/doc/src/sgml/acronyms.sgml b/doc/src/sgml/acronyms.sgml
index 29f85e0846..751c46de6d 100644
--- a/doc/src/sgml/acronyms.sgml
+++ b/doc/src/sgml/acronyms.sgml
@@ -4,8 +4,8 @@
Acronyms
- This is a list of acronyms commonly used in the PostgreSQL>
- documentation and in discussions about PostgreSQL>.
+ This is a list of acronyms commonly used in the PostgreSQL
+ documentation and in discussions about PostgreSQL.
@@ -153,7 +153,7 @@
Data
Definition Language, SQL commands such as CREATE
- TABLE>, ALTER USER>
+ TABLE, ALTER USER
@@ -164,8 +164,8 @@
Data
- Manipulation Language, SQL commands such as INSERT>,
- UPDATE>, DELETE>
+ Manipulation Language, SQL commands such as INSERT,
+ UPDATE, DELETE
@@ -232,7 +232,7 @@
GIN
- Generalized Inverted Index
+ Generalized Inverted Index
@@ -241,7 +241,7 @@
GiST
- Generalized Search Tree
+ Generalized Search Tree
@@ -281,7 +281,7 @@
Grand Unified Configuration,
- the PostgreSQL> subsystem that handles server configuration
+ the PostgreSQL subsystem that handles server configuration
@@ -369,6 +369,16 @@
+
+ JSON
+
+
+ JavaScript Object Notation
+
+
+
+
LDAP
@@ -384,7 +394,7 @@
LSN
- Log Sequence Number, see pg_lsn>
+ Log Sequence Number, see pg_lsn
and WAL Internals.
@@ -486,7 +496,7 @@
PGSQL
- PostgreSQL>
+ PostgreSQL
@@ -495,7 +505,7 @@
PGXS
- PostgreSQL> Extension System
+ PostgreSQL Extension System
@@ -583,7 +593,7 @@
SP-GiST
- Space-Partitioned Generalized Search Tree
+ Space-Partitioned Generalized Search Tree
diff --git a/doc/src/sgml/adminpack.sgml b/doc/src/sgml/adminpack.sgml
index fddf90c4a5..1197eefbf3 100644
--- a/doc/src/sgml/adminpack.sgml
+++ b/doc/src/sgml/adminpack.sgml
@@ -8,24 +8,24 @@
- adminpack> provides a number of support functions which
- pgAdmin> and other administration and management tools can
+ adminpack provides a number of support functions which
+ pgAdmin and other administration and management tools can
use to provide additional functionality, such as remote management
of server log files.
Use of all these functions is restricted to superusers.
- The functions shown in provide
+ The functions shown in provide
write access to files on the machine hosting the server. (See also the
- functions in , which
+ functions in , which
provide read-only access.)
Only files within the database cluster directory can be accessed, but
either a relative or absolute path is allowable.
- adminpack> Functions
+ adminpack FunctionsNameReturn TypeDescription
@@ -58,7 +58,7 @@
pg_catalog.pg_logdir_ls()setof record
- List the log files in the log_directory> directory
+ List the log files in the log_directory directory
@@ -69,9 +69,9 @@
pg_file_write
- pg_file_write> writes the specified data> into
- the file named by filename>. If append> is
- false, the file must not already exist. If append> is true,
+ pg_file_write writes the specified data into
+ the file named by filename. If append is
+ false, the file must not already exist. If append is true,
the file can already exist, and will be appended to if so.
Returns the number of bytes written.
@@ -80,15 +80,15 @@
pg_file_rename
- pg_file_rename> renames a file. If archivename>
- is omitted or NULL, it simply renames oldname>
- to newname> (which must not already exist).
- If archivename> is provided, it first
- renames newname> to archivename> (which must
- not already exist), and then renames oldname>
- to newname>. In event of failure of the second rename step,
- it will try to rename archivename> back
- to newname> before reporting the error.
+ pg_file_rename renames a file. If archivename
+ is omitted or NULL, it simply renames oldname
+ to newname (which must not already exist).
+ If archivename is provided, it first
+ renames newname to archivename (which must
+ not already exist), and then renames oldname
+ to newname. In event of failure of the second rename step,
+ it will try to rename archivename back
+ to newname before reporting the error.
Returns true on success, false if the source file(s) are not present or
not writable; other cases throw errors.
@@ -97,34 +97,34 @@
pg_file_unlink
- pg_file_unlink> removes the specified file.
+ pg_file_unlink removes the specified file.
Returns true on success, false if the specified file is not present
- or the unlink()> call fails; other cases throw errors.
+ or the unlink() call fails; other cases throw errors.
pg_logdir_ls
- pg_logdir_ls> returns the start timestamps and path
- names of all the log files in the
- directory. The parameter must have its
- default setting (postgresql-%Y-%m-%d_%H%M%S.log>) to use this
+ pg_logdir_ls returns the start timestamps and path
+ names of all the log files in the
+ directory. The parameter must have its
+ default setting (postgresql-%Y-%m-%d_%H%M%S.log) to use this
function.
The functions shown
- in are deprecated
+ in are deprecated
and should not be used in new applications; instead use those shown
- in
- and . These functions are
- provided in adminpack> only for compatibility with old
- versions of pgAdmin>.
+ in
+ and . These functions are
+ provided in adminpack only for compatibility with old
+ versions of pgAdmin.
- Deprecated adminpack> Functions
+ Deprecated adminpack FunctionsNameReturn TypeDescription
@@ -136,22 +136,22 @@
pg_catalog.pg_file_read(filename text, offset bigint, nbytes bigint)text
- Alternate name for pg_read_file()>
+ Alternate name for pg_read_file()pg_catalog.pg_file_length(filename text)bigint
- Same as size> column returned
- by pg_stat_file()>
+ Same as size column returned
+ by pg_stat_file()pg_catalog.pg_logfile_rotate()integer
- Alternate name for pg_rotate_logfile()>, but note that it
+ Alternate name for pg_rotate_logfile(), but note that it
returns integer 0 or 1 rather than boolean
diff --git a/doc/src/sgml/advanced.sgml b/doc/src/sgml/advanced.sgml
index f47c01987b..ae5f3fac75 100644
--- a/doc/src/sgml/advanced.sgml
+++ b/doc/src/sgml/advanced.sgml
@@ -18,12 +18,12 @@
This chapter will on occasion refer to examples found in to change or improve them, so it will be
+ linkend="tutorial-sql"/> to change or improve them, so it will be
useful to have read that chapter. Some examples from
this chapter can also be found in
advanced.sql in the tutorial directory. This
file also contains some sample data to load, which is not
- repeated here. (Refer to for
+ repeated here. (Refer to for
how to use the file.)
@@ -37,7 +37,7 @@
- Refer back to the queries in .
+ Refer back to the queries in .
Suppose the combined listing of weather records and city location
is of particular interest to your application, but you do not want
to type the query each time you need it. You can create a
@@ -82,7 +82,7 @@ SELECT * FROM myview;
Recall the weather and
cities tables from . Consider the following problem: You
+ linkend="tutorial-sql"/>. Consider the following problem: You
want to make sure that no one can insert rows in the
weather table that do not have a matching
entry in the cities table. This is called
@@ -129,7 +129,7 @@ DETAIL: Key (city)=(Berkeley) is not present in table "cities".
The behavior of foreign keys can be finely tuned to your
application. We will not go beyond this simple example in this
- tutorial, but just refer you to
+ tutorial, but just refer you to
for more information. Making correct use of
foreign keys will definitely improve the quality of your database
applications, so you are strongly encouraged to learn about them.
@@ -145,7 +145,7 @@ DETAIL: Key (city)=(Berkeley) is not present in table "cities".
- Transactions> are a fundamental concept of all database
+ Transactions are a fundamental concept of all database
systems. The essential point of a transaction is that it bundles
multiple steps into a single, all-or-nothing operation. The intermediate
states between the steps are not visible to other concurrent transactions,
@@ -182,8 +182,8 @@ UPDATE branches SET balance = balance + 100.00
remain a happy customer if she was debited without Bob being credited.
We need a guarantee that if something goes wrong partway through the
operation, none of the steps executed so far will take effect. Grouping
- the updates into a transaction> gives us this guarantee.
- A transaction is said to be atomic>: from the point of
+ the updates into a transaction gives us this guarantee.
+ A transaction is said to be atomic: from the point of
view of other transactions, it either happens completely or not at all.
@@ -216,9 +216,9 @@ UPDATE branches SET balance = balance + 100.00
- In PostgreSQL>, a transaction is set up by surrounding
+ In PostgreSQL, a transaction is set up by surrounding
the SQL commands of the transaction with
- BEGIN> and COMMIT> commands. So our banking
+ BEGIN and COMMIT commands. So our banking
transaction would actually look like:
@@ -233,23 +233,23 @@ COMMIT;
If, partway through the transaction, we decide we do not want to
commit (perhaps we just noticed that Alice's balance went negative),
- we can issue the command ROLLBACK> instead of
- COMMIT>, and all our updates so far will be canceled.
+ we can issue the command ROLLBACK instead of
+ COMMIT, and all our updates so far will be canceled.
- PostgreSQL> actually treats every SQL statement as being
- executed within a transaction. If you do not issue a BEGIN>
+ PostgreSQL actually treats every SQL statement as being
+ executed within a transaction. If you do not issue a BEGIN
command,
- then each individual statement has an implicit BEGIN> and
- (if successful) COMMIT> wrapped around it. A group of
- statements surrounded by BEGIN> and COMMIT>
- is sometimes called a transaction block>.
+ then each individual statement has an implicit BEGIN and
+ (if successful) COMMIT wrapped around it. A group of
+ statements surrounded by BEGIN and COMMIT
+ is sometimes called a transaction block.
- Some client libraries issue BEGIN> and COMMIT>
+ Some client libraries issue BEGIN and COMMIT
commands automatically, so that you might get the effect of transaction
blocks without asking. Check the documentation for the interface
you are using.
@@ -258,11 +258,11 @@ COMMIT;
It's possible to control the statements in a transaction in a more
- granular fashion through the use of savepoints>. Savepoints
+ granular fashion through the use of savepoints. Savepoints
allow you to selectively discard parts of the transaction, while
committing the rest. After defining a savepoint with
- SAVEPOINT>, you can if needed roll back to the savepoint
- with ROLLBACK TO>. All the transaction's database changes
+ SAVEPOINT, you can if needed roll back to the savepoint
+ with ROLLBACK TO. All the transaction's database changes
between defining the savepoint and rolling back to it are discarded, but
changes earlier than the savepoint are kept.
@@ -308,7 +308,7 @@ COMMIT;
This example is, of course, oversimplified, but there's a lot of control
possible in a transaction block through the use of savepoints.
- Moreover, ROLLBACK TO> is the only way to regain control of a
+ Moreover, ROLLBACK TO is the only way to regain control of a
transaction block that was put in aborted state by the
system due to an error, short of rolling it back completely and starting
again.
@@ -325,7 +325,7 @@ COMMIT;
- A window function> performs a calculation across a set of
+ A window function performs a calculation across a set of
table rows that are somehow related to the current row. This is comparable
to the type of calculation that can be done with an aggregate function.
However, window functions do not cause rows to become grouped into a single
@@ -360,31 +360,31 @@ SELECT depname, empno, salary, avg(salary) OVER (PARTITION BY depname) FROM emps
The first three output columns come directly from the table
- empsalary>, and there is one output row for each row in the
+ empsalary, and there is one output row for each row in the
table. The fourth column represents an average taken across all the table
- rows that have the same depname> value as the current row.
- (This actually is the same function as the non-window avg>
- aggregate, but the OVER> clause causes it to be
+ rows that have the same depname value as the current row.
+ (This actually is the same function as the non-window avg
+ aggregate, but the OVER clause causes it to be
treated as a window function and computed across the window frame.)
- A window function call always contains an OVER> clause
+ A window function call always contains an OVER clause
directly following the window function's name and argument(s). This is what
syntactically distinguishes it from a normal function or non-window
- aggregate. The OVER> clause determines exactly how the
+ aggregate. The OVER clause determines exactly how the
rows of the query are split up for processing by the window function.
- The PARTITION BY> clause within OVER>
+ The PARTITION BY clause within OVER
divides the rows into groups, or partitions, that share the same
- values of the PARTITION BY> expression(s). For each row,
+ values of the PARTITION BY expression(s). For each row,
the window function is computed across the rows that fall into the
same partition as the current row.
You can also control the order in which rows are processed by
- window functions using ORDER BY> within OVER>.
- (The window ORDER BY> does not even have to match the
+ window functions using ORDER BY within OVER.
+ (The window ORDER BY does not even have to match the
order in which the rows are output.) Here is an example:
@@ -409,48 +409,48 @@ FROM empsalary;
(10 rows)
- As shown here, the rank> function produces a numerical rank
- for each distinct ORDER BY> value in the current row's
- partition, using the order defined by the ORDER BY> clause.
- rank> needs no explicit parameter, because its behavior
- is entirely determined by the OVER> clause.
+ As shown here, the rank function produces a numerical rank
+ for each distinct ORDER BY value in the current row's
+ partition, using the order defined by the ORDER BY clause.
+ rank needs no explicit parameter, because its behavior
+ is entirely determined by the OVER clause.
The rows considered by a window function are those of the virtual
- table> produced by the query's FROM> clause as filtered by its
- WHERE>, GROUP BY>, and HAVING> clauses
+ table produced by the query's FROM clause as filtered by its
+ WHERE, GROUP BY, and HAVING clauses
if any. For example, a row removed because it does not meet the
- WHERE> condition is not seen by any window function.
+ WHERE condition is not seen by any window function.
A query can contain multiple window functions that slice up the data
- in different ways using different OVER> clauses, but
+ in different ways using different OVER clauses, but
they all act on the same collection of rows defined by this virtual table.
- We already saw that ORDER BY> can be omitted if the ordering
+ We already saw that ORDER BY can be omitted if the ordering
of rows is not important. It is also possible to omit PARTITION
- BY>, in which case there is a single partition containing all rows.
+ BY, in which case there is a single partition containing all rows.
There is another important concept associated with window functions:
for each row, there is a set of rows within its partition called its
- window frame>. Some window functions act only
+ window frame. Some window functions act only
on the rows of the window frame, rather than of the whole partition.
- By default, if ORDER BY> is supplied then the frame consists of
+ By default, if ORDER BY is supplied then the frame consists of
all rows from the start of the partition up through the current row, plus
any following rows that are equal to the current row according to the
- ORDER BY> clause. When ORDER BY> is omitted the
+ ORDER BY clause. When ORDER BY is omitted the
default frame consists of all rows in the partition.
There are options to define the window frame in other ways, but
this tutorial does not cover them. See
- for details.
+ for details.
- Here is an example using sum>:
+ Here is an example using sum:
@@ -474,11 +474,11 @@ SELECT salary, sum(salary) OVER () FROM empsalary;
- Above, since there is no ORDER BY> in the OVER>
+ Above, since there is no ORDER BY in the OVER
clause, the window frame is the same as the partition, which for lack of
- PARTITION BY> is the whole table; in other words each sum is
+ PARTITION BY is the whole table; in other words each sum is
taken over the whole table and so we get the same result for each output
- row. But if we add an ORDER BY> clause, we get very different
+ row. But if we add an ORDER BY clause, we get very different
results:
@@ -510,8 +510,8 @@ SELECT salary, sum(salary) OVER (ORDER BY salary) FROM empsalary;
Window functions are permitted only in the SELECT list
- and the ORDER BY> clause of the query. They are forbidden
- elsewhere, such as in GROUP BY>, HAVING>
+ and the ORDER BY clause of the query. They are forbidden
+ elsewhere, such as in GROUP BY, HAVING
and WHERE clauses. This is because they logically
execute after the processing of those clauses. Also, window functions
execute after non-window aggregate functions. This means it is valid to
@@ -534,15 +534,15 @@ WHERE pos < 3;
The above query only shows the rows from the inner query having
- rank> less than 3.
+ rank less than 3.
When a query involves multiple window functions, it is possible to write
- out each one with a separate OVER> clause, but this is
+ out each one with a separate OVER clause, but this is
duplicative and error-prone if the same windowing behavior is wanted
for several functions. Instead, each windowing behavior can be named
- in a WINDOW> clause and then referenced in OVER>.
+ in a WINDOW clause and then referenced in OVER.
For example:
@@ -554,10 +554,10 @@ SELECT sum(salary) OVER w, avg(salary) OVER w
More details about window functions can be found in
- ,
- ,
- , and the
- reference page.
+ ,
+ ,
+ , and the
+ reference page.
@@ -623,13 +623,13 @@ CREATE TABLE capitals (
In this case, a row of capitals
- inherits all columns (name>,
- population>, and altitude>) from its
+ inherits all columns (name,
+ population, and altitude) from its
parent, cities. The
type of the column name is
text, a native PostgreSQL
type for variable length character strings. State capitals have
- an extra column, state>, that shows their state. In
+ an extra column, state, that shows their state. In
PostgreSQL, a table can inherit from
zero or more other tables.
@@ -692,7 +692,7 @@ SELECT name, altitude
Although inheritance is frequently useful, it has not been integrated
with unique constraints or foreign keys, which limits its usefulness.
- See for more detail.
+ See for more detail.
diff --git a/doc/src/sgml/amcheck.sgml b/doc/src/sgml/amcheck.sgml
index dd71dbd679..852e260c09 100644
--- a/doc/src/sgml/amcheck.sgml
+++ b/doc/src/sgml/amcheck.sgml
@@ -8,19 +8,19 @@
- The amcheck> module provides functions that allow you to
+ The amcheck module provides functions that allow you to
verify the logical consistency of the structure of indexes. If the
structure appears to be valid, no error is raised.
- The functions verify various invariants> in the
+ The functions verify various invariants in the
structure of the representation of particular indexes. The
correctness of the access method functions behind index scans and
other important operations relies on these invariants always
holding. For example, certain functions verify, among other things,
- that all B-Tree pages have items in logical> order (e.g.,
- for B-Tree indexes on text>, index tuples should be in
+ that all B-Tree pages have items in logical order (e.g.,
+ for B-Tree indexes on text, index tuples should be in
collated lexical order). If that particular invariant somehow fails
to hold, we can expect binary searches on the affected page to
incorrectly guide index scans, resulting in wrong answers to SQL
@@ -31,11 +31,11 @@
index scans themselves, which may be user-defined operator class
code. For example, B-Tree index verification relies on comparisons
made with one or more B-Tree support function 1 routines. See for details of operator class support
+ linkend="xindex-support"/> for details of operator class support
functions.
- amcheck> functions may be used only by superusers.
+ amcheck functions may be used only by superusers.
@@ -82,7 +82,7 @@ ORDER BY c.relpages DESC LIMIT 10;
(10 rows)
This example shows a session that performs verification of every
- catalog index in the database test>. Details of just
+ catalog index in the database test. Details of just
the 10 largest indexes verified are displayed. Since no error
is raised, all indexes tested appear to be logically consistent.
Naturally, this query could easily be changed to call
@@ -90,10 +90,10 @@ ORDER BY c.relpages DESC LIMIT 10;
database where verification is supported.
- bt_index_check acquires an AccessShareLock>
+ bt_index_check acquires an AccessShareLock
on the target index and the heap relation it belongs to. This lock mode
is the same lock mode acquired on relations by simple
- SELECT> statements.
+ SELECT statements.
bt_index_check does not verify invariants
that span child/parent relationships, nor does it verify that
the target index is consistent with its heap relation. When a
@@ -132,13 +132,13 @@ ORDER BY c.relpages DESC LIMIT 10;
logical inconsistency or other problem.
- A ShareLock> is required on the target index by
+ A ShareLock is required on the target index by
bt_index_parent_check (a
- ShareLock> is also acquired on the heap relation).
+ ShareLock is also acquired on the heap relation).
These locks prevent concurrent data modification from
- INSERT>, UPDATE>, and DELETE>
+ INSERT, UPDATE, and DELETE
commands. The locks also prevent the underlying relation from
- being concurrently processed by VACUUM>, as well as
+ being concurrently processed by VACUUM, as well as
all other utility commands. Note that the function holds locks
only while running, not for the entire transaction.
@@ -159,13 +159,13 @@ ORDER BY c.relpages DESC LIMIT 10;
- Using amcheck> effectively
+ Using amcheck effectively
- amcheck> can be effective at detecting various types of
+ amcheck can be effective at detecting various types of
failure modes that data page
- checksums> will always fail to catch. These include:
+ checksums will always fail to catch. These include:
@@ -176,13 +176,13 @@ ORDER BY c.relpages DESC LIMIT 10;
This includes issues caused by the comparison rules of operating
system collations changing. Comparisons of datums of a collatable
- type like text> must be immutable (just as all
+ type like text must be immutable (just as all
comparisons used for B-Tree index scans must be immutable), which
implies that operating system collation rules must never change.
Though rare, updates to operating system collation rules can
cause these issues. More commonly, an inconsistency in the
collation order between a master server and a standby server is
- implicated, possibly because the major> operating
+ implicated, possibly because the major operating
system version in use is inconsistent. Such inconsistencies will
generally only arise on standby servers, and so can generally
only be detected on standby servers.
@@ -190,27 +190,27 @@ ORDER BY c.relpages DESC LIMIT 10;
If a problem like this arises, it may not affect each individual
index that is ordered using an affected collation, simply because
- indexed> values might happen to have the same
+ indexed values might happen to have the same
absolute ordering regardless of the behavioral inconsistency. See
- and for
- further details about how PostgreSQL> uses
+ and for
+ further details about how PostgreSQL uses
operating system locales and collations.
Corruption caused by hypothetical undiscovered bugs in the
- underlying PostgreSQL> access method code or sort
+ underlying PostgreSQL access method code or sort
code.
Automatic verification of the structural integrity of indexes
plays a role in the general testing of new or proposed
- PostgreSQL> features that could plausibly allow a
+ PostgreSQL features that could plausibly allow a
logical inconsistency to be introduced. One obvious testing
- strategy is to call amcheck> functions continuously
+ strategy is to call amcheck functions continuously
when running the standard regression tests. See for details on running the tests.
+ linkend="regress-run"/> for details on running the tests.
@@ -219,12 +219,12 @@ ORDER BY c.relpages DESC LIMIT 10;
simply not be enabled.
- Note that amcheck> examines a page as represented in some
+ Note that amcheck examines a page as represented in some
shared memory buffer at the time of verification if there is only a
shared buffer hit when accessing the block. Consequently,
- amcheck> does not necessarily examine data read from the
+ amcheck does not necessarily examine data read from the
file system at the time of verification. Note that when checksums are
- enabled, amcheck> may raise an error due to a checksum
+ enabled, amcheck may raise an error due to a checksum
failure when a corrupt block is read into a buffer.
@@ -234,7 +234,7 @@ ORDER BY c.relpages DESC LIMIT 10;
and operating system.
- PostgreSQL> does not protect against correctable
+ PostgreSQL does not protect against correctable
memory errors and it is assumed you will operate using RAM that
uses industry standard Error Correcting Codes (ECC) or better
protection. However, ECC memory is typically only immune to
@@ -244,7 +244,7 @@ ORDER BY c.relpages DESC LIMIT 10;
- In general, amcheck> can only prove the presence of
+ In general, amcheck can only prove the presence of
corruption; it cannot prove its absence.
@@ -252,19 +252,19 @@ ORDER BY c.relpages DESC LIMIT 10;
Repairing corruption
- No error concerning corruption raised by amcheck> should
- ever be a false positive. In practice, amcheck> is more
+ No error concerning corruption raised by amcheck should
+ ever be a false positive. In practice, amcheck is more
likely to find software bugs than problems with hardware.
- amcheck> raises errors in the event of conditions that,
+ amcheck raises errors in the event of conditions that,
by definition, should never happen, and so careful analysis of
- amcheck> errors is often required.
+ amcheck errors is often required.
There is no general method of repairing problems that
- amcheck> detects. An explanation for the root cause of
+ amcheck detects. An explanation for the root cause of
an invariant violation should be sought. may play a useful role in diagnosing
- corruption that amcheck> detects. A REINDEX>
+ linkend="pageinspect"/> may play a useful role in diagnosing
+ corruption that amcheck detects. A REINDEX
may not be effective in repairing corruption.
diff --git a/doc/src/sgml/arch-dev.sgml b/doc/src/sgml/arch-dev.sgml
index c835e87215..53f8049df3 100644
--- a/doc/src/sgml/arch-dev.sgml
+++ b/doc/src/sgml/arch-dev.sgml
@@ -7,7 +7,7 @@
Author
This chapter originated as part of
- , Stefan Simkovics'
+ , Stefan Simkovics'
Master's Thesis prepared at Vienna University of Technology under the direction
of O.Univ.Prof.Dr. Georg Gottlob and Univ.Ass. Mag. Katrin Seyr.
@@ -118,7 +118,7 @@
PostgreSQL is implemented using a
- simple process per user> client/server model. In this model
+ simple process per user client/server model. In this model
there is one client process connected to
exactly one server process. As we do not
know ahead of time how many connections will be made, we have to
@@ -136,10 +136,10 @@
The client process can be any program that understands the
PostgreSQL protocol described in
- . Many clients are based on the
- C-language library libpq>, but several independent
+ . Many clients are based on the
+ C-language library libpq, but several independent
implementations of the protocol exist, such as the Java
- JDBC> driver.
+ JDBC driver.
@@ -184,8 +184,8 @@
text) for valid syntax. If the syntax is correct a
parse tree is built up and handed back;
otherwise an error is returned. The parser and lexer are
- implemented using the well-known Unix tools bison>
- and flex>.
+ implemented using the well-known Unix tools bison
+ and flex.
@@ -251,7 +251,7 @@
back by the parser as input and does the semantic interpretation needed
to understand which tables, functions, and operators are referenced by
the query. The data structure that is built to represent this
- information is called the query tree>.
+ information is called the query tree.
@@ -259,10 +259,10 @@
system catalog lookups can only be done within a transaction, and we
do not wish to start a transaction immediately upon receiving a query
string. The raw parsing stage is sufficient to identify the transaction
- control commands (BEGIN>, ROLLBACK>, etc), and
+ control commands (BEGIN, ROLLBACK, etc), and
these can then be correctly executed without any further analysis.
Once we know that we are dealing with an actual query (such as
- SELECT> or UPDATE>), it is okay to
+ SELECT or UPDATE), it is okay to
start a transaction if we're not already in one. Only then can the
transformation process be invoked.
@@ -270,10 +270,10 @@
The query tree created by the transformation process is structurally
similar to the raw parse tree in most places, but it has many differences
- in detail. For example, a FuncCall> node in the
+ in detail. For example, a FuncCall node in the
parse tree represents something that looks syntactically like a function
- call. This might be transformed to either a FuncExpr>
- or Aggref> node depending on whether the referenced
+ call. This might be transformed to either a FuncExpr
+ or Aggref node depending on whether the referenced
name turns out to be an ordinary function or an aggregate function.
Also, information about the actual data types of columns and expression
results is added to the query tree.
@@ -317,7 +317,7 @@
The query rewriter is discussed in some detail in
- , so there is no need to cover it here.
+ , so there is no need to cover it here.
We will only point out that both the input and the output of the
rewriter are query trees, that is, there is no change in the
representation or level of semantic detail in the trees. Rewriting
@@ -347,17 +347,17 @@
involving large numbers of join operations. In order to determine
a reasonable (not necessarily optimal) query plan in a reasonable amount
of time, PostgreSQL uses a Genetic
- Query Optimizer (see ) when the number of joins
- exceeds a threshold (see ).
+ Query Optimizer (see ) when the number of joins
+ exceeds a threshold (see ).
The planner's search procedure actually works with data structures
- called paths>, which are simply cut-down representations of
+ called paths, which are simply cut-down representations of
plans containing only as much information as the planner needs to make
its decisions. After the cheapest path is determined, a full-fledged
- plan tree> is built to pass to the executor. This represents
+ plan tree is built to pass to the executor. This represents
the desired execution plan in sufficient detail for the executor to run it.
In the rest of this section we'll ignore the distinction between paths
and plans.
@@ -378,12 +378,12 @@
relation.attribute OPR constant. If
relation.attribute happens to match the key of the B-tree
index and OPR is one of the operators listed in
- the index's operator class>, another plan is created using
+ the index's operator class, another plan is created using
the B-tree index to scan the relation. If there are further indexes
present and the restrictions in the query happen to match a key of an
index, further plans will be considered. Index scan plans are also
generated for indexes that have a sort ordering that can match the
- query's ORDER BY> clause (if any), or a sort ordering that
+ query's ORDER BY clause (if any), or a sort ordering that
might be useful for merge joining (see below).
@@ -438,7 +438,7 @@
- If the query uses fewer than
+ If the query uses fewer than
relations, a near-exhaustive search is conducted to find the best
join sequence. The planner preferentially considers joins between any
two relations for which there exist a corresponding join clause in the
@@ -454,7 +454,7 @@
When geqo_threshold is exceeded, the join
sequences considered are determined by heuristics, as described
- in . Otherwise the process is the same.
+ in . Otherwise the process is the same.
@@ -462,9 +462,9 @@
the base relations, plus nested-loop, merge, or hash join nodes as
needed, plus any auxiliary steps needed, such as sort nodes or
aggregate-function calculation nodes. Most of these plan node
- types have the additional ability to do selection>
+ types have the additional ability to do selection
(discarding rows that do not meet a specified Boolean condition)
- and projection> (computation of a derived column set
+ and projection (computation of a derived column set
based on given column values, that is, evaluation of scalar
expressions where needed). One of the responsibilities of the
planner is to attach selection conditions from the
@@ -496,7 +496,7 @@
subplan) is, let's say, a
Sort node and again recursion is needed to obtain
an input row. The child node of the Sort might
- be a SeqScan> node, representing actual reading of a table.
+ be a SeqScan node, representing actual reading of a table.
Execution of this node causes the executor to fetch a row from the
table and return it up to the calling node. The Sort
node will repeatedly call its child to obtain all the rows to be sorted.
@@ -529,24 +529,24 @@
The executor mechanism is used to evaluate all four basic SQL query types:
- SELECT>, INSERT>, UPDATE>, and
- DELETE>. For SELECT>, the top-level executor
+ SELECT, INSERT, UPDATE, and
+ DELETE. For SELECT, the top-level executor
code only needs to send each row returned by the query plan tree off
- to the client. For INSERT>, each returned row is inserted
- into the target table specified for the INSERT>. This is
- done in a special top-level plan node called ModifyTable>.
+ to the client. For INSERT, each returned row is inserted
+ into the target table specified for the INSERT. This is
+ done in a special top-level plan node called ModifyTable.
(A simple
- INSERT ... VALUES> command creates a trivial plan tree
- consisting of a single Result> node, which computes just one
- result row, and ModifyTable> above it to perform the insertion.
- But INSERT ... SELECT> can demand the full power
- of the executor mechanism.) For UPDATE>, the planner arranges
+ INSERT ... VALUES command creates a trivial plan tree
+ consisting of a single Result node, which computes just one
+ result row, and ModifyTable above it to perform the insertion.
+ But INSERT ... SELECT can demand the full power
+ of the executor mechanism.) For UPDATE, the planner arranges
that each computed row includes all the updated column values, plus
- the TID> (tuple ID, or row ID) of the original target row;
- this data is fed into a ModifyTable> node, which uses the
+ the TID (tuple ID, or row ID) of the original target row;
+ this data is fed into a ModifyTable node, which uses the
information to create a new updated row and mark the old row deleted.
- For DELETE>, the only column that is actually returned by the
- plan is the TID, and the ModifyTable> node simply uses the TID
+ For DELETE, the only column that is actually returned by the
+ plan is the TID, and the ModifyTable node simply uses the TID
to visit each target row and mark it deleted.
diff --git a/doc/src/sgml/array.sgml b/doc/src/sgml/array.sgml
index 58878451f0..f4d4a610ef 100644
--- a/doc/src/sgml/array.sgml
+++ b/doc/src/sgml/array.sgml
@@ -10,9 +10,8 @@
PostgreSQL allows columns of a table to be
defined as variable-length multidimensional arrays. Arrays of any
- built-in or user-defined base type, enum type, or composite type
- can be created.
- Arrays of domains are not yet supported.
+ built-in or user-defined base type, enum type, composite type, range type,
+ or domain can be created.
@@ -33,7 +32,7 @@ CREATE TABLE sal_emp (
);
As shown, an array data type is named by appending square brackets
- ([]>) to the data type name of the array elements. The
+ ([]) to the data type name of the array elements. The
above command will create a table named
sal_emp with a column of type
text (name), a
@@ -70,7 +69,7 @@ CREATE TABLE tictactoe (
An alternative syntax, which conforms to the SQL standard by using
- the keyword ARRAY>, can be used for one-dimensional arrays.
+ the keyword ARRAY, can be used for one-dimensional arrays.
pay_by_quarter could have been defined
as:
@@ -80,7 +79,7 @@ CREATE TABLE tictactoe (
pay_by_quarter integer ARRAY,
- As before, however, PostgreSQL> does not enforce the
+ As before, however, PostgreSQL does not enforce the
size restriction in any case.
@@ -108,8 +107,8 @@ CREATE TABLE tictactoe (
for the type, as recorded in its pg_type entry.
Among the standard data types provided in the
PostgreSQL distribution, all use a comma
- (,>), except for type box> which uses a semicolon
- (;>). Each val is
+ (,), except for type box which uses a semicolon
+ (;). Each val is
either a constant of the array element type, or a subarray. An example
of an array constant is:
@@ -120,16 +119,16 @@ CREATE TABLE tictactoe (
- To set an element of an array constant to NULL, write NULL>
+ To set an element of an array constant to NULL, write NULL
for the element value. (Any upper- or lower-case variant of
- NULL> will do.) If you want an actual string value
- NULL>, you must put double quotes around it.
+ NULL will do.) If you want an actual string value
+ NULL, you must put double quotes around it.
(These kinds of array constants are actually only a special case of
the generic type constants discussed in . The constant is initially
+ linkend="sql-syntax-constants-generic"/>. The constant is initially
treated as a string and passed to the array input conversion
routine. An explicit type specification might be necessary.)
@@ -177,7 +176,7 @@ ERROR: multidimensional arrays must have array expressions with matching dimens
- The ARRAY> constructor syntax can also be used:
+ The ARRAY constructor syntax can also be used:
INSERT INTO sal_emp
VALUES ('Bill',
@@ -191,9 +190,9 @@ INSERT INTO sal_emp
Notice that the array elements are ordinary SQL constants or
expressions; for instance, string literals are single quoted, instead of
- double quoted as they would be in an array literal. The ARRAY>
+ double quoted as they would be in an array literal. The ARRAY
constructor syntax is discussed in more detail in
- .
+ .
@@ -223,8 +222,8 @@ SELECT name FROM sal_emp WHERE pay_by_quarter[1] <> pay_by_quarter[2];
The array subscript numbers are written within square brackets.
By default PostgreSQL uses a
one-based numbering convention for arrays, that is,
- an array of n> elements starts with array[1] and
- ends with array[n>].
+ an array of n elements starts with array[1] and
+ ends with array[n].
@@ -260,8 +259,8 @@ SELECT schedule[1:2][1:1] FROM sal_emp WHERE name = 'Bill';
If any dimension is written as a slice, i.e., contains a colon, then all
dimensions are treated as slices. Any dimension that has only a single
number (no colon) is treated as being from 1
- to the number specified. For example, [2]> is treated as
- [1:2]>, as in this example:
+ to the number specified. For example, [2] is treated as
+ [1:2], as in this example:
SELECT schedule[1:2][2] FROM sal_emp WHERE name = 'Bill';
@@ -273,7 +272,7 @@ SELECT schedule[1:2][2] FROM sal_emp WHERE name = 'Bill';
To avoid confusion with the non-slice case, it's best to use slice syntax
- for all dimensions, e.g., [1:2][1:1]>, not [2][1:1]>.
+ for all dimensions, e.g., [1:2][1:1], not [2][1:1].
@@ -303,9 +302,9 @@ SELECT schedule[:][1:1] FROM sal_emp WHERE name = 'Bill';
An array subscript expression will return null if either the array itself or
any of the subscript expressions are null. Also, null is returned if a
subscript is outside the array bounds (this case does not raise an error).
- For example, if schedule>
- currently has the dimensions [1:3][1:2]> then referencing
- schedule[3][3]> yields NULL. Similarly, an array reference
+ For example, if schedule
+ currently has the dimensions [1:3][1:2] then referencing
+ schedule[3][3] yields NULL. Similarly, an array reference
with the wrong number of subscripts yields a null rather than an error.
@@ -424,16 +423,16 @@ UPDATE sal_emp SET pay_by_quarter[1:2] = '{27000,27000}'
A stored array value can be enlarged by assigning to elements not already
present. Any positions between those previously present and the newly
assigned elements will be filled with nulls. For example, if array
- myarray> currently has 4 elements, it will have six
- elements after an update that assigns to myarray[6]>;
- myarray[5]> will contain null.
+ myarray currently has 4 elements, it will have six
+ elements after an update that assigns to myarray[6];
+ myarray[5] will contain null.
Currently, enlargement in this fashion is only allowed for one-dimensional
arrays, not multidimensional arrays.
Subscripted assignment allows creation of arrays that do not use one-based
- subscripts. For example one might assign to myarray[-2:7]> to
+ subscripts. For example one might assign to myarray[-2:7] to
create an array with subscript values from -2 to 7.
@@ -458,8 +457,8 @@ SELECT ARRAY[5,6] || ARRAY[[1,2],[3,4]];
The concatenation operator allows a single element to be pushed onto the
beginning or end of a one-dimensional array. It also accepts two
- N>-dimensional arrays, or an N>-dimensional
- and an N+1>-dimensional array.
+ N-dimensional arrays, or an N-dimensional
+ and an N+1-dimensional array.
@@ -502,10 +501,10 @@ SELECT array_dims(ARRAY[[1,2],[3,4]] || ARRAY[[5,6],[7,8],[9,0]]);
- When an N>-dimensional array is pushed onto the beginning
- or end of an N+1>-dimensional array, the result is
- analogous to the element-array case above. Each N>-dimensional
- sub-array is essentially an element of the N+1>-dimensional
+ When an N-dimensional array is pushed onto the beginning
+ or end of an N+1-dimensional array, the result is
+ analogous to the element-array case above. Each N-dimensional
+ sub-array is essentially an element of the N+1-dimensional
array's outer dimension. For example:
SELECT array_dims(ARRAY[1,2] || ARRAY[[3,4],[5,6]]);
@@ -588,9 +587,9 @@ SELECT array_append(ARRAY[1, 2], NULL); -- this might have been meant
The heuristic it uses to resolve the constant's type is to assume it's of
the same type as the operator's other input — in this case,
integer array. So the concatenation operator is presumed to
- represent array_cat>, not array_append>. When
+ represent array_cat, not array_append. When
that's the wrong choice, it could be fixed by casting the constant to the
- array's element type; but explicit use of array_append> might
+ array's element type; but explicit use of array_append might
be a preferable solution.
@@ -617,7 +616,7 @@ SELECT * FROM sal_emp WHERE pay_by_quarter[1] = 10000 OR
However, this quickly becomes tedious for large arrays, and is not
helpful if the size of the array is unknown. An alternative method is
- described in . The above
+ described in . The above
query could be replaced by:
@@ -634,7 +633,7 @@ SELECT * FROM sal_emp WHERE 10000 = ALL (pay_by_quarter);
- Alternatively, the generate_subscripts> function can be used.
+ Alternatively, the generate_subscripts function can be used.
For example:
@@ -645,26 +644,26 @@ SELECT * FROM
WHERE pay_by_quarter[s] = 10000;
- This function is described in .
+ This function is described in .
- You can also search an array using the &&> operator,
+ You can also search an array using the && operator,
which checks whether the left operand overlaps with the right operand.
For instance:
-SELECT * FROM sal_emp WHERE pay_by_quarter && ARRAY[10000];
+SELECT * FROM sal_emp WHERE pay_by_quarter && ARRAY[10000];
This and other array operators are further described in
- . It can be accelerated by an appropriate
- index, as described in .
+ . It can be accelerated by an appropriate
+ index, as described in .
- You can also search for specific values in an array using the array_position>
- and array_positions> functions. The former returns the subscript of
+ You can also search for specific values in an array using the array_position
+ and array_positions functions. The former returns the subscript of
the first occurrence of a value in an array; the latter returns an array with the
subscripts of all occurrences of the value in the array. For example:
@@ -704,13 +703,13 @@ SELECT array_positions(ARRAY[1, 4, 3, 1, 3, 4, 2, 1], 1);
The external text representation of an array value consists of items that
are interpreted according to the I/O conversion rules for the array's
element type, plus decoration that indicates the array structure.
- The decoration consists of curly braces ({> and }>)
+ The decoration consists of curly braces ({ and })
around the array value plus delimiter characters between adjacent items.
- The delimiter character is usually a comma (,>) but can be
- something else: it is determined by the typdelim> setting
+ The delimiter character is usually a comma (,) but can be
+ something else: it is determined by the typdelim setting
for the array's element type. Among the standard data types provided
in the PostgreSQL distribution, all use a comma,
- except for type box>, which uses a semicolon (;>).
+ except for type box, which uses a semicolon (;).
In a multidimensional array, each dimension (row, plane,
cube, etc.) gets its own level of curly braces, and delimiters
must be written between adjacent curly-braced entities of the same level.
@@ -720,7 +719,7 @@ SELECT array_positions(ARRAY[1, 4, 3, 1, 3, 4, 2, 1], 1);
The array output routine will put double quotes around element values
if they are empty strings, contain curly braces, delimiter characters,
double quotes, backslashes, or white space, or match the word
- NULL>. Double quotes and backslashes
+ NULL. Double quotes and backslashes
embedded in element values will be backslash-escaped. For numeric
data types it is safe to assume that double quotes will never appear, but
for textual data types one should be prepared to cope with either the presence
@@ -732,10 +731,10 @@ SELECT array_positions(ARRAY[1, 4, 3, 1, 3, 4, 2, 1], 1);
set to one. To represent arrays with other lower bounds, the array
subscript ranges can be specified explicitly before writing the
array contents.
- This decoration consists of square brackets ([]>)
+ This decoration consists of square brackets ([])
around each array dimension's lower and upper bounds, with
- a colon (:>) delimiter character in between. The
- array dimension decoration is followed by an equal sign (=>).
+ a colon (:) delimiter character in between. The
+ array dimension decoration is followed by an equal sign (=).
For example:
SELECT f1[1][-2][3] AS e1, f1[1][-1][5] AS e2
@@ -751,23 +750,23 @@ SELECT f1[1][-2][3] AS e1, f1[1][-1][5] AS e2
- If the value written for an element is NULL> (in any case
+ If the value written for an element is NULL (in any case
variant), the element is taken to be NULL. The presence of any quotes
or backslashes disables this and allows the literal string value
- NULL> to be entered. Also, for backward compatibility with
- pre-8.2 versions of PostgreSQL>, the configuration parameter can be turned
- off> to suppress recognition of NULL> as a NULL.
+ NULL to be entered. Also, for backward compatibility with
+ pre-8.2 versions of PostgreSQL, the configuration parameter can be turned
+ off to suppress recognition of NULL as a NULL.
As shown previously, when writing an array value you can use double
- quotes around any individual array element. You must> do so
+ quotes around any individual array element. You must do so
if the element value would otherwise confuse the array-value parser.
For example, elements containing curly braces, commas (or the data type's
delimiter character), double quotes, backslashes, or leading or trailing
whitespace must be double-quoted. Empty strings and strings matching the
- word NULL> must be quoted, too. To put a double quote or
+ word NULL must be quoted, too. To put a double quote or
backslash in a quoted array element value, use escape string syntax
and precede it with a backslash. Alternatively, you can avoid quotes and use
backslash-escaping to protect all data characters that would otherwise
@@ -786,29 +785,29 @@ SELECT f1[1][-2][3] AS e1, f1[1][-1][5] AS e2
Remember that what you write in an SQL command will first be interpreted
as a string literal, and then as an array. This doubles the number of
- backslashes you need. For example, to insert a text> array
+ backslashes you need. For example, to insert a text array
value containing a backslash and a double quote, you'd need to write:
INSERT ... VALUES (E'{"\\\\","\\""}');
The escape string processor removes one level of backslashes, so that
- what arrives at the array-value parser looks like {"\\","\""}>.
- In turn, the strings fed to the text> data type's input routine
- become \> and "> respectively. (If we were working
+ what arrives at the array-value parser looks like {"\\","\""}.
+ In turn, the strings fed to the text data type's input routine
+ become \ and " respectively. (If we were working
with a data type whose input routine also treated backslashes specially,
- bytea> for example, we might need as many as eight backslashes
+ bytea for example, we might need as many as eight backslashes
in the command to get one backslash into the stored array element.)
- Dollar quoting (see ) can be
+ Dollar quoting (see ) can be
used to avoid the need to double backslashes.
- The ARRAY> constructor syntax (see
- ) is often easier to work
+ The ARRAY constructor syntax (see
+ ) is often easier to work
with than the array-literal syntax when writing array values in SQL
- commands. In ARRAY>, individual element values are written the
+ commands. In ARRAY, individual element values are written the
same way they would be written when not members of an array.
diff --git a/doc/src/sgml/auth-delay.sgml b/doc/src/sgml/auth-delay.sgml
index 9a6e3e9bb4..bd3ef7128d 100644
--- a/doc/src/sgml/auth-delay.sgml
+++ b/doc/src/sgml/auth-delay.sgml
@@ -18,7 +18,7 @@
In order to function, this module must be loaded via
- in postgresql.conf>.
+ in postgresql.conf.
@@ -29,7 +29,7 @@
auth_delay.milliseconds (int)
- auth_delay.milliseconds> configuration parameter
+ auth_delay.milliseconds configuration parameter
@@ -42,7 +42,7 @@
- These parameters must be set in postgresql.conf>.
+ These parameters must be set in postgresql.conf.
Typical usage might be:
diff --git a/doc/src/sgml/auto-explain.sgml b/doc/src/sgml/auto-explain.sgml
index 38e6f50c80..08b67f2600 100644
--- a/doc/src/sgml/auto-explain.sgml
+++ b/doc/src/sgml/auto-explain.sgml
@@ -10,7 +10,7 @@
The auto_explain module provides a means for
logging execution plans of slow statements automatically, without
- having to run
+ having to run
by hand. This is especially helpful for tracking down un-optimized queries
in large applications.
@@ -24,10 +24,10 @@ LOAD 'auto_explain';
(You must be superuser to do that.) More typical usage is to preload
- it into some or all sessions by including auto_explain> in
- or
- in
- postgresql.conf>. Then you can track unexpectedly slow queries
+ it into some or all sessions by including auto_explain in
+ or
+ in
+ postgresql.conf. Then you can track unexpectedly slow queries
no matter when they happen. Of course there is a price in overhead for
that.
@@ -47,7 +47,7 @@ LOAD 'auto_explain';
auto_explain.log_min_duration (integer)
- auto_explain.log_min_duration> configuration parameter
+ auto_explain.log_min_duration configuration parameter
@@ -66,13 +66,13 @@ LOAD 'auto_explain';
auto_explain.log_analyze (boolean)
- auto_explain.log_analyze> configuration parameter
+ auto_explain.log_analyze configuration parameter
- auto_explain.log_analyze causes EXPLAIN ANALYZE>
- output, rather than just EXPLAIN> output, to be printed
+ auto_explain.log_analyze causes EXPLAIN ANALYZE
+ output, rather than just EXPLAIN output, to be printed
when an execution plan is logged. This parameter is off by default.
Only superusers can change this setting.
@@ -92,14 +92,14 @@ LOAD 'auto_explain';
auto_explain.log_buffers (boolean)
- auto_explain.log_buffers> configuration parameter
+ auto_explain.log_buffers configuration parameterauto_explain.log_buffers controls whether buffer
usage statistics are printed when an execution plan is logged; it's
- equivalent to the BUFFERS> option of EXPLAIN>.
+ equivalent to the BUFFERS option of EXPLAIN.
This parameter has no effect
unless auto_explain.log_analyze is enabled.
This parameter is off by default.
@@ -112,14 +112,14 @@ LOAD 'auto_explain';
auto_explain.log_timing (boolean)
- auto_explain.log_timing> configuration parameter
+ auto_explain.log_timing configuration parameterauto_explain.log_timing controls whether per-node
timing information is printed when an execution plan is logged; it's
- equivalent to the TIMING> option of EXPLAIN>.
+ equivalent to the TIMING option of EXPLAIN.
The overhead of repeatedly reading the system clock can slow down
queries significantly on some systems, so it may be useful to set this
parameter to off when only actual row counts, and not exact times, are
@@ -136,7 +136,7 @@ LOAD 'auto_explain';
auto_explain.log_triggers (boolean)
- auto_explain.log_triggers> configuration parameter
+ auto_explain.log_triggers configuration parameter
@@ -155,14 +155,14 @@ LOAD 'auto_explain';
auto_explain.log_verbose (boolean)
- auto_explain.log_verbose> configuration parameter
+ auto_explain.log_verbose configuration parameterauto_explain.log_verbose controls whether verbose
details are printed when an execution plan is logged; it's
- equivalent to the VERBOSE> option of EXPLAIN>.
+ equivalent to the VERBOSE option of EXPLAIN.
This parameter is off by default.
Only superusers can change this setting.
@@ -173,13 +173,13 @@ LOAD 'auto_explain';
auto_explain.log_format (enum)
- auto_explain.log_format> configuration parameter
+ auto_explain.log_format configuration parameterauto_explain.log_format selects the
- EXPLAIN> output format to be used.
+ EXPLAIN output format to be used.
The allowed values are text, xml,
json, and yaml. The default is text.
Only superusers can change this setting.
@@ -191,7 +191,7 @@ LOAD 'auto_explain';
auto_explain.log_nested_statements (boolean)
- auto_explain.log_nested_statements> configuration parameter
+ auto_explain.log_nested_statements configuration parameter
@@ -208,7 +208,7 @@ LOAD 'auto_explain';
auto_explain.sample_rate (real)
- auto_explain.sample_rate> configuration parameter
+ auto_explain.sample_rate configuration parameter
@@ -224,7 +224,7 @@ LOAD 'auto_explain';
In ordinary usage, these parameters are set
- in postgresql.conf>, although superusers can alter them
+ in postgresql.conf, although superusers can alter them
on-the-fly within their own sessions.
Typical usage might be:
diff --git a/doc/src/sgml/backup.sgml b/doc/src/sgml/backup.sgml
index 0e7c6e2051..9d8e69056f 100644
--- a/doc/src/sgml/backup.sgml
+++ b/doc/src/sgml/backup.sgml
@@ -3,10 +3,10 @@
Backup and Restore
- backup>>
+ backup
- As with everything that contains valuable data, PostgreSQL>
+ As with everything that contains valuable data, PostgreSQL
databases should be backed up regularly. While the procedure is
essentially simple, it is important to have a clear understanding of
the underlying techniques and assumptions.
@@ -14,9 +14,9 @@
There are three fundamentally different approaches to backing up
- PostgreSQL> data:
+ PostgreSQL data:
- SQL> dump
+ SQL dumpFile system level backupContinuous archiving
@@ -25,30 +25,30 @@
- SQL> Dump
+ SQL Dump
The idea behind this dump method is to generate a file with SQL
commands that, when fed back to the server, will recreate the
database in the same state as it was at the time of the dump.
- PostgreSQL> provides the utility program
- for this purpose. The basic usage of this
+ PostgreSQL provides the utility program
+ for this purpose. The basic usage of this
command is:
pg_dump dbname > outfile
- As you see, pg_dump> writes its result to the
+ As you see, pg_dump writes its result to the
standard output. We will see below how this can be useful.
- While the above command creates a text file, pg_dump>
+ While the above command creates a text file, pg_dump
can create files in other formats that allow for parallelism and more
fine-grained control of object restoration.
- pg_dump> is a regular PostgreSQL>
+ pg_dump is a regular PostgreSQL
client application (albeit a particularly clever one). This means
that you can perform this backup procedure from any remote host that has
- access to the database. But remember that pg_dump>
+ access to the database. But remember that pg_dump
does not operate with special permissions. In particular, it must
have read access to all tables that you want to back up, so in order
to back up the entire database you almost always have to run it as a
@@ -60,9 +60,9 @@ pg_dump dbname >
- To specify which database server pg_dump> should
+ To specify which database server pg_dump should
contact, use the command line options ). psql
+ supports options similar to pg_dump for specifying
the database server to connect to and the user name to use. See
- the reference page for more information.
+ the reference page for more information.
Non-text file dumps are restored using the utility.
+ linkend="app-pgrestore"/> utility.
@@ -134,10 +134,10 @@ psql dbname <
- By default, the psql> script will continue to
+ By default, the psql script will continue to
execute after an SQL error is encountered. You might wish to run
psql with
- the ON_ERROR_STOP> variable set to alter that
+ the ON_ERROR_STOP variable set to alter that
behavior and have psql exit with an
exit status of 3 if an SQL error occurs:
@@ -147,8 +147,8 @@ psql --set ON_ERROR_STOP=on dbname < infile
Alternatively, you can specify that the whole dump should be
restored as a single transaction, so the restore is either fully
completed or fully rolled back. This mode can be specified by
- passing the
-1> or
--single-transaction>
- command-line options to psql>. When using this
+ passing the
-1
or
--single-transaction
+ command-line options to psql. When using this
mode, be aware that even a minor error can rollback a
restore that has already run for many hours. However, that might
still be preferable to manually cleaning up a complex database
@@ -156,79 +156,79 @@ psql --set ON_ERROR_STOP=on dbname < infile
- The ability of pg_dump> and psql> to
+ The ability of pg_dump and psql to
write to or read from pipes makes it possible to dump a database
directly from one server to another, for example:
-pg_dump -h host1> dbname> | psql -h host2> dbname>
+pg_dump -h host1dbname | psql -h host2dbname
- The dumps produced by pg_dump> are relative to
- template0>. This means that any languages, procedures,
- etc. added via template1> will also be dumped by
- pg_dump>. As a result, when restoring, if you are
- using a customized template1>, you must create the
- empty database from template0>, as in the example
+ The dumps produced by pg_dump are relative to
+ template0. This means that any languages, procedures,
+ etc. added via template1 will also be dumped by
+ pg_dump. As a result, when restoring, if you are
+ using a customized template1, you must create the
+ empty database from template0, as in the example
above.
After restoring a backup, it is wise to run on each
+ linkend="sql-analyze"/> on each
database so the query optimizer has useful statistics;
- see
- and for more information.
+ see
+ and for more information.
For more advice on how to load large amounts of data
- into PostgreSQL> efficiently, refer to .
+ into PostgreSQL efficiently, refer to .
- Using pg_dumpall>
+ Using pg_dumpall
- pg_dump> dumps only a single database at a time,
+ pg_dump dumps only a single database at a time,
and it does not dump information about roles or tablespaces
(because those are cluster-wide rather than per-database).
To support convenient dumping of the entire contents of a database
- cluster, the program is provided.
- pg_dumpall> backs up each database in a given
+ cluster, the program is provided.
+ pg_dumpall backs up each database in a given
cluster, and also preserves cluster-wide data such as role and
tablespace definitions. The basic usage of this command is:
-pg_dumpall > outfile>
+pg_dumpall > outfile
- The resulting dump can be restored with psql>:
+ The resulting dump can be restored with psql:
psql -f infile postgres
(Actually, you can specify any existing database name to start from,
- but if you are loading into an empty cluster then postgres>
+ but if you are loading into an empty cluster then postgres
should usually be used.) It is always necessary to have
- database superuser access when restoring a pg_dumpall>
+ database superuser access when restoring a pg_dumpall
dump, as that is required to restore the role and tablespace information.
If you use tablespaces, make sure that the tablespace paths in the
dump are appropriate for the new installation.
- pg_dumpall> works by emitting commands to re-create
+ pg_dumpall works by emitting commands to re-create
roles, tablespaces, and empty databases, then invoking
- pg_dump> for each database. This means that while
+ pg_dump for each database. This means that while
each database will be internally consistent, the snapshots of
different databases are not synchronized.
Cluster-wide data can be dumped alone using the
- pg_dumpall>
--globals-only> option.
+ pg_dumpall
--globals-only
option.
This is necessary to fully backup the cluster if running the
- pg_dump> command on individual databases.
+ pg_dump command on individual databases.
@@ -237,8 +237,8 @@ psql -f infile postgres
Some operating systems have maximum file size limits that cause
- problems when creating large pg_dump> output files.
- Fortunately, pg_dump> can write to the standard
+ problems when creating large pg_dump output files.
+ Fortunately, pg_dump can write to the standard
output, so you can use standard Unix tools to work around this
potential problem. There are several possible methods:
@@ -268,7 +268,7 @@ cat filename.gz | gunzip | psql
- Use split>.
+ Use split.
The split command
allows you to split the output into smaller files that are
@@ -288,10 +288,10 @@ cat filename* | psql
- Use pg_dump>'s custom dump format.
+ Use pg_dump's custom dump format.
If PostgreSQL was built on a system with the
- zlib> compression library installed, the custom dump
+ zlib compression library installed, the custom dump
format will compress data as it writes it to the output file. This will
produce dump file sizes similar to using gzip, but it
has the added advantage that tables can be restored selectively. The
@@ -301,25 +301,25 @@ cat filename* | psql dbname > filename
- A custom-format dump is not a script for psql>, but
- instead must be restored with pg_restore>, for example:
+ A custom-format dump is not a script for psql, but
+ instead must be restored with pg_restore, for example:
pg_restore -d dbnamefilename
- See the and reference pages for details.
+ See the and reference pages for details.
- For very large databases, you might need to combine split>
+ For very large databases, you might need to combine split
with one of the other two approaches.
- Use pg_dump>'s parallel dump feature.
+ Use pg_dump's parallel dump feature.
To speed up the dump of a large database, you can use
pg_dump's parallel mode. This will dump
@@ -344,8 +344,8 @@ pg_dump -j num -F d -f
An alternative backup strategy is to directly copy the files that
- PostgreSQL> uses to store the data in the database;
- explains where these files
+ PostgreSQL uses to store the data in the database;
+ explains where these files
are located. You can use whatever method you prefer
for doing file system backups; for example:
@@ -356,20 +356,20 @@ tar -cf backup.tar /usr/local/pgsql/data
There are two restrictions, however, which make this method
- impractical, or at least inferior to the pg_dump>
+ impractical, or at least inferior to the pg_dump
method:
- The database server must> be shut down in order to
+ The database server must be shut down in order to
get a usable backup. Half-way measures such as disallowing all
connections will not work
(in part because tar and similar tools do not take
an atomic snapshot of the state of the file system,
but also because of internal buffering within the server).
Information about stopping the server can be found in
- . Needless to say, you
+ . Needless to say, you
also need to shut down the server before restoring the data.
@@ -379,7 +379,7 @@ tar -cf backup.tar /usr/local/pgsql/data
If you have dug into the details of the file system layout of the
database, you might be tempted to try to back up or restore only certain
individual tables or databases from their respective files or
- directories. This will not> work because the
+ directories. This will not work because the
information contained in these files is not usable without
the commit log files,
pg_xact/*, which contain the commit status of
@@ -399,7 +399,7 @@ tar -cf backup.tar /usr/local/pgsql/data
consistent snapshot of the data directory, if the
file system supports that functionality (and you are willing to
trust that it is implemented correctly). The typical procedure is
- to make a frozen snapshot> of the volume containing the
+ to make a frozen snapshot of the volume containing the
database, then copy the whole data directory (not just parts, see
above) from the snapshot to a backup device, then release the frozen
snapshot. This will work even while the database server is running.
@@ -419,7 +419,7 @@ tar -cf backup.tar /usr/local/pgsql/data
the volumes. For example, if your data files and WAL log are on different
disks, or if tablespaces are on different file systems, it might
not be possible to use snapshot backup because the snapshots
- must> be simultaneous.
+ must be simultaneous.
Read your file system documentation very carefully before trusting
the consistent-snapshot technique in such situations.
@@ -428,20 +428,20 @@ tar -cf backup.tar /usr/local/pgsql/data
If simultaneous snapshots are not possible, one option is to shut down
the database server long enough to establish all the frozen snapshots.
Another option is to perform a continuous archiving base backup () because such backups are immune to file
+ linkend="backup-base-backup"/>) because such backups are immune to file
system changes during the backup. This requires enabling continuous
archiving just during the backup process; restore is done using
- continuous archive recovery ().
+ continuous archive recovery ().
- Another option is to use rsync> to perform a file
- system backup. This is done by first running rsync>
+ Another option is to use rsync to perform a file
+ system backup. This is done by first running rsync
while the database server is running, then shutting down the database
- server long enough to do an rsync --checksum>.
- (
--checksum> is necessary because rsync> only
+ server long enough to do an rsync --checksum.
+ (
--checksum
is necessary because rsync only
has file modification-time granularity of one second.) The
- second rsync> will be quicker than the first,
+ second rsync will be quicker than the first,
because it has relatively little data to transfer, and the end result
will be consistent because the server was down. This method
allows a file system backup to be performed with minimal downtime.
@@ -471,12 +471,12 @@ tar -cf backup.tar /usr/local/pgsql/data
- At all times, PostgreSQL> maintains a
- write ahead log> (WAL) in the pg_wal/>
+ At all times, PostgreSQL maintains a
+ write ahead log (WAL) in the pg_wal/
subdirectory of the cluster's data directory. The log records
every change made to the database's data files. This log exists
primarily for crash-safety purposes: if the system crashes, the
- database can be restored to consistency by replaying> the
+ database can be restored to consistency by replaying the
log entries made since the last checkpoint. However, the existence
of the log makes it possible to use a third strategy for backing up
databases: we can combine a file-system-level backup with backup of
@@ -492,7 +492,7 @@ tar -cf backup.tar /usr/local/pgsql/data
Any internal inconsistency in the backup will be corrected by log
replay (this is not significantly different from what happens during
crash recovery). So we do not need a file system snapshot capability,
- just tar> or a similar archiving tool.
+ just tar or a similar archiving tool.
@@ -508,7 +508,7 @@ tar -cf backup.tar /usr/local/pgsql/data
It is not necessary to replay the WAL entries all the
way to the end. We could stop the replay at any point and have a
consistent snapshot of the database as it was at that time. Thus,
- this technique supports point-in-time recovery>: it is
+ this technique supports point-in-time recovery: it is
possible to restore the database to its state at any time since your base
backup was taken.
@@ -517,7 +517,7 @@ tar -cf backup.tar /usr/local/pgsql/data
If we continuously feed the series of WAL files to another
machine that has been loaded with the same base backup file, we
- have a warm standby> system: at any point we can bring up
+ have a warm standby system: at any point we can bring up
the second machine and it will have a nearly-current copy of the
database.
@@ -530,7 +530,7 @@ tar -cf backup.tar /usr/local/pgsql/data
pg_dump and
pg_dumpall do not produce file-system-level
backups and cannot be used as part of a continuous-archiving solution.
- Such dumps are logical> and do not contain enough
+ Such dumps are logical and do not contain enough
information to be used by WAL replay.
@@ -546,10 +546,10 @@ tar -cf backup.tar /usr/local/pgsql/data
To recover successfully using continuous archiving (also called
- online backup> by many database vendors), you need a continuous
+ online backup by many database vendors), you need a continuous
sequence of archived WAL files that extends back at least as far as the
start time of your backup. So to get started, you should set up and test
- your procedure for archiving WAL files before> you take your
+ your procedure for archiving WAL files before you take your
first base backup. Accordingly, we first discuss the mechanics of
archiving WAL files.
@@ -558,17 +558,17 @@ tar -cf backup.tar /usr/local/pgsql/data
Setting Up WAL Archiving
- In an abstract sense, a running PostgreSQL> system
+ In an abstract sense, a running PostgreSQL system
produces an indefinitely long sequence of WAL records. The system
physically divides this sequence into WAL segment
- files>, which are normally 16MB apiece (although the segment size
- can be altered when building PostgreSQL>). The segment
+ files, which are normally 16MB apiece (although the segment size
+ can be altered during initdb). The segment
files are given numeric names that reflect their position in the
abstract WAL sequence. When not using WAL archiving, the system
normally creates just a few segment files and then
- recycles> them by renaming no-longer-needed segment files
+ recycles them by renaming no-longer-needed segment files
to higher segment numbers. It's assumed that segment files whose
- contents precede the checkpoint-before-last are no longer of
+ contents precede the last checkpoint are no longer of
interest and can be recycled.
@@ -577,33 +577,33 @@ tar -cf backup.tar /usr/local/pgsql/data
file once it is filled, and save that data somewhere before the segment
file is recycled for reuse. Depending on the application and the
available hardware, there could be many different ways of saving
- the data somewhere>: we could copy the segment files to an NFS-mounted
+ the data somewhere: we could copy the segment files to an NFS-mounted
directory on another machine, write them onto a tape drive (ensuring that
you have a way of identifying the original name of each file), or batch
them together and burn them onto CDs, or something else entirely. To
provide the database administrator with flexibility,
- PostgreSQL> tries not to make any assumptions about how
- the archiving will be done. Instead, PostgreSQL> lets
+ PostgreSQL tries not to make any assumptions about how
+ the archiving will be done. Instead, PostgreSQL lets
the administrator specify a shell command to be executed to copy a
completed segment file to wherever it needs to go. The command could be
- as simple as a cp>, or it could invoke a complex shell
+ as simple as a cp, or it could invoke a complex shell
script — it's all up to you.
- To enable WAL archiving, set the
- configuration parameter to replica> or higher,
- to on>,
+ To enable WAL archiving, set the
+ configuration parameter to replica or higher,
+ to on,
and specify the shell command to use in the configuration parameter. In practice
+ linkend="guc-archive-command"/> configuration parameter. In practice
these settings will always be placed in the
postgresql.conf file.
- In archive_command>,
- %p> is replaced by the path name of the file to
- archive, while %f> is replaced by only the file name.
+ In archive_command,
+ %p is replaced by the path name of the file to
+ archive, while %f is replaced by only the file name.
(The path name is relative to the current working directory,
i.e., the cluster's data directory.)
- Use %%> if you need to embed an actual %>
+ Use %% if you need to embed an actual %
character in the command. The simplest useful command is something
like:
@@ -611,9 +611,9 @@ archive_command = 'test ! -f /mnt/server/archivedir/%f && cp %p /mnt/ser
archive_command = 'copy "%p" "C:\\server\\archivedir\\%f"' # Windows
which will copy archivable WAL segments to the directory
- /mnt/server/archivedir>. (This is an example, not a
+ /mnt/server/archivedir. (This is an example, not a
recommendation, and might not work on all platforms.) After the
- %p> and %f> parameters have been replaced,
+ %p and %f parameters have been replaced,
the actual command executed might look like this:
test ! -f /mnt/server/archivedir/00000001000000A900000065 && cp pg_wal/00000001000000A900000065 /mnt/server/archivedir/00000001000000A900000065
@@ -623,7 +623,7 @@ test ! -f /mnt/server/archivedir/00000001000000A900000065 && cp pg_wal/0
The archive command will be executed under the ownership of the same
- user that the PostgreSQL> server is running as. Since
+ user that the PostgreSQL server is running as. Since
the series of WAL files being archived contains effectively everything
in your database, you will want to be sure that the archived data is
protected from prying eyes; for example, archive into a directory that
@@ -633,9 +633,9 @@ test ! -f /mnt/server/archivedir/00000001000000A900000065 && cp pg_wal/0
It is important that the archive command return zero exit status if and
only if it succeeds. Upon getting a zero result,
- PostgreSQL> will assume that the file has been
+ PostgreSQL will assume that the file has been
successfully archived, and will remove or recycle it. However, a nonzero
- status tells PostgreSQL> that the file was not archived;
+ status tells PostgreSQL that the file was not archived;
it will try again periodically until it succeeds.
@@ -650,14 +650,14 @@ test ! -f /mnt/server/archivedir/00000001000000A900000065 && cp pg_wal/0
It is advisable to test your proposed archive command to ensure that it
indeed does not overwrite an existing file, and that it returns
- nonzero status in this case>.
+ nonzero status in this case.
The example command above for Unix ensures this by including a separate
- test> step. On some Unix platforms, cp> has
- switches such as
-i> that can be used to do the same thing
+ test step. On some Unix platforms, cp has
+ switches such as
-i
that can be used to do the same thing
less verbosely, but you should not rely on these without verifying that
- the right exit status is returned. (In particular, GNU cp>
- will return status zero when
-i> is used and the target file
- already exists, which is not> the desired behavior.)
+ the right exit status is returned. (In particular, GNU cp
+ will return status zero when
-i
is used and the target file
+ already exists, which is not the desired behavior.)
@@ -668,10 +668,10 @@ test ! -f /mnt/server/archivedir/00000001000000A900000065 && cp pg_wal/0
fills, nothing further can be archived until the tape is swapped.
You should ensure that any error condition or request to a human operator
is reported appropriately so that the situation can be
- resolved reasonably quickly. The pg_wal/> directory will
+ resolved reasonably quickly. The pg_wal/ directory will
continue to fill with WAL segment files until the situation is resolved.
- (If the file system containing pg_wal/> fills up,
- PostgreSQL> will do a PANIC shutdown. No committed
+ (If the file system containing pg_wal/ fills up,
+ PostgreSQL will do a PANIC shutdown. No committed
transactions will be lost, but the database will remain offline until
you free some space.)
@@ -682,7 +682,7 @@ test ! -f /mnt/server/archivedir/00000001000000A900000065 && cp pg_wal/0
operation continues even if the archiving process falls a little behind.
If archiving falls significantly behind, this will increase the amount of
data that would be lost in the event of a disaster. It will also mean that
- the pg_wal/> directory will contain large numbers of
+ the pg_wal/ directory will contain large numbers of
not-yet-archived segment files, which could eventually exceed available
disk space. You are advised to monitor the archiving process to ensure that
it is working as you intend.
@@ -692,20 +692,20 @@ test ! -f /mnt/server/archivedir/00000001000000A900000065 && cp pg_wal/0
In writing your archive command, you should assume that the file names to
be archived can be up to 64 characters long and can contain any
combination of ASCII letters, digits, and dots. It is not necessary to
- preserve the original relative path (%p>) but it is necessary to
- preserve the file name (%f>).
+ preserve the original relative path (%p) but it is necessary to
+ preserve the file name (%f).
Note that although WAL archiving will allow you to restore any
- modifications made to the data in your PostgreSQL> database,
+ modifications made to the data in your PostgreSQL database,
it will not restore changes made to configuration files (that is,
- postgresql.conf>, pg_hba.conf> and
- pg_ident.conf>), since those are edited manually rather
+ postgresql.conf, pg_hba.conf and
+ pg_ident.conf), since those are edited manually rather
than through SQL operations.
You might wish to keep the configuration files in a location that will
be backed up by your regular file system backup procedures. See
- for how to relocate the
+ for how to relocate the
configuration files.
@@ -715,36 +715,36 @@ test ! -f /mnt/server/archivedir/00000001000000A900000065 && cp pg_wal/0
where it does so), there could be a long delay between the completion
of a transaction and its safe recording in archive storage. To put
a limit on how old unarchived data can be, you can set
- to force the server to switch
+ to force the server to switch
to a new WAL segment file at least that often. Note that archived
files that are archived early due to a forced switch are still the same
length as completely full files. It is therefore unwise to set a very
- short archive_timeout> — it will bloat your archive
- storage. archive_timeout> settings of a minute or so are
+ short archive_timeout — it will bloat your archive
+ storage. archive_timeout settings of a minute or so are
usually reasonable.
Also, you can force a segment switch manually with
- pg_switch_wal> if you want to ensure that a
+ pg_switch_wal if you want to ensure that a
just-finished transaction is archived as soon as possible. Other utility
functions related to WAL management are listed in .
+ linkend="functions-admin-backup-table"/>.
- When wal_level> is minimal> some SQL commands
+ When wal_level is minimal some SQL commands
are optimized to avoid WAL logging, as described in . If archiving or streaming replication were
+ linkend="populate-pitr"/>. If archiving or streaming replication were
turned on during execution of one of these statements, WAL would not
contain enough information for archive recovery. (Crash recovery is
- unaffected.) For this reason, wal_level> can only be changed at
- server start. However, archive_command> can be changed with a
+ unaffected.) For this reason, wal_level can only be changed at
+ server start. However, archive_command can be changed with a
configuration file reload. If you wish to temporarily stop archiving,
- one way to do it is to set archive_command> to the empty
- string (''>).
- This will cause WAL files to accumulate in pg_wal/> until a
- working archive_command> is re-established.
+ one way to do it is to set archive_command to the empty
+ string ('').
+ This will cause WAL files to accumulate in pg_wal/ until a
+ working archive_command is re-established.
@@ -753,18 +753,18 @@ test ! -f /mnt/server/archivedir/00000001000000A900000065 && cp pg_wal/0
The easiest way to perform a base backup is to use the
- tool. It can create
+ tool. It can create
a base backup either as regular files or as a tar archive. If more
- flexibility than can provide is
+ flexibility than can provide is
required, you can also make a base backup using the low level API
- (see ).
+ (see ).
It is not necessary to be concerned about the amount of time it takes
to make a base backup. However, if you normally run the
- server with full_page_writes> disabled, you might notice a drop
- in performance while the backup runs since full_page_writes> is
+ server with full_page_writes disabled, you might notice a drop
+ in performance while the backup runs since full_page_writes is
effectively forced on during backup mode.
@@ -772,13 +772,13 @@ test ! -f /mnt/server/archivedir/00000001000000A900000065 && cp pg_wal/0
To make use of the backup, you will need to keep all the WAL
segment files generated during and after the file system backup.
To aid you in doing this, the base backup process
- creates a backup history file> that is immediately
+ creates a backup history file that is immediately
stored into the WAL archive area. This file is named after the first
WAL segment file that you need for the file system backup.
For example, if the starting WAL file is
- 0000000100001234000055CD> the backup history file will be
+ 0000000100001234000055CD the backup history file will be
named something like
- 0000000100001234000055CD.007C9330.backup>. (The second
+ 0000000100001234000055CD.007C9330.backup. (The second
part of the file name stands for an exact position within the WAL
file, and can ordinarily be ignored.) Once you have safely archived
the file system backup and the WAL segment files used during the
@@ -791,7 +791,7 @@ test ! -f /mnt/server/archivedir/00000001000000A900000065 && cp pg_wal/0
The backup history file is just a small text file. It contains the
- label string you gave to , as well as
+ label string you gave to , as well as
the starting and ending times and WAL segments of the backup.
If you used the label to identify the associated dump file,
then the archived history file is enough to tell you which dump file to
@@ -814,7 +814,7 @@ test ! -f /mnt/server/archivedir/00000001000000A900000065 && cp pg_wal/0
The procedure for making a base backup using the low level
APIs contains a few more steps than
- the method, but is relatively
+ the method, but is relatively
simple. It is very important that these steps are executed in
sequence, and that the success of a step is verified before
proceeding to the next step.
@@ -830,7 +830,7 @@ test ! -f /mnt/server/archivedir/00000001000000A900000065 && cp pg_wal/0
A non-exclusive low level backup is one that allows other
concurrent backups to be running (both those started using
the same backup API and those started using
- ).
+ ).
@@ -847,39 +847,39 @@ test ! -f /mnt/server/archivedir/00000001000000A900000065 && cp pg_wal/0
SELECT pg_start_backup('label', false, false);
- where label> is any string you want to use to uniquely
+ where label is any string you want to use to uniquely
identify this backup operation. The connection
- calling pg_start_backup> must be maintained until the end of
+ calling pg_start_backup must be maintained until the end of
the backup, or the backup will be automatically aborted.
- By default, pg_start_backup> can take a long time to finish.
+ By default, pg_start_backup can take a long time to finish.
This is because it performs a checkpoint, and the I/O
required for the checkpoint will be spread out over a significant
period of time, by default half your inter-checkpoint interval
(see the configuration parameter
- ). This is
+ ). This is
usually what you want, because it minimizes the impact on query
processing. If you want to start the backup as soon as
- possible, change the second parameter to true>, which will
+ possible, change the second parameter to true, which will
issue an immediate checkpoint using as much I/O as available.
- The third parameter being false> tells
- pg_start_backup> to initiate a non-exclusive base backup.
+ The third parameter being false tells
+ pg_start_backup to initiate a non-exclusive base backup.
Perform the backup, using any convenient file-system-backup tool
- such as tar> or cpio> (not
+ such as tar or cpio (not
pg_dump or
pg_dumpall). It is neither
necessary nor desirable to stop normal operation of the database
while you do this. See
- for things to
+ for things to
consider during this backup.
@@ -889,47 +889,54 @@ SELECT pg_start_backup('label', false, false);
SELECT * FROM pg_stop_backup(false, true);
- This terminates the backup mode and performs an automatic switch to
- the next WAL segment. The reason for the switch is to arrange for
+ This terminates backup mode. On a primary, it also performs an automatic
+ switch to the next WAL segment. On a standby, it is not possible to
+ automatically switch WAL segments, so you may wish to run
+ pg_switch_wal on the primary to perform a manual
+ switch. The reason for the switch is to arrange for
the last WAL segment file written during the backup interval to be
ready to archive.
- The pg_stop_backup> will return one row with three
+ The pg_stop_backup will return one row with three
values. The second of these fields should be written to a file named
- backup_label> in the root directory of the backup. The
+ backup_label in the root directory of the backup. The
third field should be written to a file named
- tablespace_map> unless the field is empty. These files are
+ tablespace_map unless the field is empty. These files are
vital to the backup working, and must be written without modification.
Once the WAL segment files active during the backup are archived, you are
- done. The file identified by pg_stop_backup>'s first return
+ done. The file identified by pg_stop_backup's first return
value is the last segment that is required to form a complete set of
- backup files. If archive_mode> is enabled,
- pg_stop_backup> does not return until the last segment has
+ backup files. On a primary, if archive_mode is enabled and the
+ wait_for_archive parameter is true,
+ pg_stop_backup does not return until the last segment has
been archived.
+ On a standby, archive_mode must be always in order
+ for pg_stop_backup to wait.
Archiving of these files happens automatically since you have
- already configured archive_command>. In most cases this
+ already configured archive_command. In most cases this
happens quickly, but you are advised to monitor your archive
system to ensure there are no delays.
If the archive process has fallen behind
because of failures of the archive command, it will keep retrying
until the archive succeeds and the backup is complete.
If you wish to place a time limit on the execution of
- pg_stop_backup>, set an appropriate
+ pg_stop_backup, set an appropriate
statement_timeout value, but make note that if
- pg_stop_backup> terminates because of this your backup
+ pg_stop_backup terminates because of this your backup
may not be valid.
If the backup process monitors and ensures that all WAL segment files
- required for the backup are successfully archived then the second
- parameter (which defaults to true) can be set to false to have
- pg_stop_backup> return as soon as the stop backup record is
- written to the WAL. By default, pg_stop_backup> will wait
+ required for the backup are successfully archived then the
+ wait_for_archive parameter (which defaults to true) can be set
+ to false to have
+ pg_stop_backup return as soon as the stop backup record is
+ written to the WAL. By default, pg_stop_backup will wait
until all WAL has been archived, which can take some time. This option
must be used with caution: if WAL archiving is not monitored correctly
then the backup might not include all of the WAL files and will
@@ -943,9 +950,9 @@ SELECT * FROM pg_stop_backup(false, true);
Making an exclusive low level backup
The process for an exclusive backup is mostly the same as for a
- non-exclusive one, but it differs in a few key steps. It does not allow
- more than one concurrent backup to run, and there can be some issues on
- the server if it crashes during the backup. Prior to PostgreSQL 9.6, this
+ non-exclusive one, but it differs in a few key steps. This type of backup
+ can only be taken on a primary and does not allow concurrent backups.
+ Prior to PostgreSQL 9.6, this
was the only low-level method available, but it is now recommended that
all users upgrade their scripts to use non-exclusive backups if possible.
@@ -964,25 +971,25 @@ SELECT * FROM pg_stop_backup(false, true);
SELECT pg_start_backup('label');
- where label> is any string you want to use to uniquely
+ where label is any string you want to use to uniquely
identify this backup operation.
- pg_start_backup> creates a backup label> file,
- called backup_label>, in the cluster directory with
+ pg_start_backup creates a backup label file,
+ called backup_label, in the cluster directory with
information about your backup, including the start time and label string.
- The function also creates a tablespace map> file,
- called tablespace_map>, in the cluster directory with
- information about tablespace symbolic links in pg_tblspc/> if
+ The function also creates a tablespace map file,
+ called tablespace_map, in the cluster directory with
+ information about tablespace symbolic links in pg_tblspc/ if
one or more such link is present. Both files are critical to the
integrity of the backup, should you need to restore from it.
- By default, pg_start_backup> can take a long time to finish.
+ By default, pg_start_backup can take a long time to finish.
This is because it performs a checkpoint, and the I/O
required for the checkpoint will be spread out over a significant
period of time, by default half your inter-checkpoint interval
(see the configuration parameter
- ). This is
+ ). This is
usually what you want, because it minimizes the impact on query
processing. If you want to start the backup as soon as
possible, use:
@@ -995,14 +1002,19 @@ SELECT pg_start_backup('label', true);
Perform the backup, using any convenient file-system-backup tool
- such as tar> or cpio> (not
+ such as tar or cpio (not
pg_dump or
pg_dumpall). It is neither
necessary nor desirable to stop normal operation of the database
while you do this. See
- for things to
+ for things to
consider during this backup.
+
+ Note that if the server crashes during the backup it may not be
+ possible to restart until the backup_label file has been
+ manually deleted from the PGDATA directory.
+
@@ -1012,36 +1024,31 @@ SELECT pg_start_backup('label', true);
SELECT pg_stop_backup();
- This function, when called on a primary, terminates the backup mode and
+ This function terminates backup mode and
performs an automatic switch to the next WAL segment. The reason for the
switch is to arrange for the last WAL segment written during the backup
- interval to be ready to archive. When called on a standby, this function
- only terminates backup mode. A subsequent WAL segment switch will be
- needed in order to ensure that all WAL files needed to restore the backup
- can be archived; if the primary does not have sufficient write activity
- to trigger one, pg_switch_wal should be executed on
- the primary.
+ interval to be ready to archive.
Once the WAL segment files active during the backup are archived, you are
- done. The file identified by pg_stop_backup>'s result is
+ done. The file identified by pg_stop_backup's result is
the last segment that is required to form a complete set of backup files.
- If archive_mode> is enabled,
- pg_stop_backup> does not return until the last segment has
+ If archive_mode is enabled,
+ pg_stop_backup does not return until the last segment has
been archived.
Archiving of these files happens automatically since you have
- already configured archive_command>. In most cases this
+ already configured archive_command. In most cases this
happens quickly, but you are advised to monitor your archive
system to ensure there are no delays.
If the archive process has fallen behind
because of failures of the archive command, it will keep retrying
until the archive succeeds and the backup is complete.
If you wish to place a time limit on the execution of
- pg_stop_backup>, set an appropriate
+ pg_stop_backup, set an appropriate
statement_timeout value, but make note that if
- pg_stop_backup> terminates because of this your backup
+ pg_stop_backup terminates because of this your backup
may not be valid.
@@ -1056,21 +1063,21 @@ SELECT pg_stop_backup();
When taking a base backup of an active database, this situation is normal
and not an error. However, you need to ensure that you can distinguish
complaints of this sort from real errors. For example, some versions
- of rsync> return a separate exit code for
- vanished source files>, and you can write a driver script to
+ of rsync return a separate exit code for
+ vanished source files, and you can write a driver script to
accept this exit code as a non-error case. Also, some versions of
- GNU tar> return an error code indistinguishable from
- a fatal error if a file was truncated while tar> was
- copying it. Fortunately, GNU tar> versions 1.16 and
+ GNU tar return an error code indistinguishable from
+ a fatal error if a file was truncated while tar was
+ copying it. Fortunately, GNU tar versions 1.16 and
later exit with 1 if a file was changed during the backup,
- and 2 for other errors. With GNU tar> version 1.23 and
+ and 2 for other errors. With GNU tar version 1.23 and
later, you can use the warning options --warning=no-file-changed
--warning=no-file-removed to hide the related warning messages.
Be certain that your backup includes all of the files under
- the database cluster directory (e.g., /usr/local/pgsql/data>).
+ the database cluster directory (e.g., /usr/local/pgsql/data).
If you are using tablespaces that do not reside underneath this directory,
be careful to include them as well (and be sure that your backup
archives symbolic links as links, otherwise the restore will corrupt
@@ -1079,21 +1086,21 @@ SELECT pg_stop_backup();
You should, however, omit from the backup the files within the
- cluster's pg_wal/> subdirectory. This
+ cluster's pg_wal/ subdirectory. This
slight adjustment is worthwhile because it reduces the risk
of mistakes when restoring. This is easy to arrange if
- pg_wal/> is a symbolic link pointing to someplace outside
+ pg_wal/ is a symbolic link pointing to someplace outside
the cluster directory, which is a common setup anyway for performance
- reasons. You might also want to exclude postmaster.pid>
- and postmaster.opts>, which record information
- about the running postmaster>, not about the
- postmaster> which will eventually use this backup.
- (These files can confuse pg_ctl>.)
+ reasons. You might also want to exclude postmaster.pid
+ and postmaster.opts, which record information
+ about the running postmaster, not about the
+ postmaster which will eventually use this backup.
+ (These files can confuse pg_ctl.)
It is often a good idea to also omit from the backup the files
- within the cluster's pg_replslot/> directory, so that
+ within the cluster's pg_replslot/ directory, so that
replication slots that exist on the master do not become part of the
backup. Otherwise, the subsequent use of the backup to create a standby
may result in indefinite retention of WAL files on the standby, and
@@ -1107,12 +1114,12 @@ SELECT pg_stop_backup();
- The contents of the directories pg_dynshmem/>,
- pg_notify/>, pg_serial/>,
- pg_snapshots/>, pg_stat_tmp/>,
- and pg_subtrans/> (but not the directories themselves) can be
+ The contents of the directories pg_dynshmem/,
+ pg_notify/, pg_serial/,
+ pg_snapshots/, pg_stat_tmp/,
+ and pg_subtrans/ (but not the directories themselves) can be
omitted from the backup as they will be initialized on postmaster startup.
- If is set and is under the data
+ If is set and is under the data
directory then the contents of that directory can also be omitted.
@@ -1122,15 +1129,21 @@ SELECT pg_stop_backup();
the directories will be recreated as needed.
+
+ pg_internal.init files can be omitted from the
+ backup whenever a file of that name is found. These files contain
+ relation cache data that is always rebuilt when recovering.
+
+
The backup label
- file includes the label string you gave to pg_start_backup>,
- as well as the time at which pg_start_backup> was run, and
+ file includes the label string you gave to pg_start_backup,
+ as well as the time at which pg_start_backup was run, and
the name of the starting WAL file. In case of confusion it is therefore
possible to look inside a backup file and determine exactly which
backup session the dump file came from. The tablespace map file includes
the symbolic link names as they exist in the directory
- pg_tblspc/> and the full path of each symbolic link.
+ pg_tblspc/ and the full path of each symbolic link.
These files are not merely for your information; their presence and
contents are critical to the proper operation of the system's recovery
process.
@@ -1139,7 +1152,7 @@ SELECT pg_stop_backup();
It is also possible to make a backup while the server is
stopped. In this case, you obviously cannot use
- pg_start_backup> or pg_stop_backup>, and
+ pg_start_backup or pg_stop_backup, and
you will therefore be left to your own devices to keep track of which
backup is which and how far back the associated WAL files go.
It is generally better to follow the continuous archiving procedure above.
@@ -1166,7 +1179,7 @@ SELECT pg_stop_backup();
location in case you need them later. Note that this precaution will
require that you have enough free space on your system to hold two
copies of your existing database. If you do not have enough space,
- you should at least save the contents of the cluster's pg_wal>
+ you should at least save the contents of the cluster's pg_wal
subdirectory, as it might contain logs which
were not archived before the system went down.
@@ -1181,17 +1194,17 @@ SELECT pg_stop_backup();
Restore the database files from your file system backup. Be sure that they
are restored with the right ownership (the database system user, not
- root>!) and with the right permissions. If you are using
+ root!) and with the right permissions. If you are using
tablespaces,
- you should verify that the symbolic links in pg_tblspc/>
+ you should verify that the symbolic links in pg_tblspc/
were correctly restored.
- Remove any files present in pg_wal/>; these came from the
+ Remove any files present in pg_wal/; these came from the
file system backup and are therefore probably obsolete rather than current.
- If you didn't archive pg_wal/> at all, then recreate
+ If you didn't archive pg_wal/ at all, then recreate
it with proper permissions,
being careful to ensure that you re-establish it as a symbolic link
if you had it set up that way before.
@@ -1200,16 +1213,16 @@ SELECT pg_stop_backup();
If you have unarchived WAL segment files that you saved in step 2,
- copy them into pg_wal/>. (It is best to copy them,
+ copy them into pg_wal/. (It is best to copy them,
not move them, so you still have the unmodified files if a
problem occurs and you have to start over.)
- Create a recovery command file recovery.conf> in the cluster
- data directory (see ). You might
- also want to temporarily modify pg_hba.conf> to prevent
+ Create a recovery command file recovery.conf in the cluster
+ data directory (see ). You might
+ also want to temporarily modify pg_hba.conf to prevent
ordinary users from connecting until you are sure the recovery was successful.
@@ -1220,7 +1233,7 @@ SELECT pg_stop_backup();
recovery be terminated because of an external error, the server can
simply be restarted and it will continue recovery. Upon completion
of the recovery process, the server will rename
- recovery.conf> to recovery.done> (to prevent
+ recovery.conf to recovery.done (to prevent
accidentally re-entering recovery mode later) and then
commence normal database operations.
@@ -1229,7 +1242,7 @@ SELECT pg_stop_backup();
Inspect the contents of the database to ensure you have recovered to
the desired state. If not, return to step 1. If all is well,
- allow your users to connect by restoring pg_hba.conf> to normal.
+ allow your users to connect by restoring pg_hba.conf to normal.
@@ -1238,32 +1251,32 @@ SELECT pg_stop_backup();
The key part of all this is to set up a recovery configuration file that
describes how you want to recover and how far the recovery should
- run. You can use recovery.conf.sample> (normally
- located in the installation's share/> directory) as a
+ run. You can use recovery.conf.sample (normally
+ located in the installation's share/ directory) as a
prototype. The one thing that you absolutely must specify in
- recovery.conf> is the restore_command>,
- which tells PostgreSQL> how to retrieve archived
- WAL file segments. Like the archive_command>, this is
- a shell command string. It can contain %f>, which is
- replaced by the name of the desired log file, and %p>,
+ recovery.conf is the restore_command,
+ which tells PostgreSQL how to retrieve archived
+ WAL file segments. Like the archive_command, this is
+ a shell command string. It can contain %f, which is
+ replaced by the name of the desired log file, and %p,
which is replaced by the path name to copy the log file to.
(The path name is relative to the current working directory,
i.e., the cluster's data directory.)
- Write %%> if you need to embed an actual %>
+ Write %% if you need to embed an actual %
character in the command. The simplest useful command is
something like:
restore_command = 'cp /mnt/server/archivedir/%f %p'
which will copy previously archived WAL segments from the directory
- /mnt/server/archivedir>. Of course, you can use something
+ /mnt/server/archivedir. Of course, you can use something
much more complicated, perhaps even a shell script that requests the
operator to mount an appropriate tape.
It is important that the command return nonzero exit status on failure.
- The command will> be called requesting files that are not
+ The command will be called requesting files that are not
present in the archive; it must return nonzero when so asked. This is not
an error condition. An exception is that if the command was terminated by
a signal (other than SIGTERM, which is used as
@@ -1275,36 +1288,36 @@ restore_command = 'cp /mnt/server/archivedir/%f %p'
Not all of the requested files will be WAL segment
files; you should also expect requests for files with a suffix of
- .backup> or .history>. Also be aware that
- the base name of the %p> path will be different from
- %f>; do not expect them to be interchangeable.
+ .backup or .history. Also be aware that
+ the base name of the %p path will be different from
+ %f; do not expect them to be interchangeable.
WAL segments that cannot be found in the archive will be sought in
- pg_wal/>; this allows use of recent un-archived segments.
+ pg_wal/; this allows use of recent un-archived segments.
However, segments that are available from the archive will be used in
- preference to files in pg_wal/>.
+ preference to files in pg_wal/.
Normally, recovery will proceed through all available WAL segments,
thereby restoring the database to the current point in time (or as
close as possible given the available WAL segments). Therefore, a normal
- recovery will end with a file not found> message, the exact text
+ recovery will end with a file not found message, the exact text
of the error message depending upon your choice of
- restore_command>. You may also see an error message
+ restore_command. You may also see an error message
at the start of recovery for a file named something like
- 00000001.history>. This is also normal and does not
+ 00000001.history. This is also normal and does not
indicate a problem in simple recovery situations; see
- for discussion.
+ for discussion.
If you want to recover to some previous point in time (say, right before
the junior DBA dropped your main transaction table), just specify the
- required stopping point in recovery.conf>. You can specify
- the stop point, known as the recovery target>, either by
+ required stopping point in recovery.conf. You can specify
+ the stop point, known as the recovery target, either by
date/time, named restore point or by completion of a specific transaction
ID. As of this writing only the date/time and named restore point options
are very usable, since there are no tools to help you identify with any
@@ -1314,7 +1327,7 @@ restore_command = 'cp /mnt/server/archivedir/%f %p'
The stop point must be after the ending time of the base backup, i.e.,
- the end time of pg_stop_backup>. You cannot use a base backup
+ the end time of pg_stop_backup. You cannot use a base backup
to recover to a time when that backup was in progress. (To
recover to such a time, you must go back to your previous base backup
and roll forward from there.)
@@ -1325,14 +1338,14 @@ restore_command = 'cp /mnt/server/archivedir/%f %p'
If recovery finds corrupted WAL data, recovery will
halt at that point and the server will not start. In such a case the
recovery process could be re-run from the beginning, specifying a
- recovery target> before the point of corruption so that recovery
+ recovery target before the point of corruption so that recovery
can complete normally.
If recovery fails for an external reason, such as a system crash or
if the WAL archive has become inaccessible, then the recovery can simply
be restarted and it will restart almost from where it failed.
Recovery restart works much like checkpointing in normal operation:
the server periodically forces all its state to disk, and then updates
- the pg_control> file to indicate that the already-processed
+ the pg_control file to indicate that the already-processed
WAL data need not be scanned again.
@@ -1352,7 +1365,7 @@ restore_command = 'cp /mnt/server/archivedir/%f %p'
suppose you dropped a critical table at 5:15PM on Tuesday evening, but
didn't realize your mistake until Wednesday noon.
Unfazed, you get out your backup, restore to the point-in-time 5:14PM
- Tuesday evening, and are up and running. In this> history of
+ Tuesday evening, and are up and running. In this history of
the database universe, you never dropped the table. But suppose
you later realize this wasn't such a great idea, and would like
to return to sometime Wednesday morning in the original history.
@@ -1365,8 +1378,8 @@ restore_command = 'cp /mnt/server/archivedir/%f %p'
- To deal with this problem, PostgreSQL> has a notion
- of timelines>. Whenever an archive recovery completes,
+ To deal with this problem, PostgreSQL has a notion
+ of timelines. Whenever an archive recovery completes,
a new timeline is created to identify the series of WAL records
generated after that recovery. The timeline
ID number is part of WAL segment file names so a new timeline does
@@ -1377,13 +1390,13 @@ restore_command = 'cp /mnt/server/archivedir/%f %p'
and so have to do several point-in-time recoveries by trial and error
until you find the best place to branch off from the old history. Without
timelines this process would soon generate an unmanageable mess. With
- timelines, you can recover to any> prior state, including
+ timelines, you can recover to any prior state, including
states in timeline branches that you abandoned earlier.
- Every time a new timeline is created, PostgreSQL> creates
- a timeline history> file that shows which timeline it branched
+ Every time a new timeline is created, PostgreSQL creates
+ a timeline history file that shows which timeline it branched
off from and when. These history files are necessary to allow the system
to pick the right WAL segment files when recovering from an archive that
contains multiple timelines. Therefore, they are archived into the WAL
@@ -1401,7 +1414,7 @@ restore_command = 'cp /mnt/server/archivedir/%f %p'
that was current when the base backup was taken. If you wish to recover
into some child timeline (that is, you want to return to some state that
was itself generated after a recovery attempt), you need to specify the
- target timeline ID in recovery.conf>. You cannot recover into
+ target timeline ID in recovery.conf. You cannot recover into
timelines that branched off earlier than the base backup.
@@ -1417,18 +1430,18 @@ restore_command = 'cp /mnt/server/archivedir/%f %p'
Standalone Hot Backups
- It is possible to use PostgreSQL>'s backup facilities to
+ It is possible to use PostgreSQL's backup facilities to
produce standalone hot backups. These are backups that cannot be used
for point-in-time recovery, yet are typically much faster to backup and
- restore than pg_dump> dumps. (They are also much larger
- than pg_dump> dumps, so in some cases the speed advantage
+ restore than pg_dump dumps. (They are also much larger
+ than pg_dump dumps, so in some cases the speed advantage
might be negated.)
As with base backups, the easiest way to produce a standalone
- hot backup is to use the
- tool. If you include the -X> parameter when calling
+ hot backup is to use the
+ tool. If you include the -X parameter when calling
it, all the write-ahead log required to use the backup will be
included in the backup automatically, and no special action is
required to restore the backup.
@@ -1438,16 +1451,16 @@ restore_command = 'cp /mnt/server/archivedir/%f %p'
If more flexibility in copying the backup files is needed, a lower
level process can be used for standalone hot backups as well.
To prepare for low level standalone hot backups, make sure
- wal_level> is set to
- replica> or higher, archive_mode> to
- on>, and set up an archive_command> that performs
- archiving only when a switch file> exists. For example:
+ wal_level is set to
+ replica or higher, archive_mode to
+ on, and set up an archive_command that performs
+ archiving only when a switch file exists. For example:
archive_command = 'test ! -f /var/lib/pgsql/backup_in_progress || (test ! -f /var/lib/pgsql/archive/%f && cp %p /var/lib/pgsql/archive/%f)'
This command will perform archiving when
- /var/lib/pgsql/backup_in_progress> exists, and otherwise
- silently return zero exit status (allowing PostgreSQL>
+ /var/lib/pgsql/backup_in_progress exists, and otherwise
+ silently return zero exit status (allowing PostgreSQL
to recycle the unwanted WAL file).
@@ -1462,11 +1475,11 @@ psql -c "select pg_stop_backup();"
rm /var/lib/pgsql/backup_in_progress
tar -rf /var/lib/pgsql/backup.tar /var/lib/pgsql/archive/
- The switch file /var/lib/pgsql/backup_in_progress> is
+ The switch file /var/lib/pgsql/backup_in_progress is
created first, enabling archiving of completed WAL files to occur.
After the backup the switch file is removed. Archived WAL files are
then added to the backup so that both base backup and all required
- WAL files are part of the same tar> file.
+ WAL files are part of the same tar file.
Please remember to add error handling to your backup scripts.
@@ -1481,7 +1494,7 @@ tar -rf /var/lib/pgsql/backup.tar /var/lib/pgsql/archive/
archive_command = 'gzip < %p > /var/lib/pgsql/archive/%f'
- You will then need to use gunzip> during recovery:
+ You will then need to use gunzip during recovery:
restore_command = 'gunzip < /mnt/server/archivedir/%f > %p'
@@ -1494,7 +1507,7 @@ restore_command = 'gunzip < /mnt/server/archivedir/%f > %p'
Many people choose to use scripts to define their
archive_command, so that their
- postgresql.conf> entry looks very simple:
+ postgresql.conf entry looks very simple:
archive_command = 'local_backup_script.sh "%p" "%f"'
@@ -1502,7 +1515,7 @@ archive_command = 'local_backup_script.sh "%p" "%f"'
more than a single command in the archiving process.
This allows all complexity to be managed within the script, which
can be written in a popular scripting language such as
- bash> or perl>.
+ bash or perl.
@@ -1535,8 +1548,8 @@ archive_command = 'local_backup_script.sh "%p" "%f"'
When using an archive_command script, it's desirable
- to enable .
- Any messages written to stderr> from the script will then
+ to enable .
+ Any messages written to stderr from the script will then
appear in the database server log, allowing complex configurations to
be diagnosed easily if they fail.
@@ -1554,9 +1567,9 @@ archive_command = 'local_backup_script.sh "%p" "%f"'
- If a
+ If a
command is executed while a base backup is being taken, and then
- the template database that the CREATE DATABASE> copied
+ the template database that the CREATE DATABASE copied
is modified while the base backup is still in progress, it is
possible that recovery will cause those modifications to be
propagated into the created database as well. This is of course
@@ -1567,7 +1580,7 @@ archive_command = 'local_backup_script.sh "%p" "%f"'
-
+
commands are WAL-logged with the literal absolute path, and will
therefore be replayed as tablespace creations with the same
absolute path. This might be undesirable if the log is being
@@ -1590,12 +1603,12 @@ archive_command = 'local_backup_script.sh "%p" "%f"'
your system hardware and software, the risk of partial writes might
be small enough to ignore, in which case you can significantly
reduce the total volume of archived logs by turning off page
- snapshots using the
- parameter. (Read the notes and warnings in
+ snapshots using the
+ parameter. (Read the notes and warnings in
before you do so.) Turning off page snapshots does not prevent
use of the logs for PITR operations. An area for future
development is to compress archived WAL data by removing
- unnecessary page copies even when full_page_writes> is
+ unnecessary page copies even when full_page_writes is
on. In the meantime, administrators might wish to reduce the number
of page snapshots included in WAL by increasing the checkpoint
interval parameters as much as feasible.
diff --git a/doc/src/sgml/bgworker.sgml b/doc/src/sgml/bgworker.sgml
index b422323081..e490bb8750 100644
--- a/doc/src/sgml/bgworker.sgml
+++ b/doc/src/sgml/bgworker.sgml
@@ -11,17 +11,17 @@
PostgreSQL can be extended to run user-supplied code in separate processes.
Such processes are started, stopped and monitored by postgres,
which permits them to have a lifetime closely linked to the server's status.
- These processes have the option to attach to PostgreSQL>'s
+ These processes have the option to attach to PostgreSQL's
shared memory area and to connect to databases internally; they can also run
multiple transactions serially, just like a regular client-connected server
- process. Also, by linking to libpq> they can connect to the
+ process. Also, by linking to libpq they can connect to the
server and behave like a regular client application.
There are considerable robustness and security risks in using background
- worker processes because, being written in the C> language,
+ worker processes because, being written in the C language,
they have unrestricted access to data. Administrators wishing to enable
modules that include background worker process should exercise extreme
caution. Only carefully audited modules should be permitted to run
@@ -31,17 +31,17 @@
Background workers can be initialized at the time that
- PostgreSQL> is started by including the module name in
- shared_preload_libraries>. A module wishing to run a background
+ PostgreSQL is started by including the module name in
+ shared_preload_libraries. A module wishing to run a background
worker can register it by calling
RegisterBackgroundWorker(BackgroundWorker *worker)
- from its _PG_init()>. Background workers can also be started
+ from its _PG_init(). Background workers can also be started
after the system is up and running by calling the function
RegisterDynamicBackgroundWorker(BackgroundWorker
*worker, BackgroundWorkerHandle **handle). Unlike
- RegisterBackgroundWorker>, which can only be called from within
+ RegisterBackgroundWorker, which can only be called from within
the postmaster, RegisterDynamicBackgroundWorker must be
- called from a regular backend.
+ called from a regular backend, possibly another background worker.
@@ -51,6 +51,7 @@ typedef void (*bgworker_main_type)(Datum main_arg);
typedef struct BackgroundWorker
{
char bgw_name[BGW_MAXLEN];
+ char bgw_type[BGW_MAXLEN];
int bgw_flags;
BgWorkerStartTime bgw_start_time;
int bgw_restart_time; /* in seconds, or BGW_NEVER_RESTART */
@@ -64,12 +65,18 @@ typedef struct BackgroundWorker
- bgw_name> is a string to be used in log messages, process
- listings and similar contexts.
+ bgw_name and bgw_type are
+ strings to be used in log messages, process listings and similar contexts.
+ bgw_type should be the same for all background
+ workers of the same type, so that it is possible to group such workers in a
+ process listing, for example. bgw_name on the
+ other hand can contain additional information about the specific process.
+ (Typically, the string for bgw_name will contain
+ the type somehow, but that is not strictly required.)
- bgw_flags> is a bitwise-or'd bit mask indicating the
+ bgw_flags is a bitwise-or'd bit mask indicating the
capabilities that the module wants. Possible values are:
@@ -107,14 +114,14 @@ typedef struct BackgroundWorker
bgw_start_time is the server state during which
- postgres> should start the process; it can be one of
- BgWorkerStart_PostmasterStart> (start as soon as
- postgres> itself has finished its own initialization; processes
+ postgres should start the process; it can be one of
+ BgWorkerStart_PostmasterStart (start as soon as
+ postgres itself has finished its own initialization; processes
requesting this are not eligible for database connections),
- BgWorkerStart_ConsistentState> (start as soon as a consistent state
+ BgWorkerStart_ConsistentState (start as soon as a consistent state
has been reached in a hot standby, allowing processes to connect to
databases and run read-only queries), and
- BgWorkerStart_RecoveryFinished> (start as soon as the system has
+ BgWorkerStart_RecoveryFinished (start as soon as the system has
entered normal read-write state). Note the last two values are equivalent
in a server that's not a hot standby. Note that this setting only indicates
when the processes are to be started; they do not stop when a different state
@@ -145,9 +152,9 @@ typedef struct BackgroundWorker
- bgw_main_arg is the Datum> argument
+ bgw_main_arg is the Datum argument
to the background worker main function. This main function should take a
- single argument of type Datum> and return void>.
+ single argument of type Datum and return void.
bgw_main_arg will be passed as the argument.
In addition, the global variable MyBgworkerEntry
points to a copy of the BackgroundWorker structure
@@ -158,39 +165,39 @@ typedef struct BackgroundWorker
On Windows (and anywhere else where EXEC_BACKEND is
defined) or in dynamic background workers it is not safe to pass a
- Datum> by reference, only by value. If an argument is required, it
+ Datum by reference, only by value. If an argument is required, it
is safest to pass an int32 or other small value and use that as an index
- into an array allocated in shared memory. If a value like a cstring>
+ into an array allocated in shared memory. If a value like a cstring
or text is passed then the pointer won't be valid from the
new background worker process.
bgw_extra can contain extra data to be passed
- to the background worker. Unlike bgw_main_arg>, this data
+ to the background worker. Unlike bgw_main_arg, this data
is not passed as an argument to the worker's main function, but it can be
accessed via MyBgworkerEntry, as discussed above.
bgw_notify_pid is the PID of a PostgreSQL
- backend process to which the postmaster should send SIGUSR1>
+ backend process to which the postmaster should send SIGUSR1
when the process is started or exits. It should be 0 for workers registered
at postmaster startup time, or when the backend registering the worker does
not wish to wait for the worker to start up. Otherwise, it should be
- initialized to MyProcPid>.
+ initialized to MyProcPid.
Once running, the process can connect to a database by calling
BackgroundWorkerInitializeConnection(char *dbname, char *username) or
BackgroundWorkerInitializeConnectionByOid(Oid dboid, Oid useroid).
This allows the process to run transactions and queries using the
- SPI interface. If dbname> is NULL or
- dboid> is InvalidOid>, the session is not connected
+ SPI interface. If dbname is NULL or
+ dboid is InvalidOid, the session is not connected
to any particular database, but shared catalogs can be accessed.
- If username> is NULL or useroid> is
- InvalidOid>, the process will run as the superuser created
- during initdb>.
+ If username is NULL or useroid is
+ InvalidOid, the process will run as the superuser created
+ during initdb.
A background worker can only call one of these two functions, and only
once. It is not possible to switch databases.
@@ -200,24 +207,24 @@ typedef struct BackgroundWorker
background worker's main function, and must be unblocked by it; this is to
allow the process to customize its signal handlers, if necessary.
Signals can be unblocked in the new process by calling
- BackgroundWorkerUnblockSignals> and blocked by calling
- BackgroundWorkerBlockSignals>.
+ BackgroundWorkerUnblockSignals and blocked by calling
+ BackgroundWorkerBlockSignals.
If bgw_restart_time for a background worker is
- configured as BGW_NEVER_RESTART>, or if it exits with an exit
- code of 0 or is terminated by TerminateBackgroundWorker>,
+ configured as BGW_NEVER_RESTART, or if it exits with an exit
+ code of 0 or is terminated by TerminateBackgroundWorker,
it will be automatically unregistered by the postmaster on exit.
Otherwise, it will be restarted after the time period configured via
- bgw_restart_time>, or immediately if the postmaster
+ bgw_restart_time, or immediately if the postmaster
reinitializes the cluster due to a backend failure. Backends which need
to suspend execution only temporarily should use an interruptible sleep
rather than exiting; this can be achieved by calling
WaitLatch(). Make sure the
- WL_POSTMASTER_DEATH> flag is set when calling that function, and
+ WL_POSTMASTER_DEATH flag is set when calling that function, and
verify the return code for a prompt exit in the emergency case that
- postgres> itself has terminated.
+ postgres itself has terminated.
@@ -231,29 +238,29 @@ typedef struct BackgroundWorker
opaque handle that can subsequently be passed to
GetBackgroundWorkerPid(BackgroundWorkerHandle *, pid_t *) or
TerminateBackgroundWorker(BackgroundWorkerHandle *).
- GetBackgroundWorkerPid> can be used to poll the status of the
- worker: a return value of BGWH_NOT_YET_STARTED> indicates that
+ GetBackgroundWorkerPid can be used to poll the status of the
+ worker: a return value of BGWH_NOT_YET_STARTED indicates that
the worker has not yet been started by the postmaster;
BGWH_STOPPED indicates that it has been started but is
no longer running; and BGWH_STARTED indicates that it is
currently running. In this last case, the PID will also be returned via the
second argument.
- TerminateBackgroundWorker> causes the postmaster to send
- SIGTERM> to the worker if it is running, and to unregister it
+ TerminateBackgroundWorker causes the postmaster to send
+ SIGTERM to the worker if it is running, and to unregister it
as soon as it is not.
In some cases, a process which registers a background worker may wish to
wait for the worker to start up. This can be accomplished by initializing
- bgw_notify_pid to MyProcPid> and
+ bgw_notify_pid to MyProcPid and
then passing the BackgroundWorkerHandle * obtained at
registration time to
WaitForBackgroundWorkerStartup(BackgroundWorkerHandle
*handle, pid_t *) function.
This function will block until the postmaster has attempted to start the
background worker, or until the postmaster dies. If the background runner
- is running, the return value will BGWH_STARTED>, and
+ is running, the return value will BGWH_STARTED, and
the PID will be written to the provided address. Otherwise, the return
value will be BGWH_STOPPED or
BGWH_POSTMASTER_DIED.
@@ -272,13 +279,13 @@ typedef struct BackgroundWorker
- The src/test/modules/worker_spi> module
+ The src/test/modules/worker_spi module
contains a working example,
which demonstrates some useful techniques.
The maximum number of registered background workers is limited by
- .
+ .
diff --git a/doc/src/sgml/biblio.sgml b/doc/src/sgml/biblio.sgml
index 5462bc38e4..4953024162 100644
--- a/doc/src/sgml/biblio.sgml
+++ b/doc/src/sgml/biblio.sgml
@@ -18,7 +18,7 @@
SQL Reference Books
-
+ The Practical SQL HandbookUsing SQL VariantsFourth Edition
@@ -43,7 +43,7 @@
2001
-
+ A Guide to the SQL StandardA user's guide to the standard database language SQLFourth Edition
@@ -64,7 +64,7 @@
1997
-
+ An Introduction to Database SystemsEighth Edition
@@ -80,7 +80,7 @@
2003
-
+ Fundamentals of Database SystemsFourth Edition
@@ -100,7 +100,7 @@
2003
-
+ Understanding the New SQLA complete guide
@@ -120,7 +120,7 @@
1993
-
+ Principles of Database and KnowledgeBase Systems
@@ -141,7 +141,7 @@
PostgreSQL-specific Documentation
-
+ Enhancement of the ANSI SQL Implementation of PostgreSQL
@@ -171,7 +171,7 @@ ssimkovi@ag.or.at
Discusses SQL history and syntax, and describes the addition of
- INTERSECT> and EXCEPT> constructs into
+ INTERSECT and EXCEPT constructs into
PostgreSQL. Prepared as a Master's
Thesis with the support of O. Univ. Prof. Dr. Georg Gottlob and
Univ. Ass. Mag. Katrin Seyr at Vienna University of Technology.
@@ -185,7 +185,7 @@ ssimkovi@ag.or.at
November 29, 1998
-
+ The Postgres95 User Manual
@@ -204,7 +204,7 @@ ssimkovi@ag.or.at
Sept. 5, 1995
-
+ The
design and implementation of the POSTGRES query
optimizer
@@ -222,7 +222,7 @@ ssimkovi@ag.or.at
Proceedings and Articles
-
+ Partial indexing in POSTGRES: research project
@@ -238,7 +238,7 @@ ssimkovi@ag.or.at
1993
-
+ A Unified Framework for Version Modeling Using Production Rules in a Database System
@@ -262,7 +262,7 @@ ssimkovi@ag.or.at
-
+ The POSTGRES
data model
@@ -284,7 +284,7 @@ ssimkovi@ag.or.at
-
+ Generalized
Partial Indexes
@@ -313,7 +313,7 @@ ssimkovi@ag.or.at
420-7
-
+ The
design of POSTGRES
@@ -335,7 +335,7 @@ ssimkovi@ag.or.at
-
+ The design of the POSTGRES rules system
@@ -360,7 +360,7 @@ ssimkovi@ag.or.at
-
+ The
design of the POSTGRES storage
@@ -379,7 +379,7 @@ ssimkovi@ag.or.at
-
+ A
commentary on the POSTGRES rules
@@ -405,7 +405,7 @@ ssimkovi@ag.or.at
-
+ The
case for partial indexes
@@ -423,7 +423,7 @@ ssimkovi@ag.or.at
-
+ The
implementation of POSTGRES
@@ -451,7 +451,7 @@ ssimkovi@ag.or.at
-
+ On
Rules, Procedures, Caching and Views in Database Systems
diff --git a/doc/src/sgml/bki.sgml b/doc/src/sgml/bki.sgml
index af6d8d1d2a..33378b46ea 100644
--- a/doc/src/sgml/bki.sgml
+++ b/doc/src/sgml/bki.sgml
@@ -21,7 +21,7 @@
input file used by initdb is created as
part of building and installing PostgreSQL
by a program named genbki.pl, which reads some
- specially formatted C header files in the src/include/catalog/>
+ specially formatted C header files in the src/include/catalog/
directory of the source tree. The created BKI file
is called postgres.bki and is
normally installed in the
@@ -67,13 +67,13 @@
- create>
+ createtablenametableoid
- bootstrap>
- shared_relation>
- without_oids>
- rowtype_oid> oid>
+ bootstrap
+ shared_relation
+ without_oids
+ rowtype_oidoid
(name1 =
type1FORCE NOT NULL | FORCE NULL ,
@@ -93,7 +93,7 @@
The following column types are supported directly by
- bootstrap.c>: bool,
+ bootstrap.c: bool,
bytea, char (1 byte),
name, int2,
int4, regproc, regclass,
@@ -104,31 +104,31 @@
_oid (array), _char (array),
_aclitem (array). Although it is possible to create
tables containing columns of other types, this cannot be done until
- after pg_type> has been created and filled with
+ after pg_type has been created and filled with
appropriate entries. (That effectively means that only these
column types can be used in bootstrapped tables, but non-bootstrap
catalogs can contain any built-in type.)
- When bootstrap> is specified,
+ When bootstrap is specified,
the table will only be created on disk; nothing is entered into
pg_class,
pg_attribute, etc, for it. Thus the
table will not be accessible by ordinary SQL operations until
- such entries are made the hard way (with insert>
+ such entries are made the hard way (with insert
commands). This option is used for creating
pg_class etc themselves.
- The table is created as shared if shared_relation> is
+ The table is created as shared if shared_relation is
specified.
- It will have OIDs unless without_oids> is specified.
- The table's row type OID (pg_type> OID) can optionally
- be specified via the rowtype_oid> clause; if not specified,
- an OID is automatically generated for it. (The rowtype_oid>
- clause is useless if bootstrap> is specified, but it can be
+ It will have OIDs unless without_oids is specified.
+ The table's row type OID (pg_type OID) can optionally
+ be specified via the rowtype_oid clause; if not specified,
+ an OID is automatically generated for it. (The rowtype_oid
+ clause is useless if bootstrap is specified, but it can be
provided anyway for documentation.)
@@ -136,7 +136,7 @@
- open> tablename
+ opentablename
@@ -150,7 +150,7 @@
- close> tablename
+ closetablename
@@ -163,7 +163,7 @@
- insert> OID => oid_value(> value1value2 ... )>
+ insertOID =oid_value(value1value2 ... )
@@ -188,14 +188,14 @@
- declare> unique>
- index> indexname
+ declareunique
+ indexindexnameindexoid
- on> tablename
- using> amname
- (> opclass1
+ ontablename
+ usingamname
+ (opclass1name1
- , ...)>
+ , ...)
@@ -220,10 +220,10 @@
- declare toast>
+ declare toasttoasttableoidtoastindexoid
- on> tablename
+ ontablename
@@ -234,14 +234,14 @@
toasttableoid
and its index is assigned OID
toastindexoid.
- As with declare index>, filling of the index
+ As with declare index, filling of the index
is postponed.
- build indices>
+ build indices
@@ -257,17 +257,17 @@
Structure of the Bootstrap BKI File
- The open> command cannot be used until the tables it uses
+ The open command cannot be used until the tables it uses
exist and have entries for the table that is to be opened.
- (These minimum tables are pg_class>,
- pg_attribute>, pg_proc>, and
- pg_type>.) To allow those tables themselves to be filled,
- create> with the bootstrap> option implicitly opens
+ (These minimum tables are pg_class,
+ pg_attribute, pg_proc, and
+ pg_type.) To allow those tables themselves to be filled,
+ create with the bootstrap option implicitly opens
the created table for data insertion.
- Also, the declare index> and declare toast>
+ Also, the declare index and declare toast
commands cannot be used until the system catalogs they need have been
created and filled in.
@@ -278,17 +278,17 @@
- create bootstrap> one of the critical tables
+ create bootstrap one of the critical tables
- insert> data describing at least the critical tables
+ insert data describing at least the critical tables
- close>
+ close
@@ -298,22 +298,22 @@
- create> (without bootstrap>) a noncritical table
+ create (without bootstrap) a noncritical table
- open>
+ open
- insert> desired data
+ insert desired data
- close>
+ close
@@ -328,7 +328,7 @@
- build indices>
+ build indices
diff --git a/doc/src/sgml/bloom.sgml b/doc/src/sgml/bloom.sgml
index 396348c523..e13ebf80fd 100644
--- a/doc/src/sgml/bloom.sgml
+++ b/doc/src/sgml/bloom.sgml
@@ -8,7 +8,7 @@
- bloom> provides an index access method based on
+ bloom provides an index access method based on
Bloom filters.
@@ -42,29 +42,29 @@
Parameters
- A bloom> index accepts the following parameters in its
- WITH> clause:
+ A bloom index accepts the following parameters in its
+ WITH clause:
- length>
+ length
Length of each signature (index entry) in bits. The default
- is 80> bits and maximum is 4096>.
+ is 80 bits and maximum is 4096.
- col1 — col32>
+ col1 — col32
Number of bits generated for each index column. Each parameter's name
refers to the number of the index column that it controls. The default
- is 2> bits and maximum is 4095>. Parameters for
+ is 2 bits and maximum is 4095. Parameters for
index columns not actually used are ignored.
@@ -87,8 +87,8 @@ CREATE INDEX bloomidx ON tbloom USING bloom (i1,i2,i3)
The index is created with a signature length of 80 bits, with attributes
i1 and i2 mapped to 2 bits, and attribute i3 mapped to 4 bits. We could
- have omitted the length>, col1>,
- and col2> specifications since those have the default values.
+ have omitted the length, col1,
+ and col2 specifications since those have the default values.
@@ -175,7 +175,7 @@ CREATE INDEX
Note the relatively large number of false positives: 2439 rows were
selected to be visited in the heap, but none actually matched the
query. We could reduce that by specifying a larger signature length.
- In this example, creating the index with length=200>
+ In this example, creating the index with length=200
reduced the number of false positives to 55; but it doubled the index size
(to 306 MB) and ended up being slower for this query (125 ms overall).
@@ -213,7 +213,7 @@ CREATE INDEX
An operator class for bloom indexes requires only a hash function for the
indexed data type and an equality operator for searching. This example
- shows the operator class definition for the text> data type:
+ shows the operator class definition for the text data type:
@@ -230,7 +230,7 @@ DEFAULT FOR TYPE text USING bloom AS
- Only operator classes for int4> and text> are
+ Only operator classes for int4 and text are
included with the module.
diff --git a/doc/src/sgml/brin.sgml b/doc/src/sgml/brin.sgml
index 8dcc29925b..23c0e05ed6 100644
--- a/doc/src/sgml/brin.sgml
+++ b/doc/src/sgml/brin.sgml
@@ -1,6 +1,6 @@
-
+BRIN Indexes
@@ -16,7 +16,7 @@
BRIN is designed for handling very large tables
in which certain columns have some natural correlation with their
physical location within the table.
- A block range> is a group of pages that are physically
+ A block range is a group of pages that are physically
adjacent in the table; for each block range, some summary info is stored
by the index.
For example, a table storing a store's sale orders might have
@@ -29,7 +29,7 @@
BRIN indexes can satisfy queries via regular bitmap
index scans, and will return all tuples in all pages within each range if
- the summary info stored by the index is consistent> with the
+ the summary info stored by the index is consistent with the
query conditions.
The query executor is in charge of rechecking these tuples and discarding
those that do not match the query conditions — in other words, these
@@ -51,9 +51,9 @@
The size of the block range is determined at index creation time by
- the pages_per_range> storage parameter. The number of index
+ the pages_per_range storage parameter. The number of index
entries will be equal to the size of the relation in pages divided by
- the selected value for pages_per_range>. Therefore, the smaller
+ the selected value for pages_per_range. Therefore, the smaller
the number, the larger the index becomes (because of the need to
store more index entries), but at the same time the summary data stored can
be more precise and more data blocks can be skipped during an index scan.
@@ -95,13 +95,13 @@
The core PostgreSQL distribution
includes the BRIN operator classes shown in
- .
+ .
- The minmax>
+ The minmax
operator classes store the minimum and the maximum values appearing
- in the indexed column within the range. The inclusion>
+ in the indexed column within the range. The inclusion
operator classes store a value which includes the values in the indexed
column within the range.
@@ -162,21 +162,21 @@
- box_inclusion_ops>
+ box_inclusion_opsbox
- <<>
- &<>
- &&>
- &>>
- >>>
- ~=>
- @>>
- <@>
- &<|>
- <<|>
+ <<
+ &<
+ &&
+ &>
+ >>
+ ~=
+ @>
+ <@
+ &<|
+ <<||>>
- |&>>
+ |&>
@@ -249,11 +249,11 @@
network_inclusion_opsinet
- &&>
- >>=>
+ &&
+ >>=<<==
- >>>
+ >><<
@@ -346,18 +346,18 @@
- range_inclusion_ops>
+ range_inclusion_opsany range type
- <<>
- &<>
- &&>
- &>>
- >>>
- @>>
- <@>
- -|->
- =>
+ <<
+ &<
+ &&
+ &>
+ >>
+ @>
+ <@
+ -|-
+ =<<==
@@ -505,11 +505,11 @@
- BrinOpcInfo *opcInfo(Oid type_oid)>
+ BrinOpcInfo *opcInfo(Oid type_oid)
Returns internal information about the indexed columns' summary data.
- The return value must point to a palloc'd BrinOpcInfo>,
+ The return value must point to a palloc'd BrinOpcInfo,
which has this definition:
typedef struct BrinOpcInfo
@@ -524,7 +524,7 @@ typedef struct BrinOpcInfo
TypeCacheEntry *oi_typcache[FLEXIBLE_ARRAY_MEMBER];
} BrinOpcInfo;
- BrinOpcInfo>.oi_opaque> can be used by the
+ BrinOpcInfo.oi_opaque can be used by the
operator class routines to pass information between support procedures
during an index scan.
@@ -590,7 +590,7 @@ typedef struct BrinOpcInfo
To write an operator class for a data type that implements a totally
ordered set, it is possible to use the minmax support procedures
alongside the corresponding operators, as shown in
- .
+ .
All operator class members (procedures and operators) are mandatory.
@@ -648,7 +648,7 @@ typedef struct BrinOpcInfo
To write an operator class for a complex data type which has values
included within another type, it's possible to use the inclusion support
procedures alongside the corresponding operators, as shown
- in . It requires
+ in . It requires
only a single additional function, which can be written in any language.
More functions can be defined for additional functionality. All operators
are optional. Some operators require other operators, as shown as
@@ -797,8 +797,8 @@ typedef struct BrinOpcInfo
It should accept two arguments with the same data type as the operator class,
and return the union of them. The inclusion operator class can store union
values with different data types if it is defined with the
- STORAGE> parameter. The return value of the union
- function should match the STORAGE> data type.
+ STORAGE parameter. The return value of the union
+ function should match the STORAGE data type.
@@ -821,13 +821,13 @@ typedef struct BrinOpcInfo
additional data types to be supported by defining extra sets
of operators. Inclusion operator class operator strategies are dependent
on another operator strategy as shown in
- , or the same
+ , or the same
operator strategy as themselves. They require the dependency
- operator to be defined with the STORAGE> data type as the
+ operator to be defined with the STORAGE data type as the
left-hand-side argument and the other supported data type to be the
right-hand-side argument of the supported operator. See
- float4_minmax_ops> as an example of minmax, and
- box_inclusion_ops> as an example of inclusion.
+ float4_minmax_ops as an example of minmax, and
+ box_inclusion_ops as an example of inclusion.
diff --git a/doc/src/sgml/btree-gin.sgml b/doc/src/sgml/btree-gin.sgml
index 375e7ec4be..e491fa76e7 100644
--- a/doc/src/sgml/btree-gin.sgml
+++ b/doc/src/sgml/btree-gin.sgml
@@ -8,16 +8,16 @@
- btree_gin> provides sample GIN operator classes that
+ btree_gin provides sample GIN operator classes that
implement B-tree equivalent behavior for the data types
- int2>, int4>, int8>, float4>,
- float8>, timestamp with time zone>,
- timestamp without time zone>, time with time zone>,
- time without time zone>, date>, interval>,
- oid>, money>, "char">,
- varchar>, text>, bytea>, bit>,
- varbit>, macaddr>, macaddr8>, inet>,
- cidr>, and all enum> types.
+ int2, int4, int8, float4,
+ float8, timestamp with time zone,
+ timestamp without time zone, time with time zone,
+ time without time zone, date, interval,
+ oid, money, "char",
+ varchar, text, bytea, bit,
+ varbit, macaddr, macaddr8, inet,
+ cidr, and all enum types.
diff --git a/doc/src/sgml/btree-gist.sgml b/doc/src/sgml/btree-gist.sgml
index f3c639c2f3..774442feee 100644
--- a/doc/src/sgml/btree-gist.sgml
+++ b/doc/src/sgml/btree-gist.sgml
@@ -8,16 +8,16 @@
- btree_gist> provides GiST index operator classes that
+ btree_gist provides GiST index operator classes that
implement B-tree equivalent behavior for the data types
- int2>, int4>, int8>, float4>,
- float8>, numeric>, timestamp with time zone>,
- timestamp without time zone>, time with time zone>,
- time without time zone>, date>, interval>,
- oid>, money>, char>,
- varchar>, text>, bytea>, bit>,
- varbit>, macaddr>, macaddr8>, inet>,
- cidr>, uuid>, and all enum> types.
+ int2, int4, int8, float4,
+ float8, numeric, timestamp with time zone,
+ timestamp without time zone, time with time zone,
+ time without time zone, date, interval,
+ oid, money, char,
+ varchar, text, bytea, bit,
+ varbit, macaddr, macaddr8, inet,
+ cidr, uuid, and all enum types.
@@ -33,23 +33,23 @@
- In addition to the typical B-tree search operators, btree_gist>
+ In addition to the typical B-tree search operators, btree_gist
also provides index support for <> (not
equals). This may be useful in combination with an
- exclusion constraint,
+ exclusion constraint,
as described below.
Also, for data types for which there is a natural distance metric,
- btree_gist> defines a distance operator <->>,
+ btree_gist defines a distance operator <->,
and provides GiST index support for nearest-neighbor searches using
this operator. Distance operators are provided for
- int2>, int4>, int8>, float4>,
- float8>, timestamp with time zone>,
- timestamp without time zone>,
- time without time zone>, date>, interval>,
- oid>, and money>.
+ int2, int4, int8, float4,
+ float8, timestamp with time zone,
+ timestamp without time zone,
+ time without time zone, date, interval,
+ oid, and money.
@@ -70,7 +70,7 @@ SELECT *, a <-> 42 AS dist FROM test ORDER BY a <-> 42 LIMIT 10;
- Use an exclusion
+ Use an exclusion
constraint to enforce the rule that a cage at a zoo
can contain only one kind of animal:
diff --git a/doc/src/sgml/btree.sgml b/doc/src/sgml/btree.sgml
new file mode 100644
index 0000000000..10abf90189
--- /dev/null
+++ b/doc/src/sgml/btree.sgml
@@ -0,0 +1,446 @@
+
+
+
+B-Tree Indexes
+
+
+ index
+ B-Tree
+
+
+
+ Introduction
+
+
+ PostgreSQL includes an implementation of the
+ standard btree (multi-way binary tree) index data
+ structure. Any data type that can be sorted into a well-defined linear
+ order can be indexed by a btree index. The only limitation is that an
+ index entry cannot exceed approximately one-third of a page (after TOAST
+ compression, if applicable).
+
+
+
+ Because each btree operator class imposes a sort order on its data type,
+ btree operator classes (or, really, operator families) have come to be
+ used as PostgreSQL's general representation
+ and understanding of sorting semantics. Therefore, they've acquired
+ some features that go beyond what would be needed just to support btree
+ indexes, and parts of the system that are quite distant from the
+ btree AM make use of them.
+
+
+
+
+
+ Behavior of B-Tree Operator Classes
+
+
+ As shown in , a btree operator
+ class must provide five comparison operators,
+ <,
+ <=,
+ =,
+ >= and
+ >.
+ One might expect that <> should also be part of
+ the operator class, but it is not, because it would almost never be
+ useful to use a <> WHERE clause in an index
+ search. (For some purposes, the planner treats <>
+ as associated with a btree operator class; but it finds that operator via
+ the = operator's negator link, rather than
+ from pg_amop.)
+
+
+
+ When several data types share near-identical sorting semantics, their
+ operator classes can be grouped into an operator family. Doing so is
+ advantageous because it allows the planner to make deductions about
+ cross-type comparisons. Each operator class within the family should
+ contain the single-type operators (and associated support functions)
+ for its input data type, while cross-type comparison operators and
+ support functions are loose in the family. It is
+ recommendable that a complete set of cross-type operators be included
+ in the family, thus ensuring that the planner can represent any
+ comparison conditions that it deduces from transitivity.
+
+
+
+ There are some basic assumptions that a btree operator family must
+ satisfy:
+
+
+
+
+
+ An = operator must be an equivalence relation; that
+ is, for all non-null values A,
+ B, C of the
+ data type:
+
+
+
+
+ A=
+ A is true
+ (reflexive law)
+
+
+
+
+ if A=
+ B,
+ then B=
+ A
+ (symmetric law)
+
+
+
+
+ if A=
+ B and B
+ =C,
+ then A=
+ C
+ (transitive law)
+
+
+
+
+
+
+
+
+ A < operator must be a strong ordering relation;
+ that is, for all non-null values A,
+ B, C:
+
+
+
+
+ A<
+ A is false
+ (irreflexive law)
+
+
+
+
+ if A<
+ B
+ and B<
+ C,
+ then A<
+ C
+ (transitive law)
+
+
+
+
+
+
+
+
+ Furthermore, the ordering is total; that is, for all non-null
+ values A, B:
+
+
+
+
+ exactly one of A<
+ B, A
+ =B, and
+ B<
+ A is true
+ (trichotomy law)
+
+
+
+
+ (The trichotomy law justifies the definition of the comparison support
+ function, of course.)
+
+
+
+
+
+ The other three operators are defined in terms of =
+ and < in the obvious way, and must act consistently
+ with them.
+
+
+
+ For an operator family supporting multiple data types, the above laws must
+ hold when A, B,
+ C are taken from any data types in the family.
+ The transitive laws are the trickiest to ensure, as in cross-type
+ situations they represent statements that the behaviors of two or three
+ different operators are consistent.
+ As an example, it would not work to put float8
+ and numeric into the same operator family, at least not with
+ the current semantics that numeric values are converted
+ to float8 for comparison to a float8. Because
+ of the limited accuracy of float8, this means there are
+ distinct numeric values that will compare equal to the
+ same float8 value, and thus the transitive law would fail.
+
+
+
+ Another requirement for a multiple-data-type family is that any implicit
+ or binary-coercion casts that are defined between data types included in
+ the operator family must not change the associated sort ordering.
+
+
+
+ It should be fairly clear why a btree index requires these laws to hold
+ within a single data type: without them there is no ordering to arrange
+ the keys with. Also, index searches using a comparison key of a
+ different data type require comparisons to behave sanely across two
+ data types. The extensions to three or more data types within a family
+ are not strictly required by the btree index mechanism itself, but the
+ planner relies on them for optimization purposes.
+
+
+
+
+
+ B-Tree Support Functions
+
+
+ As shown in , btree defines
+ one required and two optional support functions.
+
+
+
+ For each combination of data types that a btree operator family provides
+ comparison operators for, it must provide a comparison support function,
+ registered in pg_amproc with support function
+ number 1 and
+ amproclefttype/amprocrighttype
+ equal to the left and right data types for the comparison (i.e., the
+ same data types that the matching operators are registered with
+ in pg_amop).
+ The comparison function must take two non-null values
+ A and B and
+ return an int32 value that
+ is <0, 0,
+ or >0
+ when A<
+ B, A
+ =B,
+ or A>
+ B, respectively. The function must not
+ return INT_MIN for the A
+ <B case,
+ since the value may be negated before being tested for sign. A null
+ result is disallowed, too.
+ See src/backend/access/nbtree/nbtcompare.c for
+ examples.
+
+
+
+ If the compared values are of a collatable data type, the appropriate
+ collation OID will be passed to the comparison support function, using
+ the standard PG_GET_COLLATION() mechanism.
+
+
+
+ Optionally, a btree operator family may provide sort
+ support function(s), registered under support function number
+ 2. These functions allow implementing comparisons for sorting purposes
+ in a more efficient way than naively calling the comparison support
+ function. The APIs involved in this are defined in
+ src/include/utils/sortsupport.h.
+
+
+
+ in_range support functions
+
+
+
+ support functions
+ in_range
+
+
+
+ Optionally, a btree operator family may
+ provide in_range support function(s), registered
+ under support function number 3. These are not used during btree index
+ operations; rather, they extend the semantics of the operator family so
+ that it can support window clauses containing
+ the RANGEoffset
+ PRECEDING
+ and RANGEoffset
+ FOLLOWING frame bound types (see
+ ). Fundamentally, the extra
+ information provided is how to add or subtract
+ an offset value in a way that is compatible
+ with the family's data ordering.
+
+
+
+ An in_range function must have the signature
+
+in_range(val type1, base type1, offset type2, sub bool, less bool)
+returns bool
+
+ val and base must be
+ of the same type, which is one of the types supported by the operator
+ family (i.e., a type for which it provides an ordering).
+ However, offset could be of a different type,
+ which might be one otherwise unsupported by the family. An example is
+ that the built-in time_ops family provides
+ an in_range function that
+ has offset of type interval.
+ A family can provide in_range functions for any of
+ its supported types and one or more offset
+ types. Each in_range function should be entered
+ in pg_amproc
+ with amproclefttype equal to type1
+ and amprocrighttype equal to type2.
+
+
+
+ The essential semantics of an in_range function
+ depend on the two boolean flag parameters. It should add or
+ subtract base
+ and offset, then
+ compare val to the result, as follows:
+
+
+
+ if !sub and
+ !less,
+ return val>=
+ (base+
+ offset)
+
+
+
+
+ if !sub
+ and less,
+ return val<=
+ (base+
+ offset)
+
+
+
+
+ if sub
+ and !less,
+ return val>=
+ (base-
+ offset)
+
+
+
+
+ if sub and less,
+ return val<=
+ (base-
+ offset)
+
+
+
+ Before doing so, the function should check the sign
+ of offset: if it is less than zero, raise
+ error ERRCODE_INVALID_PRECEDING_FOLLOWING_SIZE (22013)
+ with error text like invalid preceding or following size in window
+ function. (This is required by the SQL standard, although
+ nonstandard operator families might perhaps choose to ignore this
+ restriction, since there seems to be little semantic necessity for it.)
+ This requirement is delegated to the in_range
+ function so that the core code needn't understand what less than
+ zero means for a particular data type.
+
+
+
+ An additional expectation is that in_range functions
+ should, if practical, avoid throwing an error
+ if base+
+ offset
+ or base-
+ offset would overflow.
+ The correct comparison result can be determined even if that value would
+ be out of the data type's range. Note that if the data type includes
+ concepts such as infinity or NaN, extra care
+ may be needed to ensure that in_range's results agree
+ with the normal sort order of the operator family.
+
+
+
+ The results of the in_range function must be
+ consistent with the sort ordering imposed by the operator family.
+ To be precise, given any fixed values of offset
+ and sub, then:
+
+
+
+ If in_range with less =
+ true is true for some val1
+ and base, it must be true for
+ every val2<=
+ val1 with the
+ same base.
+
+
+
+
+ If in_range with less =
+ true is false for some val1
+ and base, it must be false for
+ every val2>=
+ val1 with the
+ same base.
+
+
+
+
+ If in_range with less =
+ true is true for some val
+ and base1, it must be true for
+ every base2>=
+ base1 with the
+ same val.
+
+
+
+
+ If in_range with less =
+ true is false for some val
+ and base1, it must be false for
+ every base2<=
+ base1 with the
+ same val.
+
+
+
+ Analogous statements with inverted conditions hold
+ when less = false.
+
+
+
+ If the type being ordered (type1) is collatable,
+ the appropriate collation OID will be passed to
+ the in_range function, using the standard
+ PG_GET_COLLATION() mechanism.
+
+
+
+ in_range functions need not handle NULL inputs, and
+ typically will be marked strict.
+
+
+
+
+
+ Implementation
+
+
+ An introduction to the btree index implementation can be found in
+ src/backend/access/nbtree/README.
+
+
+
+
+
diff --git a/doc/src/sgml/catalogs.sgml b/doc/src/sgml/catalogs.sgml
index ef7054cf26..71e20f2740 100644
--- a/doc/src/sgml/catalogs.sgml
+++ b/doc/src/sgml/catalogs.sgml
@@ -27,7 +27,7 @@
Overview
- lists the system catalogs.
+ lists the system catalogs.
More detailed documentation of each catalog follows below.
@@ -387,7 +387,7 @@
- pg_aggregate> Columns
+ pg_aggregate Columns
@@ -410,9 +410,9 @@
charAggregate kind:
- n for normal> aggregates,
- o for ordered-set> aggregates, or
- h for hypothetical-set> aggregates
+ n for normal aggregates,
+ o for ordered-set aggregates, or
+ h for hypothetical-set aggregates
@@ -421,7 +421,7 @@
Number of direct (non-aggregated) arguments of an ordered-set or
hypothetical-set aggregate, counting a variadic array as one argument.
- If equal to pronargs>, the aggregate must be variadic
+ If equal to pronargs, the aggregate must be variadic
and the variadic array describes the aggregated arguments as well as
the final direct arguments.
Always zero for normal aggregates.
@@ -486,6 +486,26 @@
True to pass extra dummy arguments to aggmfinalfn
+
+ aggfinalmodify
+ char
+
+ Whether aggfinalfn modifies the
+ transition state value:
+ r if it is read-only,
+ s if the aggtransfn
+ cannot be applied after the aggfinalfn, or
+ w if it writes on the value
+
+
+
+ aggmfinalmodify
+ char
+
+ Like aggfinalmodify, but for
+ the aggmfinalfn
+
+ aggsortopoid
@@ -547,8 +567,8 @@
New aggregate functions are registered with the
- command. See for more information about
+ linkend="sql-createaggregate"/>
+ command. See for more information about
writing aggregate functions and the meaning of the transition
functions, etc.
@@ -568,11 +588,11 @@
relation access methods. There is one row for each access method supported
by the system.
Currently, only indexes have access methods. The requirements for index
- access methods are discussed in detail in .
+ access methods are discussed in detail in .
- pg_am> Columns
+ pg_am Columns
@@ -624,12 +644,12 @@
- Before PostgreSQL> 9.6, pg_am
+ Before PostgreSQL 9.6, pg_am
contained many additional columns representing properties of index access
methods. That data is now only directly visible at the C code level.
However, pg_index_column_has_property() and related
functions have been added to allow SQL queries to inspect index access
- method properties; see .
+ method properties; see .
@@ -647,8 +667,8 @@
The catalog pg_amop stores information about
operators associated with access method operator families. There is one
row for each operator that is a member of an operator family. A family
- member can be either a search> operator or an
- ordering> operator. An operator
+ member can be either a search operator or an
+ ordering operator. An operator
can appear in more than one family, but cannot appear in more than one
search position nor more than one ordering position within a family.
(It is allowed, though unlikely, for an operator to be used for both
@@ -656,7 +676,7 @@
- pg_amop> Columns
+ pg_amop Columns
@@ -708,8 +728,8 @@
amoppurposechar
- Operator purpose, either s> for search or
- o> for ordering
+ Operator purpose, either s for search or
+ o for ordering
@@ -739,26 +759,26 @@
- A search> operator entry indicates that an index of this operator
+ A search operator entry indicates that an index of this operator
family can be searched to find all rows satisfying
- WHERE>
- indexed_column>
- operator>
- constant>.
+ WHERE
+ indexed_column
+ operator
+ constant.
Obviously, such an operator must return boolean, and its left-hand input
type must match the index's column data type.
- An ordering> operator entry indicates that an index of this
+ An ordering operator entry indicates that an index of this
operator family can be scanned to return rows in the order represented by
- ORDER BY>
- indexed_column>
- operator>
- constant>.
+ ORDER BY
+ indexed_column
+ operator
+ constant.
Such an operator could return any sortable data type, though again
its left-hand input type must match the index's column data type.
- The exact semantics of the ORDER BY> are specified by the
+ The exact semantics of the ORDER BY are specified by the
amopsortfamily column, which must reference
a B-tree operator family for the operator's result type.
@@ -767,19 +787,19 @@
At present, it's assumed that the sort order for an ordering operator
is the default for the referenced operator family, i.e., ASC NULLS
- LAST>. This might someday be relaxed by adding additional columns
+ LAST. This might someday be relaxed by adding additional columns
to specify sort options explicitly.
- An entry's amopmethod> must match the
- opfmethod> of its containing operator family (including
- amopmethod> here is an intentional denormalization of the
+ An entry's amopmethod must match the
+ opfmethod of its containing operator family (including
+ amopmethod here is an intentional denormalization of the
catalog structure for performance reasons). Also,
- amoplefttype> and amoprighttype> must match
- the oprleft> and oprright> fields of the
- referenced pg_operator> entry.
+ amoplefttype and amoprighttype must match
+ the oprleft and oprright fields of the
+ referenced pg_operator entry.
@@ -860,14 +880,14 @@
The usual interpretation of the
- amproclefttype> and amprocrighttype> fields
+ amproclefttype and amprocrighttype fields
is that they identify the left and right input types of the operator(s)
that a particular support procedure supports. For some access methods
these match the input data type(s) of the support procedure itself, for
- others not. There is a notion of default> support procedures for
- an index, which are those with amproclefttype> and
- amprocrighttype> both equal to the index operator class's
- opcintype>.
+ others not. There is a notion of default support procedures for
+ an index, which are those with amproclefttype and
+ amprocrighttype both equal to the index operator class's
+ opcintype.
@@ -889,7 +909,7 @@
- pg_attrdef> Columns
+ pg_attrdef Columns
@@ -944,7 +964,7 @@
The adsrc field is historical, and is best
not used, because it does not track outside changes that might affect
the representation of the default value. Reverse-compiling the
- adbin field (with pg_get_expr> for
+ adbin field (with pg_get_expr for
example) is a better way to display the default value.
@@ -973,7 +993,7 @@
- pg_attribute> Columns
+ pg_attribute Columns
@@ -1014,7 +1034,7 @@
attstattarget controls the level of detail
of statistics accumulated for this column by
- .
+ .
A zero value indicates that no statistics should be collected.
A negative value says to use the system default statistics target.
The exact meaning of positive values is data type-dependent.
@@ -1052,7 +1072,7 @@
Number of dimensions, if the column is an array type; otherwise 0.
(Presently, the number of dimensions of an array is not enforced,
- so any nonzero value effectively means it's an array>.)
+ so any nonzero value effectively means it's an array.)
@@ -1076,7 +1096,7 @@
supplied at table creation time (for example, the maximum
length of a varchar column). It is passed to
type-specific input functions and length coercion functions.
- The value will generally be -1 for types that do not need atttypmod>.
+ The value will generally be -1 for types that do not need atttypmod.
@@ -1085,7 +1105,7 @@
bool
- A copy of pg_type.typbyval> of this column's type
+ A copy of pg_type.typbyval of this column's type
@@ -1094,7 +1114,7 @@
char
- Normally a copy of pg_type.typstorage> of this
+ Normally a copy of pg_type.typstorage of this
column's type. For TOAST-able data types, this can be altered
after column creation to control storage policy.
@@ -1105,7 +1125,7 @@
char
- A copy of pg_type.typalign> of this column's type
+ A copy of pg_type.typalign of this column's type
@@ -1196,7 +1216,7 @@
text[]
- Attribute-level options, as keyword=value> strings
+ Attribute-level options, as keyword=value strings
@@ -1205,7 +1225,7 @@
text[]
- Attribute-level foreign data wrapper options, as keyword=value> strings
+ Attribute-level foreign data wrapper options, as keyword=value strings
@@ -1217,9 +1237,9 @@
In a dropped column's pg_attribute entry,
atttypid is reset to zero, but
attlen and the other fields copied from
- pg_type> are still valid. This arrangement is needed
+ pg_type are still valid. This arrangement is needed
to cope with the situation where the dropped column's data type was
- later dropped, and so there is no pg_type> row anymore.
+ later dropped, and so there is no pg_type row anymore.
attlen and the other fields can be used
to interpret the contents of a row of the table.
@@ -1236,9 +1256,9 @@
The catalog pg_authid contains information about
database authorization identifiers (roles). A role subsumes the concepts
- of users> and groups>. A user is essentially just a
- role with the rolcanlogin> flag set. Any role (with or
- without rolcanlogin>) can have other roles as members; see
+ of users and groups. A user is essentially just a
+ role with the rolcanlogin flag set. Any role (with or
+ without rolcanlogin) can have other roles as members; see
pg_auth_members.
@@ -1250,7 +1270,7 @@
- contains detailed information about user and
+ contains detailed information about user and
privilege management.
@@ -1263,7 +1283,7 @@
- pg_authid> Columns
+ pg_authid Columns
@@ -1336,7 +1356,7 @@
bool
Role bypasses every row level security policy, see
- for more information.
+ for more information.
@@ -1370,20 +1390,20 @@
For an MD5 encrypted password, rolpassword
- column will begin with the string md5> followed by a
+ column will begin with the string md5 followed by a
32-character hexadecimal MD5 hash. The MD5 hash will be of the user's
password concatenated to their user name. For example, if user
- joe> has password xyzzy>, PostgreSQL>
- will store the md5 hash of xyzzyjoe>.
+ joe has password xyzzy, PostgreSQL
+ will store the md5 hash of xyzzyjoe.
If the password is encrypted with SCRAM-SHA-256, it has the format:
-SCRAM-SHA-256$<iteration count>>:<salt>>$<StoredKey>>:<ServerKey>>
+SCRAM-SHA-256$<iteration count>:<salt>$<StoredKey>:<ServerKey>
- where salt>, StoredKey> and
- ServerKey> are in Base64 encoded format. This format is
+ where salt, StoredKey and
+ ServerKey are in Base64 encoded format. This format is
the same as that specified by RFC 5803.
@@ -1415,7 +1435,7 @@ SCRAM-SHA-256$<iteration count>>:<salt><
- pg_auth_members> Columns
+ pg_auth_members Columns
@@ -1439,7 +1459,7 @@ SCRAM-SHA-256$<iteration count>>:<salt><
memberoidpg_authid.oid
- ID of a role that is a member of roleid>
+ ID of a role that is a member of roleid
@@ -1453,8 +1473,8 @@ SCRAM-SHA-256$<iteration count>>:<salt><
admin_optionbool
- True if member> can grant membership in
- roleid> to others
+ True if member can grant membership in
+ roleid to others
@@ -1481,14 +1501,14 @@ SCRAM-SHA-256$<iteration count>>:<salt><
cannot be deduced from some generic rule. For example, casting between a
domain and its base type is not explicitly represented in
pg_cast. Another important exception is that
- automatic I/O conversion casts>, those performed using a data
- type's own I/O functions to convert to or from text> or other
+ automatic I/O conversion casts, those performed using a data
+ type's own I/O functions to convert to or from text or other
string types, are not explicitly represented in
pg_cast.
- pg_cast> Columns
+ pg_cast Columns
@@ -1538,11 +1558,11 @@ SCRAM-SHA-256$<iteration count>>:<salt><
Indicates what contexts the cast can be invoked in.
- e> means only as an explicit cast (using
- CAST> or ::> syntax).
- a> means implicitly in assignment
+ e means only as an explicit cast (using
+ CAST or :: syntax).
+ a means implicitly in assignment
to a target column, as well as explicitly.
- i> means implicitly in expressions, as well as the
+ i means implicitly in expressions, as well as the
other cases.
@@ -1552,9 +1572,9 @@ SCRAM-SHA-256$<iteration count>>:<salt><
Indicates how the cast is performed.
- f> means that the function specified in the castfunc> field is used.
- i> means that the input/output functions are used.
- b> means that the types are binary-coercible, thus no conversion is required.
+ f means that the function specified in the castfunc field is used.
+ i means that the input/output functions are used.
+ b means that the types are binary-coercible, thus no conversion is required.
@@ -1566,18 +1586,18 @@ SCRAM-SHA-256$<iteration count>>:<salt><
always take the cast source type as their first argument type, and
return the cast destination type as their result type. A cast
function can have up to three arguments. The second argument,
- if present, must be type integer>; it receives the type
+ if present, must be type integer; it receives the type
modifier associated with the destination type, or -1
if there is none. The third argument,
- if present, must be type boolean>; it receives true>
- if the cast is an explicit cast, false> otherwise.
+ if present, must be type boolean; it receives true
+ if the cast is an explicit cast, false otherwise.
It is legitimate to create a pg_cast entry
in which the source and target types are the same, if the associated
function takes more than one argument. Such entries represent
- length coercion functions> that coerce values of the type
+ length coercion functions that coerce values of the type
to be legal for a particular type modifier value.
@@ -1604,14 +1624,14 @@ SCRAM-SHA-256$<iteration count>>:<salt><
table. This includes indexes (but see also
pg_index), sequences (but see also
pg_sequence), views, materialized
- views, composite types, and TOAST tables; see relkind>.
+ views, composite types, and TOAST tables; see relkind.
Below, when we mean all of these
kinds of objects we speak of relations. Not all
columns are meaningful for all relation types.
- pg_class> Columns
+ pg_class Columns
@@ -1653,7 +1673,7 @@ SCRAM-SHA-256$<iteration count>>:<salt><
pg_type.oid
The OID of the data type that corresponds to this table's row type,
- if any (zero for indexes, which have no pg_type> entry)
+ if any (zero for indexes, which have no pg_type entry)
@@ -1686,7 +1706,7 @@ SCRAM-SHA-256$<iteration count>>:<salt><
oidName of the on-disk file of this relation; zero means this
- is a mapped> relation whose disk file name is determined
+ is a mapped relation whose disk file name is determined
by low-level state
@@ -1775,8 +1795,8 @@ SCRAM-SHA-256$<iteration count>>:<salt><
char
- p> = permanent table, u> = unlogged table,
- t> = temporary table
+ p = permanent table, u = unlogged table,
+ t = temporary table
@@ -1785,15 +1805,15 @@ SCRAM-SHA-256$<iteration count>>:<salt><
char
- r> = ordinary table,
- i> = index,
- S> = sequence,
- t> = TOAST table,
- v> = view,
- m> = materialized view,
- c> = composite type,
- f> = foreign table,
- p> = partitioned table
+ r = ordinary table,
+ i = index,
+ S = sequence,
+ t = TOAST table,
+ v = view,
+ m = materialized view,
+ c = composite type,
+ f = foreign table,
+ p = partitioned table
@@ -1814,7 +1834,7 @@ SCRAM-SHA-256$<iteration count>>:<salt><
int2
- Number of CHECK> constraints on the table; see
+ Number of CHECK constraints on the table; see
pg_constraint catalog
@@ -1897,11 +1917,11 @@ SCRAM-SHA-256$<iteration count>>:<salt><
char
- Columns used to form replica identity> for rows:
- d> = default (primary key, if any),
- n> = nothing,
- f> = all columns
- i> = index with indisreplident set, or default
+ Columns used to form replica identity for rows:
+ d = default (primary key, if any),
+ n = nothing,
+ f = all columns
+ i = index with indisreplident set, or default
@@ -1918,9 +1938,9 @@ SCRAM-SHA-256$<iteration count>>:<salt><
All transaction IDs before this one have been replaced with a permanent
- (frozen>) transaction ID in this table. This is used to track
+ (frozen) transaction ID in this table. This is used to track
whether the table needs to be vacuumed in order to prevent transaction
- ID wraparound or to allow pg_xact> to be shrunk. Zero
+ ID wraparound or to allow pg_xact to be shrunk. Zero
(InvalidTransactionId) if the relation is not a table.
@@ -1933,7 +1953,7 @@ SCRAM-SHA-256$<iteration count>>:<salt><
All multixact IDs before this one have been replaced by a
transaction ID in this table. This is used to track
whether the table needs to be vacuumed in order to prevent multixact ID
- wraparound or to allow pg_multixact> to be shrunk. Zero
+ wraparound or to allow pg_multixact to be shrunk. Zero
(InvalidMultiXactId) if the relation is not a table.
@@ -1944,8 +1964,8 @@ SCRAM-SHA-256$<iteration count>>:<salt><
Access privileges; see
- and
-
+ and
+
for details
@@ -1955,7 +1975,7 @@ SCRAM-SHA-256$<iteration count>>:<salt><
text[]
- Access-method-specific options, as keyword=value> strings
+ Access-method-specific options, as keyword=value strings
@@ -1973,13 +1993,13 @@ SCRAM-SHA-256$<iteration count>>:<salt><
- Several of the Boolean flags in pg_class> are maintained
+ Several of the Boolean flags in pg_class are maintained
lazily: they are guaranteed to be true if that's the correct state, but
may not be reset to false immediately when the condition is no longer
- true. For example, relhasindex> is set by
+ true. For example, relhasindex is set by
CREATE INDEX, but it is never cleared by
DROP INDEX. Instead, VACUUM clears
- relhasindex> if it finds the table has no indexes. This
+ relhasindex if it finds the table has no indexes. This
arrangement avoids race conditions and improves concurrency.
@@ -1995,11 +2015,11 @@ SCRAM-SHA-256$<iteration count>>:<salt><
The catalog pg_collation describes the
available collations, which are essentially mappings from an SQL
name to operating system locale categories.
- See for more information.
+ See for more information.
- pg_collation> Columns
+ pg_collation Columns
@@ -2062,14 +2082,14 @@ SCRAM-SHA-256$<iteration count>>:<salt><
collcollatename
- LC_COLLATE> for this collation object
+ LC_COLLATE for this collation objectcollctypename
- LC_CTYPE> for this collation object
+ LC_CTYPE for this collation object
@@ -2087,27 +2107,27 @@ SCRAM-SHA-256$<iteration count>>:<salt><
- Note that the unique key on this catalog is (collname>,
- collencoding>, collnamespace>) not just
- (collname>, collnamespace>).
+ Note that the unique key on this catalog is (collname,
+ collencoding, collnamespace) not just
+ (collname, collnamespace).
PostgreSQL generally ignores all
- collations that do not have collencoding> equal to
+ collations that do not have collencoding equal to
either the current database's encoding or -1, and creation of new entries
- with the same name as an entry with collencoding> = -1
+ with the same name as an entry with collencoding = -1
is forbidden. Therefore it is sufficient to use a qualified SQL name
- (schema>.name>) to identify a collation,
+ (schema.name) to identify a collation,
even though this is not unique according to the catalog definition.
The reason for defining the catalog this way is that
- initdb> fills it in at cluster initialization time with
+ initdb fills it in at cluster initialization time with
entries for all locales available on the system, so it must be able to
hold entries for all encodings that might ever be used in the cluster.
- In the template0> database, it could be useful to create
+ In the template0 database, it could be useful to create
collations whose encoding does not match the database encoding,
since they could match the encodings of databases later cloned from
- template0>. This would currently have to be done manually.
+ template0. This would currently have to be done manually.
@@ -2123,13 +2143,13 @@ SCRAM-SHA-256$<iteration count>>:<salt><
key, unique, foreign key, and exclusion constraints on tables.
(Column constraints are not treated specially. Every column constraint is
equivalent to some table constraint.)
- Not-null constraints are represented in the pg_attribute>
+ Not-null constraints are represented in the pg_attribute
catalog, not here.
User-defined constraint triggers (created with CREATE CONSTRAINT
- TRIGGER>) also give rise to an entry in this table.
+ TRIGGER) also give rise to an entry in this table.
@@ -2137,7 +2157,7 @@ SCRAM-SHA-256$<iteration count>>:<salt><
- pg_constraint> Columns
+ pg_constraint Columns
@@ -2178,12 +2198,12 @@ SCRAM-SHA-256$<iteration count>>:<salt><
char
- c> = check constraint,
- f> = foreign key constraint,
- p> = primary key constraint,
- u> = unique constraint,
- t> = constraint trigger,
- x> = exclusion constraint
+ c = check constraint,
+ f = foreign key constraint,
+ p = primary key constraint,
+ u = unique constraint,
+ t = constraint trigger,
+ x = exclusion constraint
@@ -2243,11 +2263,11 @@ SCRAM-SHA-256$<iteration count>>:<salt><
charForeign key update action code:
- a> = no action,
- r> = restrict,
- c> = cascade,
- n> = set null,
- d> = set default
+ a = no action,
+ r = restrict,
+ c = cascade,
+ n = set null,
+ d = set default
@@ -2256,11 +2276,11 @@ SCRAM-SHA-256$<iteration count>>:<salt><
charForeign key deletion action code:
- a> = no action,
- r> = restrict,
- c> = cascade,
- n> = set null,
- d> = set default
+ a = no action,
+ r = restrict,
+ c = cascade,
+ n = set null,
+ d = set default
@@ -2269,9 +2289,9 @@ SCRAM-SHA-256$<iteration count>>:<salt><
charForeign key match type:
- f> = full,
- p> = partial,
- s> = simple
+ f = full,
+ p = partial,
+ s = simple
@@ -2309,7 +2329,7 @@ SCRAM-SHA-256$<iteration count>>:<salt><
conkeyint2[]
- pg_attribute.attnum>
+ pg_attribute.attnumIf a table constraint (including foreign keys, but not constraint
triggers), list of the constrained columns
@@ -2317,35 +2337,35 @@ SCRAM-SHA-256$<iteration count>>:<salt><
confkeyint2[]
- pg_attribute.attnum>
+ pg_attribute.attnumIf a foreign key, list of the referenced columnsconpfeqopoid[]
- pg_operator.oid>
+ pg_operator.oidIf a foreign key, list of the equality operators for PK = FK comparisonsconppeqopoid[]
- pg_operator.oid>
+ pg_operator.oidIf a foreign key, list of the equality operators for PK = PK comparisonsconffeqopoid[]
- pg_operator.oid>
+ pg_operator.oidIf a foreign key, list of the equality operators for FK = FK comparisonsconexclopoid[]
- pg_operator.oid>
+ pg_operator.oidIf an exclusion constraint, list of the per-column exclusion operators
@@ -2372,7 +2392,7 @@ SCRAM-SHA-256$<iteration count>>:<salt><
For other cases, a zero appears in conkey
and the associated index must be consulted to discover the expression
that is constrained. (conkey thus has the
- same contents as pg_index>.indkey> for the
+ same contents as pg_index.indkey for the
index.)
@@ -2380,7 +2400,7 @@ SCRAM-SHA-256$<iteration count>>:<salt><
consrc is not updated when referenced objects
change; for example, it won't track renaming of columns. Rather than
- relying on this field, it's best to use pg_get_constraintdef()>
+ relying on this field, it's best to use pg_get_constraintdef()
to extract the definition of a check constraint.
@@ -2404,12 +2424,12 @@ SCRAM-SHA-256$<iteration count>>:<salt><
The catalog pg_conversion describes
- encoding conversion procedures. See
+ encoding conversion procedures. See
for more information.
- pg_conversion> Columns
+ pg_conversion Columns
@@ -2496,8 +2516,8 @@ SCRAM-SHA-256$<iteration count>>:<salt><
The catalog pg_database stores information about
the available databases. Databases are created with the command.
- Consult for details about the meaning
+ linkend="sql-createdatabase"/> command.
+ Consult for details about the meaning
of some of the parameters.
@@ -2509,7 +2529,7 @@ SCRAM-SHA-256$<iteration count>>:<salt><
- pg_database> Columns
+ pg_database Columns
@@ -2572,7 +2592,7 @@ SCRAM-SHA-256$<iteration count>>:<salt><
If true, then this database can be cloned by
- any user with CREATEDB> privileges;
+ any user with CREATEDB privileges;
if false, then only superusers or the owner of
the database can clone it.
@@ -2584,7 +2604,7 @@ SCRAM-SHA-256$<iteration count>>:<salt><
If false then no one can connect to this database. This is
- used to protect the template0> database from being altered.
+ used to protect the template0 database from being altered.
@@ -2614,11 +2634,11 @@ SCRAM-SHA-256$<iteration count>>:<salt><
All transaction IDs before this one have been replaced with a permanent
- (frozen>) transaction ID in this database. This is used to
+ (frozen) transaction ID in this database. This is used to
track whether the database needs to be vacuumed in order to prevent
- transaction ID wraparound or to allow pg_xact> to be shrunk.
+ transaction ID wraparound or to allow pg_xact to be shrunk.
It is the minimum of the per-table
- pg_class>.relfrozenxid> values.
+ pg_class.relfrozenxid values.
@@ -2630,9 +2650,9 @@ SCRAM-SHA-256$<iteration count>>:<salt><
All multixact IDs before this one have been replaced with a
transaction ID in this database. This is used to
track whether the database needs to be vacuumed in order to prevent
- multixact ID wraparound or to allow pg_multixact> to be shrunk.
+ multixact ID wraparound or to allow pg_multixact to be shrunk.
It is the minimum of the per-table
- pg_class>.relminmxid> values.
+ pg_class.relminmxid values.
@@ -2643,7 +2663,7 @@ SCRAM-SHA-256$<iteration count>>:<salt><
The default tablespace for the database.
Within this database, all tables for which
- pg_class>.reltablespace> is zero
+ pg_class.reltablespace is zero
will be stored in this tablespace; in particular, all the non-shared
system catalogs will be there.
@@ -2655,8 +2675,8 @@ SCRAM-SHA-256$<iteration count>>:<salt><
Access privileges; see
- and
-
+ and
+
for details
@@ -2687,7 +2707,7 @@ SCRAM-SHA-256$<iteration count>>:<salt><
- pg_db_role_setting> Columns
+ pg_db_role_setting Columns
@@ -2734,12 +2754,12 @@ SCRAM-SHA-256$<iteration count>>:<salt><
- The catalog pg_default_acl> stores initial
+ The catalog pg_default_acl stores initial
privileges to be assigned to newly created objects.
- pg_default_acl> Columns
+ pg_default_acl Columns
@@ -2780,10 +2800,10 @@ SCRAM-SHA-256$<iteration count>>:<salt><
Type of object this entry is for:
- r> = relation (table, view),
- S> = sequence,
- f> = function,
- T> = type
+ r = relation (table, view),
+ S = sequence,
+ f = function,
+ T = type
@@ -2800,21 +2820,21 @@ SCRAM-SHA-256$<iteration count>>:<salt><
- A pg_default_acl> entry shows the initial privileges to
+ A pg_default_acl entry shows the initial privileges to
be assigned to an object belonging to the indicated user. There are
- currently two types of entry: global> entries with
- defaclnamespace> = 0, and per-schema> entries
+ currently two types of entry: global entries with
+ defaclnamespace = 0, and per-schema entries
that reference a particular schema. If a global entry is present then
- it overrides> the normal hard-wired default privileges
+ it overrides the normal hard-wired default privileges
for the object type. A per-schema entry, if present, represents privileges
- to be added to> the global or hard-wired default privileges.
+ to be added to the global or hard-wired default privileges.
Note that when an ACL entry in another catalog is null, it is taken
to represent the hard-wired default privileges for its object,
- not> whatever might be in pg_default_acl>
- at the moment. pg_default_acl> is only consulted during
+ not whatever might be in pg_default_acl
+ at the moment. pg_default_acl is only consulted during
object creation.
@@ -2831,9 +2851,9 @@ SCRAM-SHA-256$<iteration count>>:<salt><
The catalog pg_depend records the dependency
relationships between database objects. This information allows
- DROP> commands to find which other objects must be dropped
- by DROP CASCADE> or prevent dropping in the DROP
- RESTRICT> case.
+ DROP commands to find which other objects must be dropped
+ by DROP CASCADE or prevent dropping in the DROP
+ RESTRICT case.
@@ -2843,7 +2863,7 @@ SCRAM-SHA-256$<iteration count>>:<salt><
- pg_depend> Columns
+ pg_depend Columns
@@ -2876,7 +2896,7 @@ SCRAM-SHA-256$<iteration count>>:<salt><
For a table column, this is the column number (the
- objid> and classid> refer to the
+ objid and classid refer to the
table itself). For all other object types, this column is
zero.
@@ -2902,7 +2922,7 @@ SCRAM-SHA-256$<iteration count>>:<salt><
For a table column, this is the column number (the
- refobjid> and refclassid> refer
+ refobjid and refclassid refer
to the table itself). For all other object types, this column
is zero.
@@ -2925,17 +2945,17 @@ SCRAM-SHA-256$<iteration count>>:<salt><
In all cases, a pg_depend entry indicates that the
referenced object cannot be dropped without also dropping the dependent
object. However, there are several subflavors identified by
- deptype>:
+ deptype:
- DEPENDENCY_NORMAL> (n>)
+ DEPENDENCY_NORMAL (n)
A normal relationship between separately-created objects. The
dependent object can be dropped without affecting the
referenced object. The referenced object can only be dropped
- by specifying CASCADE>, in which case the dependent
+ by specifying CASCADE, in which case the dependent
object is dropped, too. Example: a table column has a normal
dependency on its data type.
@@ -2943,12 +2963,12 @@ SCRAM-SHA-256$<iteration count>>:<salt><
- DEPENDENCY_AUTO> (a>)
+ DEPENDENCY_AUTO (a)
The dependent object can be dropped separately from the
referenced object, and should be automatically dropped
- (regardless of RESTRICT> or CASCADE>
+ (regardless of RESTRICT or CASCADE
mode) if the referenced object is dropped. Example: a named
constraint on a table is made autodependent on the table, so
that it will go away if the table is dropped.
@@ -2957,41 +2977,64 @@ SCRAM-SHA-256$<iteration count>>:<salt><
- DEPENDENCY_INTERNAL> (i>)
+ DEPENDENCY_INTERNAL (i)
The dependent object was created as part of creation of the
referenced object, and is really just a part of its internal
- implementation. A DROP> of the dependent object
+ implementation. A DROP of the dependent object
will be disallowed outright (we'll tell the user to issue a
- DROP> against the referenced object, instead). A
- DROP> of the referenced object will be propagated
+ DROP against the referenced object, instead). A
+ DROP of the referenced object will be propagated
through to drop the dependent object whether
- CASCADE> is specified or not. Example: a trigger
+ CASCADE is specified or not. Example: a trigger
that's created to enforce a foreign-key constraint is made
internally dependent on the constraint's
- pg_constraint> entry.
+ pg_constraint entry.
+
+
+
+
+
+ DEPENDENCY_INTERNAL_AUTO (I)
+
+
+ The dependent object was created as part of creation of the
+ referenced object, and is really just a part of its internal
+ implementation. A DROP of the dependent object
+ will be disallowed outright (we'll tell the user to issue a
+ DROP against the referenced object, instead).
+ While a regular internal dependency will prevent
+ the dependent object from being dropped while any such dependencies
+ remain, DEPENDENCY_INTERNAL_AUTO will allow such
+ a drop as long as the object can be found by following any of such
+ dependencies.
+ Example: an index on a partition is made internal-auto-dependent on
+ both the partition itself as well as on the index on the parent
+ partitioned table; so the partition index is dropped together with
+ either the partition it indexes, or with the parent index it is
+ attached to.
- DEPENDENCY_EXTENSION> (e>)
+ DEPENDENCY_EXTENSION (e)
- The dependent object is a member of the extension> that is
+ The dependent object is a member of the extension that is
the referenced object (see
pg_extension).
The dependent object can be dropped only via
- DROP EXTENSION> on the referenced object. Functionally
+ DROP EXTENSION on the referenced object. Functionally
this dependency type acts the same as an internal dependency, but
- it's kept separate for clarity and to simplify pg_dump>.
+ it's kept separate for clarity and to simplify pg_dump.
- DEPENDENCY_AUTO_EXTENSION> (x>)
+ DEPENDENCY_AUTO_EXTENSION (x)
The dependent object is not a member of the extension that is the
@@ -3004,7 +3047,7 @@ SCRAM-SHA-256$<iteration count>>:<salt><
- DEPENDENCY_PIN> (p>)
+ DEPENDENCY_PIN (p)
There is no dependent object; this type of entry is a signal
@@ -3031,9 +3074,9 @@ SCRAM-SHA-256$<iteration count>>:<salt><
- The catalog pg_description> stores optional descriptions
+ The catalog pg_description stores optional descriptions
(comments) for each database object. Descriptions can be manipulated
- with the command and viewed with
+ with the command and viewed with
psql's \d commands.
Descriptions of many built-in system objects are provided in the initial
contents of pg_description.
@@ -3046,7 +3089,7 @@ SCRAM-SHA-256$<iteration count>>:<salt><
- pg_description> Columns
+ pg_description Columns
@@ -3079,7 +3122,7 @@ SCRAM-SHA-256$<iteration count>>:<salt><
For a comment on a table column, this is the column number (the
- objoid> and classoid> refer to
+ objoid and classoid refer to
the table itself). For all other object types, this column is
zero.
@@ -3113,7 +3156,7 @@ SCRAM-SHA-256$<iteration count>>:<salt><
- pg_enum> Columns
+ pg_enum Columns
@@ -3137,7 +3180,7 @@ SCRAM-SHA-256$<iteration count>>:<salt><
enumtypidoidpg_type.oid
- The OID of the pg_type> entry owning this enum value
+ The OID of the pg_type entry owning this enum value
@@ -3171,7 +3214,7 @@ SCRAM-SHA-256$<iteration count>>:<salt><
When an enum type is created, its members are assigned sort-order
- positions 1..n>. But members added later might be given
+ positions 1..n. But members added later might be given
negative or fractional values of enumsortorder.
The only requirement on these values is that they be correctly
ordered and unique within each enum type.
@@ -3188,11 +3231,11 @@ SCRAM-SHA-256$<iteration count>>:<salt><
The catalog pg_event_trigger stores event triggers.
- See for more information.
+ See for more information.
- pg_event_trigger> Columns
+ pg_event_trigger Columns
@@ -3238,12 +3281,12 @@ SCRAM-SHA-256$<iteration count>>:<salt><
char
- Controls in which modes
+ Controls in which modes
the event trigger fires.
- O> = trigger fires in origin> and local> modes,
- D> = trigger is disabled,
- R> = trigger fires in replica> mode,
- A> = trigger fires always.
+ O = trigger fires in origin and local modes,
+ D = trigger is disabled,
+ R = trigger fires in replica mode,
+ A = trigger fires always.
@@ -3271,12 +3314,12 @@ SCRAM-SHA-256$<iteration count>>:<salt><
The catalog pg_extension stores information
- about the installed extensions. See
+ about the installed extensions. See
for details about extensions.
- pg_extension> Columns
+ pg_extension Columns
@@ -3335,16 +3378,16 @@ SCRAM-SHA-256$<iteration count>>:<salt><
extconfigoid[]pg_class.oid
- Array of regclass> OIDs for the extension's configuration
- table(s), or NULL> if none
+ Array of regclass OIDs for the extension's configuration
+ table(s), or NULL if noneextconditiontext[]
- Array of WHERE>-clause filter conditions for the
- extension's configuration table(s), or NULL> if none
+ Array of WHERE-clause filter conditions for the
+ extension's configuration table(s), or NULL if none
@@ -3352,7 +3395,7 @@ SCRAM-SHA-256$<iteration count>>:<salt><
- Note that unlike most catalogs with a namespace> column,
+ Note that unlike most catalogs with a namespace column,
extnamespace is not meant to imply
that the extension belongs to that schema. Extension names are never
schema-qualified. Rather, extnamespace
@@ -3379,7 +3422,7 @@ SCRAM-SHA-256$<iteration count>>:<salt><
- pg_foreign_data_wrapper> Columns
+ pg_foreign_data_wrapper Columns
@@ -3443,8 +3486,8 @@ SCRAM-SHA-256$<iteration count>>:<salt><
Access privileges; see
- and
-
+ and
+
for details
@@ -3454,7 +3497,7 @@ SCRAM-SHA-256$<iteration count>>:<salt><
text[]
- Foreign-data wrapper specific options, as keyword=value> strings
+ Foreign-data wrapper specific options, as keyword=value strings
@@ -3478,7 +3521,7 @@ SCRAM-SHA-256$<iteration count>>:<salt><
- pg_foreign_server> Columns
+ pg_foreign_server Columns
@@ -3539,8 +3582,8 @@ SCRAM-SHA-256$<iteration count>>:<salt><
Access privileges; see
- and
-
+ and
+
for details
@@ -3550,7 +3593,7 @@ SCRAM-SHA-256$<iteration count>>:<salt><
text[]
- Foreign server specific options, as keyword=value> strings
+ Foreign server specific options, as keyword=value strings
@@ -3576,7 +3619,7 @@ SCRAM-SHA-256$<iteration count>>:<salt><
- pg_foreign_table> Columns
+ pg_foreign_table Columns
@@ -3593,7 +3636,7 @@ SCRAM-SHA-256$<iteration count>>:<salt><
ftrelidoidpg_class.oid
- OID of the pg_class> entry for this foreign table
+ OID of the pg_class entry for this foreign table
@@ -3608,7 +3651,7 @@ SCRAM-SHA-256$<iteration count>>:<salt><
text[]
- Foreign table options, as keyword=value> strings
+ Foreign table options, as keyword=value strings
@@ -3631,7 +3674,7 @@ SCRAM-SHA-256$<iteration count>>:<salt><
- pg_index> Columns
+ pg_index Columns
@@ -3648,14 +3691,14 @@ SCRAM-SHA-256$<iteration count>>:<salt><
indexrelidoidpg_class.oid
- The OID of the pg_class> entry for this index
+ The OID of the pg_class entry for this indexindrelidoidpg_class.oid
- The OID of the pg_class> entry for the table this index is for
+ The OID of the pg_class entry for the table this index is for
@@ -3678,7 +3721,7 @@ SCRAM-SHA-256$<iteration count>>:<salt><
boolIf true, this index represents the primary key of the table
- (indisunique> should always be true when this is true)
+ (indisunique should always be true when this is true)
@@ -3694,7 +3737,7 @@ SCRAM-SHA-256$<iteration count>>:<salt><
If true, the uniqueness check is enforced immediately on
insertion
- (irrelevant if indisunique> is not true)
+ (irrelevant if indisunique is not true)
@@ -3711,7 +3754,7 @@ SCRAM-SHA-256$<iteration count>>:<salt><
If true, the index is currently valid for queries. False means the
index is possibly incomplete: it must still be modified by
- INSERT>/UPDATE> operations, but it cannot safely
+ INSERT/UPDATE operations, but it cannot safely
be used for queries. If it is unique, the uniqueness property is not
guaranteed true either.
@@ -3722,8 +3765,8 @@ SCRAM-SHA-256$<iteration count>>:<salt><
bool
- If true, queries must not use the index until the xmin>
- of this pg_index> row is below their TransactionXmin
+ If true, queries must not use the index until the xmin
+ of this pg_index row is below their TransactionXmin
event horizon, because the table may contain broken HOT chains with
incompatible rows that they can see
@@ -3735,7 +3778,7 @@ SCRAM-SHA-256$<iteration count>>:<salt><
If true, the index is currently ready for inserts. False means the
- index must be ignored by INSERT>/UPDATE>
+ index must be ignored by INSERT/UPDATE
operations.
@@ -3755,9 +3798,9 @@ SCRAM-SHA-256$<iteration count>>:<salt><
bool
- If true this index has been chosen as replica identity>
+ If true this index has been chosen as replica identity
using ALTER TABLE ... REPLICA IDENTITY USING INDEX
- ...>
+ ...
@@ -3816,7 +3859,7 @@ SCRAM-SHA-256$<iteration count>>:<salt><
Expression trees (in nodeToString()
representation) for index attributes that are not simple column
references. This is a list with one element for each zero
- entry in indkey>. Null if all index attributes
+ entry in indkey. Null if all index attributes
are simple references.
@@ -3846,14 +3889,14 @@ SCRAM-SHA-256$<iteration count>>:<salt><
- The catalog pg_inherits> records information about
+ The catalog pg_inherits records information about
table inheritance hierarchies. There is one entry for each direct
- child table in the database. (Indirect inheritance can be determined
+ parent-child table relationship in the database. (Indirect inheritance can be determined
by following chains of entries.)
- pg_inherits> Columns
+ pg_inherits Columns
@@ -3908,7 +3951,7 @@ SCRAM-SHA-256$<iteration count>>:<salt><
- The catalog pg_init_privs> records information about
+ The catalog pg_init_privs records information about
the initial privileges of objects in the system. There is one entry
for each object in the database which has a non-default (non-NULL)
initial set of privileges.
@@ -3916,7 +3959,7 @@ SCRAM-SHA-256$<iteration count>>: