Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
60154: sql: add crdb_internal.show_create_all_tables builtin r=rafiss a=RichardJCai sql: add crdb_internal.show_create_all_tables builtin Making this a PR first before continuing with #53488, we can alias this builtin with SHOW CREATE ALL TABLES. Example output: ``` query T SELECT crdb_internal.show_create_all_tables('d') ---- CREATE TABLE public.parent ( x INT8 NULL, y INT8 NULL, z INT8 NULL, UNIQUE INDEX parent_x_y_z_key (x ASC, y ASC, z ASC), UNIQUE INDEX parent_x_key (x ASC), FAMILY f1 (x, y, z, rowid) ); CREATE TABLE public.full_test ( x INT8 NULL, y INT8 NULL, z INT8 NULL, UNIQUE INDEX full_test_x_key (x ASC), FAMILY f1 (x, y, z, rowid) ); CREATE SEQUENCE public.s MINVALUE 1 MAXVALUE 9223372036854775807 INCREMENT 1 START 1; CREATE VIEW public.vx ("?column?") AS SELECT 1; ALTER TABLE public.full_test ADD CONSTRAINT fk_x_ref_parent FOREIGN KEY (x, y, z) REFERENCES public.parent(x, y, z) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE; ALTER TABLE public.full_test ADD CONSTRAINT test_fk FOREIGN KEY (x) REFERENCES public.parent(x) ON DELETE CASCADE; -- Validate foreign key constraints. These can fail if there was unvalidated data during the SHOW CREATE ALL TABLES ALTER TABLE public.full_test VALIDATE CONSTRAINT fk_x_ref_parent; ALTER TABLE public.full_test VALIDATE CONSTRAINT test_fk; ``` Release note (sql change): crdb_internal.show_create_all_tables is a new builtin that takes in a database name (string) and returns a flat log of all the CREATE TABLE statements in the database followed by alter statements to add constraints. The output can be used to recreate a database. This builtin was added to replace old dump logic. 60469: opt: prefer sorting fewer columns r=RaduBerinde a=RaduBerinde Currently, if we have to sort results and project a new column, there is no cost difference between the two orders and we happen to prefer the sort on top. It is preferable to sort before adding new columns to avoid storing the extra value in memory or on disk. This change improves the sort costing by adding a cost proportional to the total number of values. Fixes #32952. Co-authored-by: richardjcai <caioftherichard@gmail.com> Co-authored-by: Radu Berinde <radu@cockroachlabs.com>
- Loading branch information