Commit 9d88571
committed
[BACKPORT 2024.1][yugabyte#23708] YSQL: Fix bug in create colocated table
Summary:
To reproduce the bug:
(1) create a local cluster with the following command
```
./bin/yb-ctl create --rf 1 --tserver_flags=report_ysql_ddl_txn_status_to_master=false
```
(2) Run the following SQL via ysqlsh
```
$ ./bin/ysqlsh
ysqlsh (11.2-YB-2.23.1.0-b0)
Type "help" for help.
yugabyte=# CREATE DATABASE colocation_db colocation = true;
CREATE DATABASE
yugabyte=# \c colocation_db
You are now connected to database "colocation_db" as user "yugabyte".
colocation_db=# CREATE TABLE foo(id INT);
```
The `CREATE TABLE` statement hangs until timed out after 600 seconds.
From the yb-master log, I saw the following error:
```
W0829 00:29:56.928934 2215 ysql_ddl_handler.cc:669] YsqlTableSchemaChecker failed: Illegal state (yb/master/ysql_ddl_handler.cc:174): Find Transaction Status for table 00004000000030008000000000004003.colocation.parent.tablename [id=00004000000030008000000000004003.colocation.parent.uuid] txn: f274cc3c-3ee2-4570-b089-6e254ba81168 failed with Not found (yb/common/schema.cc:602): Couldn't find column relkind in the schema
```
The bug is that in function `PgSchemaCheckerWithReadTime` we try to read
`relkind` column unconditionally from a catalog table which can be either
`pg_yb_tablegroup` or `pg_class`. But `relkind` is only a column of `pg_class`,
not a column of `pg_yb_tablegroup`. I fixed the bug by only read `relkind` column
from `pg_class`, and skip reading relkind column if the catalog table is
`pg_yb_tablegroup`.
Added a new unit test, which would fail without the fix.
Jira: DB-12618
Original commit: 31a6d4f / D37635
NOTE:
Merge conflicts resolved. The bug only existed in master branch so there
is no code fix backport needed. However I backported the unit test TestCreateColocatedTable
from the original diff, plus an additional unit test added in the master branch
TestPartitionedTableSchemaVerification to 2024.1 to ensure we don't regress on 2024.1.
Test Plan: ./yb_build.sh debug --cxx-test pg_ddl_atomicity-test --gtest_filter PgDdlAtomicityTest.TestCreateColocatedTable
Reviewers: fizaa
Reviewed By: fizaa
Subscribers: yql, ybase
Differential Revision: https://phorge.dev.yugabyte.com/D377091 parent e282b15 commit 9d88571
1 file changed
+53
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1722 | 1722 | | |
1723 | 1723 | | |
1724 | 1724 | | |
| 1725 | + | |
| 1726 | + | |
| 1727 | + | |
| 1728 | + | |
| 1729 | + | |
| 1730 | + | |
| 1731 | + | |
| 1732 | + | |
| 1733 | + | |
| 1734 | + | |
| 1735 | + | |
| 1736 | + | |
| 1737 | + | |
| 1738 | + | |
| 1739 | + | |
| 1740 | + | |
| 1741 | + | |
| 1742 | + | |
| 1743 | + | |
| 1744 | + | |
| 1745 | + | |
| 1746 | + | |
| 1747 | + | |
| 1748 | + | |
| 1749 | + | |
| 1750 | + | |
| 1751 | + | |
| 1752 | + | |
| 1753 | + | |
| 1754 | + | |
| 1755 | + | |
| 1756 | + | |
| 1757 | + | |
| 1758 | + | |
| 1759 | + | |
| 1760 | + | |
| 1761 | + | |
| 1762 | + | |
| 1763 | + | |
| 1764 | + | |
| 1765 | + | |
| 1766 | + | |
| 1767 | + | |
| 1768 | + | |
| 1769 | + | |
| 1770 | + | |
| 1771 | + | |
| 1772 | + | |
| 1773 | + | |
| 1774 | + | |
| 1775 | + | |
| 1776 | + | |
| 1777 | + | |
1725 | 1778 | | |
1726 | 1779 | | |
0 commit comments