postgresql/src/test
Peter Eisentraut 83ea6c5402 Virtual generated columns
This adds a new variant of generated columns that are computed on read
(like a view, unlike the existing stored generated columns, which are
computed on write, like a materialized view).

The syntax for the column definition is

    ... GENERATED ALWAYS AS (...) VIRTUAL

and VIRTUAL is also optional.  VIRTUAL is the default rather than
STORED to match various other SQL products.  (The SQL standard makes
no specification about this, but it also doesn't know about VIRTUAL or
STORED.)  (Also, virtual views are the default, rather than
materialized views.)

Virtual generated columns are stored in tuples as null values.  (A
very early version of this patch had the ambition to not store them at
all.  But so much stuff breaks or gets confused if you have tuples
where a column in the middle is completely missing.  This is a
compromise, and it still saves space over being forced to use stored
generated columns.  If we ever find a way to improve this, a bit of
pg_upgrade cleverness could allow for upgrades to a newer scheme.)

The capabilities and restrictions of virtual generated columns are
mostly the same as for stored generated columns.  In some cases, this
patch keeps virtual generated columns more restricted than they might
technically need to be, to keep the two kinds consistent.  Some of
that could maybe be relaxed later after separate careful
considerations.

Some functionality that is currently not supported, but could possibly
be added as incremental features, some easier than others:

- index on or using a virtual column
- hence also no unique constraints on virtual columns
- extended statistics on virtual columns
- foreign-key constraints on virtual columns
- not-null constraints on virtual columns (check constraints are supported)
- ALTER TABLE / DROP EXPRESSION
- virtual column cannot have domain type
- virtual columns are not supported in logical replication

The tests in generated_virtual.sql have been copied over from
generated_stored.sql with the keyword replaced.  This way we can make
sure the behavior is mostly aligned, and the differences can be
visible.  Some tests for currently not supported features are
currently commented out.

Reviewed-by: Jian He <jian.universality@gmail.com>
Reviewed-by: Dean Rasheed <dean.a.rasheed@gmail.com>
Tested-by: Shlok Kyal <shlok.kyal.oss@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/a368248e-69e4-40be-9c07-6c3b5880b0a6@eisentraut.org
2025-02-07 09:46:59 +01:00
..
authentication require_auth: prepare for multiple SASL mechanisms 2025-01-31 15:47:28 +01:00
examples Update copyright for 2025 2025-01-01 11:21:55 -05:00
icu Update copyright for 2025 2025-01-01 11:21:55 -05:00
isolation Add OLD/NEW support to RETURNING in DML queries. 2025-01-16 14:57:35 +00:00
kerberos Update copyright for 2025 2025-01-01 11:21:55 -05:00
ldap Update copyright for 2025 2025-01-01 11:21:55 -05:00
locale Update copyright for 2025 2025-01-01 11:21:55 -05:00
mb Fix MB regression tests for WAL-logging of hash indexes. 2017-03-15 07:25:36 -04:00
modules injection_points: Tweak more permutation in isolation test "basic" 2025-02-07 13:58:22 +09:00
perl Run perltidy 2025-01-22 10:15:32 +09:00
postmaster Test postmaster with program_options_handling_ok() et al. 2025-01-26 09:39:05 -08:00
recovery Move SQL tests of pg_stat_io for WAL data to recovery test 029_stats_restart 2025-02-07 09:42:31 +09:00
regress Virtual generated columns 2025-02-07 09:46:59 +01:00
ssl Improve grammar of options for command arrays in TAP tests 2025-01-22 14:47:13 +09:00
subscription Virtual generated columns 2025-02-07 09:46:59 +01:00
Makefile Add PG_TEST_EXTRA configure option to the Make builds 2024-11-04 14:09:38 +02:00
meson.build Update copyright for 2025 2025-01-01 11:21:55 -05:00
README Remove the option to build thread_test.c outside configure. 2020-10-21 12:08:48 -04:00

PostgreSQL tests
================

This directory contains a variety of test infrastructure as well as some of the
tests in PostgreSQL. Not all tests are here -- in particular, there are more in
individual contrib/ modules and in src/bin.

Not all these tests get run by "make check". Check src/test/Makefile to see
which tests get run automatically.

authentication/
  Tests for authentication (but see also below)

examples/
  Demonstration programs for libpq that double as regression tests via
  "make check"

isolation/
  Tests for concurrent behavior at the SQL level

kerberos/
  Tests for Kerberos/GSSAPI authentication and encryption

ldap/
  Tests for LDAP-based authentication

locale/
  Sanity checks for locale data, encodings, etc

mb/
  Tests for multibyte encoding (UTF-8) support

modules/
  Extensions used only or mainly for test purposes, generally not suitable
  for installing in production databases

perl/
  Infrastructure for Perl-based TAP tests

recovery/
  Test suite for recovery and replication

regress/
  PostgreSQL's main regression test suite, pg_regress

ssl/
  Tests to exercise and verify SSL certificate handling

subscription/
  Tests for logical replication