mirror of https://github.com/citusdata/citus.git
Fix the incorrect column count after ALTER TABLE, this fixes the bug #7378 (please read the analysis in the bug for more information)
(cherry picked from commit 00068e07c5
)
pull/7462/head
parent
eca999d6fe
commit
e18be9a972
|
@ -45,7 +45,7 @@ jobs:
|
||||||
- oraclelinux-7
|
- oraclelinux-7
|
||||||
- oraclelinux-8
|
- oraclelinux-8
|
||||||
- centos-7
|
- centos-7
|
||||||
- centos-8
|
- almalinux-8
|
||||||
- almalinux-9
|
- almalinux-9
|
||||||
POSTGRES_VERSION: ${{ fromJson(needs.get_postgres_versions_from_file.outputs.pg_versions) }}
|
POSTGRES_VERSION: ${{ fromJson(needs.get_postgres_versions_from_file.outputs.pg_versions) }}
|
||||||
|
|
||||||
|
@ -111,7 +111,6 @@ jobs:
|
||||||
- debian-buster-all
|
- debian-buster-all
|
||||||
- debian-bookworm-all
|
- debian-bookworm-all
|
||||||
- debian-bullseye-all
|
- debian-bullseye-all
|
||||||
- ubuntu-bionic-all
|
|
||||||
- ubuntu-focal-all
|
- ubuntu-focal-all
|
||||||
- ubuntu-jammy-all
|
- ubuntu-jammy-all
|
||||||
- ubuntu-kinetic-all
|
- ubuntu-kinetic-all
|
||||||
|
|
|
@ -1388,8 +1388,15 @@ set_join_column_names(deparse_namespace *dpns, RangeTblEntry *rte,
|
||||||
|
|
||||||
/* Assert we processed the right number of columns */
|
/* Assert we processed the right number of columns */
|
||||||
#ifdef USE_ASSERT_CHECKING
|
#ifdef USE_ASSERT_CHECKING
|
||||||
while (i < colinfo->num_cols && colinfo->colnames[i] == NULL)
|
for (int col_index = 0; col_index < colinfo->num_cols; col_index++)
|
||||||
i++;
|
{
|
||||||
|
/*
|
||||||
|
* In the above processing-loops, "i" advances only if
|
||||||
|
* the column is not new, check if this is a new column.
|
||||||
|
*/
|
||||||
|
if (colinfo->is_new_col[col_index])
|
||||||
|
i++;
|
||||||
|
}
|
||||||
Assert(i == colinfo->num_cols);
|
Assert(i == colinfo->num_cols);
|
||||||
Assert(j == nnewcolumns);
|
Assert(j == nnewcolumns);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1405,8 +1405,15 @@ set_join_column_names(deparse_namespace *dpns, RangeTblEntry *rte,
|
||||||
|
|
||||||
/* Assert we processed the right number of columns */
|
/* Assert we processed the right number of columns */
|
||||||
#ifdef USE_ASSERT_CHECKING
|
#ifdef USE_ASSERT_CHECKING
|
||||||
while (i < colinfo->num_cols && colinfo->colnames[i] == NULL)
|
for (int col_index = 0; col_index < colinfo->num_cols; col_index++)
|
||||||
i++;
|
{
|
||||||
|
/*
|
||||||
|
* In the above processing-loops, "i" advances only if
|
||||||
|
* the column is not new, check if this is a new column.
|
||||||
|
*/
|
||||||
|
if (colinfo->is_new_col[col_index])
|
||||||
|
i++;
|
||||||
|
}
|
||||||
Assert(i == colinfo->num_cols);
|
Assert(i == colinfo->num_cols);
|
||||||
Assert(j == nnewcolumns);
|
Assert(j == nnewcolumns);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1528,8 +1528,15 @@ set_join_column_names(deparse_namespace *dpns, RangeTblEntry *rte,
|
||||||
|
|
||||||
/* Assert we processed the right number of columns */
|
/* Assert we processed the right number of columns */
|
||||||
#ifdef USE_ASSERT_CHECKING
|
#ifdef USE_ASSERT_CHECKING
|
||||||
while (i < colinfo->num_cols && colinfo->colnames[i] == NULL)
|
for (int col_index = 0; col_index < colinfo->num_cols; col_index++)
|
||||||
i++;
|
{
|
||||||
|
/*
|
||||||
|
* In the above processing-loops, "i" advances only if
|
||||||
|
* the column is not new, check if this is a new column.
|
||||||
|
*/
|
||||||
|
if (colinfo->is_new_col[col_index])
|
||||||
|
i++;
|
||||||
|
}
|
||||||
Assert(i == colinfo->num_cols);
|
Assert(i == colinfo->num_cols);
|
||||||
Assert(j == nnewcolumns);
|
Assert(j == nnewcolumns);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -141,7 +141,17 @@ SetRangeTblExtraData(RangeTblEntry *rte, CitusRTEKind rteKind, char *fragmentSch
|
||||||
fauxFunction->funcexpr = (Node *) fauxFuncExpr;
|
fauxFunction->funcexpr = (Node *) fauxFuncExpr;
|
||||||
|
|
||||||
/* set the column count to pass ruleutils checks, not used elsewhere */
|
/* set the column count to pass ruleutils checks, not used elsewhere */
|
||||||
fauxFunction->funccolcount = list_length(rte->eref->colnames);
|
if (rte->relid != 0)
|
||||||
|
{
|
||||||
|
Relation rel = RelationIdGetRelation(rte->relid);
|
||||||
|
fauxFunction->funccolcount = RelationGetNumberOfAttributes(rel);
|
||||||
|
RelationClose(rel);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fauxFunction->funccolcount = list_length(rte->eref->colnames);
|
||||||
|
}
|
||||||
|
|
||||||
fauxFunction->funccolnames = funcColumnNames;
|
fauxFunction->funccolnames = funcColumnNames;
|
||||||
fauxFunction->funccoltypes = funcColumnTypes;
|
fauxFunction->funccoltypes = funcColumnTypes;
|
||||||
fauxFunction->funccoltypmods = funcColumnTypeMods;
|
fauxFunction->funccoltypmods = funcColumnTypeMods;
|
||||||
|
|
|
@ -682,5 +682,33 @@ ALTER TABLE table_without_sequence ADD COLUMN x BIGINT DEFAULT nextval('test_sch
|
||||||
SELECT pg_identify_object_as_address(classid, objid, objsubid) from pg_catalog.pg_dist_object WHERE objid IN ('test_schema_for_sequence_propagation.seq_10'::regclass);
|
SELECT pg_identify_object_as_address(classid, objid, objsubid) from pg_catalog.pg_dist_object WHERE objid IN ('test_schema_for_sequence_propagation.seq_10'::regclass);
|
||||||
SELECT pg_identify_object_as_address(classid, objid, objsubid) from pg_catalog.pg_dist_object WHERE objid IN ('test_schema_for_sequence_propagation'::regnamespace);
|
SELECT pg_identify_object_as_address(classid, objid, objsubid) from pg_catalog.pg_dist_object WHERE objid IN ('test_schema_for_sequence_propagation'::regnamespace);
|
||||||
|
|
||||||
|
-- Bug: https://github.com/citusdata/citus/issues/7378
|
||||||
|
|
||||||
|
-- Create a reference table
|
||||||
|
CREATE TABLE tbl_ref_mats(row_id integer primary key);
|
||||||
|
INSERT INTO tbl_ref_mats VALUES (1), (2);
|
||||||
|
SELECT create_reference_table('tbl_ref_mats');
|
||||||
|
|
||||||
|
-- Create a distributed table
|
||||||
|
CREATE TABLE tbl_dist_mats(series_id integer);
|
||||||
|
INSERT INTO tbl_dist_mats VALUES (1), (1), (2), (2);
|
||||||
|
SELECT create_distributed_table('tbl_dist_mats', 'series_id');
|
||||||
|
|
||||||
|
-- Create a view that joins the distributed table with the reference table on the distribution key.
|
||||||
|
CREATE VIEW vw_citus_views as
|
||||||
|
SELECT d.series_id FROM tbl_dist_mats d JOIN tbl_ref_mats r ON d.series_id = r.row_id;
|
||||||
|
|
||||||
|
-- The view initially works fine
|
||||||
|
SELECT * FROM vw_citus_views ORDER BY 1;
|
||||||
|
-- Now, alter the table
|
||||||
|
ALTER TABLE tbl_ref_mats ADD COLUMN category1 varchar(50);
|
||||||
|
SELECT * FROM vw_citus_views ORDER BY 1;
|
||||||
|
ALTER TABLE tbl_ref_mats ADD COLUMN category2 varchar(50);
|
||||||
|
SELECT * FROM vw_citus_views ORDER BY 1;
|
||||||
|
ALTER TABLE tbl_ref_mats DROP COLUMN category1;
|
||||||
|
SELECT * FROM vw_citus_views ORDER BY 1;
|
||||||
|
|
||||||
DROP SCHEMA test_schema_for_sequence_propagation CASCADE;
|
DROP SCHEMA test_schema_for_sequence_propagation CASCADE;
|
||||||
DROP TABLE table_without_sequence;
|
DROP TABLE table_without_sequence;
|
||||||
|
DROP TABLE tbl_ref_mats CASCADE;
|
||||||
|
DROP TABLE tbl_dist_mats CASCADE;
|
||||||
|
|
|
@ -1318,8 +1318,82 @@ SELECT pg_identify_object_as_address(classid, objid, objsubid) from pg_catalog.p
|
||||||
(schema,{test_schema_for_sequence_propagation},{})
|
(schema,{test_schema_for_sequence_propagation},{})
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
|
-- Bug: https://github.com/citusdata/citus/issues/7378
|
||||||
|
-- Create a reference table
|
||||||
|
CREATE TABLE tbl_ref_mats(row_id integer primary key);
|
||||||
|
INSERT INTO tbl_ref_mats VALUES (1), (2);
|
||||||
|
SELECT create_reference_table('tbl_ref_mats');
|
||||||
|
NOTICE: Copying data from local table...
|
||||||
|
NOTICE: copying the data has completed
|
||||||
|
DETAIL: The local data in the table is no longer visible, but is still on disk.
|
||||||
|
HINT: To remove the local data, run: SELECT truncate_local_data_after_distributing_table($$public.tbl_ref_mats$$)
|
||||||
|
create_reference_table
|
||||||
|
---------------------------------------------------------------------
|
||||||
|
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
-- Create a distributed table
|
||||||
|
CREATE TABLE tbl_dist_mats(series_id integer);
|
||||||
|
INSERT INTO tbl_dist_mats VALUES (1), (1), (2), (2);
|
||||||
|
SELECT create_distributed_table('tbl_dist_mats', 'series_id');
|
||||||
|
NOTICE: Copying data from local table...
|
||||||
|
NOTICE: copying the data has completed
|
||||||
|
DETAIL: The local data in the table is no longer visible, but is still on disk.
|
||||||
|
HINT: To remove the local data, run: SELECT truncate_local_data_after_distributing_table($$public.tbl_dist_mats$$)
|
||||||
|
create_distributed_table
|
||||||
|
---------------------------------------------------------------------
|
||||||
|
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
-- Create a view that joins the distributed table with the reference table on the distribution key.
|
||||||
|
CREATE VIEW vw_citus_views as
|
||||||
|
SELECT d.series_id FROM tbl_dist_mats d JOIN tbl_ref_mats r ON d.series_id = r.row_id;
|
||||||
|
-- The view initially works fine
|
||||||
|
SELECT * FROM vw_citus_views ORDER BY 1;
|
||||||
|
series_id
|
||||||
|
---------------------------------------------------------------------
|
||||||
|
1
|
||||||
|
1
|
||||||
|
2
|
||||||
|
2
|
||||||
|
(4 rows)
|
||||||
|
|
||||||
|
-- Now, alter the table
|
||||||
|
ALTER TABLE tbl_ref_mats ADD COLUMN category1 varchar(50);
|
||||||
|
SELECT * FROM vw_citus_views ORDER BY 1;
|
||||||
|
series_id
|
||||||
|
---------------------------------------------------------------------
|
||||||
|
1
|
||||||
|
1
|
||||||
|
2
|
||||||
|
2
|
||||||
|
(4 rows)
|
||||||
|
|
||||||
|
ALTER TABLE tbl_ref_mats ADD COLUMN category2 varchar(50);
|
||||||
|
SELECT * FROM vw_citus_views ORDER BY 1;
|
||||||
|
series_id
|
||||||
|
---------------------------------------------------------------------
|
||||||
|
1
|
||||||
|
1
|
||||||
|
2
|
||||||
|
2
|
||||||
|
(4 rows)
|
||||||
|
|
||||||
|
ALTER TABLE tbl_ref_mats DROP COLUMN category1;
|
||||||
|
SELECT * FROM vw_citus_views ORDER BY 1;
|
||||||
|
series_id
|
||||||
|
---------------------------------------------------------------------
|
||||||
|
1
|
||||||
|
1
|
||||||
|
2
|
||||||
|
2
|
||||||
|
(4 rows)
|
||||||
|
|
||||||
DROP SCHEMA test_schema_for_sequence_propagation CASCADE;
|
DROP SCHEMA test_schema_for_sequence_propagation CASCADE;
|
||||||
NOTICE: drop cascades to 2 other objects
|
NOTICE: drop cascades to 2 other objects
|
||||||
DETAIL: drop cascades to sequence test_schema_for_sequence_propagation.seq_10
|
DETAIL: drop cascades to sequence test_schema_for_sequence_propagation.seq_10
|
||||||
drop cascades to default value for column x of table table_without_sequence
|
drop cascades to default value for column x of table table_without_sequence
|
||||||
DROP TABLE table_without_sequence;
|
DROP TABLE table_without_sequence;
|
||||||
|
DROP TABLE tbl_ref_mats CASCADE;
|
||||||
|
NOTICE: drop cascades to view vw_citus_views
|
||||||
|
DROP TABLE tbl_dist_mats CASCADE;
|
||||||
|
|
Loading…
Reference in New Issue