Files
floci/docs
Vũ Thế Huy a42779bb2a feat(redshift): prune external table partitions from query WHERE predicates (#7413)
* feat(redshift): prune external table partitions from query WHERE predicates

Load only the partitions selected by top-level AND predicates of the query WHERE clause for external tables, accumulating partitions across queries and avoiding full scans when specific partitions are requested.

* fix(redshift): handle CASE in partition pruner, overlapping refreshes, and isolate spectrum test schema

* fix(redshift): identify materialized rows by partition and share SQL lexer

Tell materialized external table rows apart by an internal partition identifier column so that refreshing or deleting a partition only deletes its exact rows and never removes rows belonging to partitions whose keys overlap when converted. Dropping a partition no longer reads or authorizes retained overlapping partitions, preventing unauthorized S3 access errors on unselected partitions.

Share tokenization rules between ExternalReferenceScanner and PartitionPruner in SpectrumSqlLexer.

* fix(redshift): hide the partition column behind a view and read strings as strings in the scanner

A partitioned external table kept the partition each row came from in a column of the public table,
so SELECT * returned an extra column and INSERT ... SELECT * could fail on the column count. The rows
now live in a backing table, _floci_spectrum_<table>, and the name the user queries is a view of the
declared columns only. DROP TABLE drops the view and the backing table, and the Data API ListTables
does not list the backing table.

ExternalReferenceScanner took a one-character string such as ';' for a statement separator, which
cleared the table context and let the query skip preparation and its S3 checks. It now reads the
structural characters by token kind.

The pruning integration test used the legacy catalog, whose parser does not read PARTITIONED BY, so
it now creates a Glue database.

* fix(redshift): keep the partition backing table in a schema of its own and send plain batches

The batches that drop and replace the relation of a partitioned external table started with a DO
block. PostgresExtendedBackendSession wraps only batches that start with CREATE or DROP, so an
extended query sent them unchanged and PostgreSQL refused several commands in one prepared
statement. A DO block nested in the wrapper is not valid either, and a schema or table name that
held the dollar-quote tag would have closed the body early. The relation is now dropped with
DROP VIEW or DROP TABLE as the last load made it, so every batch is plain statements.

The backing table was named after the table it backs in the user's schema, so a Glue table of the
same name could drop or reuse it, and the Data API ListTables hid every table with that prefix. It
now lives in the schema floci_spectrum under a name made from the external schema and table, and
ListSchemas and ListTables hide only that schema.

* fix(redshift): load the whole external table when partition keys overlap instead of keeping a backing table

Delete by key value is only safe when no two partitions cast to the same value. When they do (integer 1 and 01, decimal 1.0 and 1.00, boolean true and t), the query reads every partition and a change replaces the whole table. This drops the backing table, view and floci_spectrum schema, which broke dropping a table whose Glue definition gained partition keys, other users' loads, and DROP SCHEMA CASCADE.

* fix(redshift): expect 22P02 SQLSTATE on invalid partition data
2026-11-03 21:39:17 -04:00
..
2026-03-15 17:43:56 -05:00