-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unexpected behaviour in "pg_attribute" on column drop and recreate #34710
Comments
It's a bug, we have a PR open already with a fix in the works.
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
|
@AlexMesser while we're at this, so you know we have ran some investigations about what breaks in TypeORM when ran with CockroachDB 2.1. Are you interested in our findings? so as to save you some time. |
The analysis is here: #22298 (comment) |
33697: sql: make pg_catalog OIDs stable and refer to the descriptor IDs directly r=knz a=hueypark Fixes #32940 Fixes #32963 Fixes #34710 Enables #32964 This patch changes the definition of vtables to assign a unique table ID to every virtual table. Moreover, it also extends vtable descriptors to assign proper column IDs to virtual table columns. This aims to support the logical planning code, the table and plan caches, and simplify+fix the introspection tables. Incidentally it also makes it possible to use COMMENT ON on virtual tables and their columns too. The table IDs are picked descending from MaxUint32 although this may be refined in future PRs to accommodate the numbering of virtual schema descriptors. Incidentally `pg_catalog.pg_attribute` is fixed to properly use the column ID in column `attnum`, so that `attnum` remains stable across column drops. Release note (sql change): Virtual tables in `pg_catalog`, `information_schema` etc now support `COMMENT ON` like regular tables. Co-authored-by: Jaewan Park <jaewan.huey.park@gmail.com>
You can pick up the changes in #33697 to move forward with |
You can alternatively pick #34734 against the release-2.1 branch. |
hey @knz, how can I get those changes in my locally installed crdb? Do I need to build a binary manually or do you have some automatic build system? Thanks in advice. |
@AlexMesser you can pull a copy of the repo + branch (ensure it's in your $GOPATH) then |
Hello. I'm working on CockroachDB implementation in TypeORM and I faced a strange behaviour when I drop and recreate column again. I tested the same steps on postgres and also show postgres behavior.
First, create a table with some columns and constraints:
columns definition in "pg_attribute" is the same in crdb and postgres:
then, drop the "name" column
"pg_attribute" result in crdb:
and in postgres:
then, recreate column again:
result in crdb:
and in postgres
As we see, in crdb columns attnum recalculating after each column deletion.
Why its a problem?
I'm trying to find all table constraints with such query which relies on columns
attnum
property. It works perfectly in postgres, but wrong in crdb:result after table creation:
here we see an unique constraint named
UQ_12e79261329cf680e4e4db3cc0d
with columnstext
andtag
presented on 3 and 4 rows. They haveattnum
attribute with values 4 fortext
and 5 fortag
which are also defined in 'conkey' column as {4, 5}. Thename
column does not have any constraint and not presented in selection. Itsattnum
is equal 3."name" column dropped:
after column was dropped,
attnum
property values recalculated.text
'sattnum
becomes 3 andtag
's - 4. Butconkey
was't changed and row withtext
column disappears from selection result."name" column recreated:
Now column was recreated,
attnum
values recalculated again andname
becomes 5. Nowname
column involved in composite unique constraint, but WE NEVER created UNIQUE for itQuery result becomes totally wrong and breaks table synchronization. Is it an expected behaviour of
attnum
and I must look for other ways to find table constraints, or it is a bug ?I am using CockroachDB version 2.1.4.
The text was updated successfully, but these errors were encountered: