Skip to content
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

[YSQL] Incorrect syscatalog negative caching for pg_type #15152

Open
m-iancu opened this issue Nov 28, 2022 · 0 comments
Open

[YSQL] Incorrect syscatalog negative caching for pg_type #15152

m-iancu opened this issue Nov 28, 2022 · 0 comments
Labels
area/ysql Yugabyte SQL (YSQL) kind/bug This issue is a bug priority/medium Medium priority issue

Comments

@m-iancu
Copy link
Contributor

m-iancu commented Nov 28, 2022

Jira Link: DB-4349

Description

In the latest versions we use negative caching for pg_type (TYPEOID and TYPENAMENSP).
As a result we have increment the catalog version when we create a new type (so negative entries can be invalidated correctly).
See for instance the cases in: https://github.com/yugabyte/yugabyte-db/blob/master/src/postgres/src/backend/utils/misc/pg_yb_utils.c#L1332

However, the current version is not complete.
First domain (T_CreateDomainStmt) and enum (T_CreateEnumStmt) incorrectly do not increment the version.
Second, CREATE TABLE t also creates a type t implicitly (composite type with the table schema). So technically we should increment the catalog version for every create table as well (currently we only do it for some sub-cases of CREATE TABLE).

Repro

General setup

Create a simulated 3-node cluster (yugabyted instead of yb-ctl also works).

 ./bin/yb-ctl destroy && ./bin/yb-ctl create --rf 3

Connect to node 1

Will call this connection 1 below

./bin/ysqlsh -h 127.0.0.1

Connect to node 2

Will call this connection 2 below

./bin/ysqlsh -h 127.0.0.1

Example 1

On connection 2 try to use a type enum_tp1.

As expected this will fail and also it will add a negative entry in the system catalog cache for that type name.

CREATE TABLE test(c enum_tp1);
ERROR:  type "enum_tp1" does not exist
LINE 1: CREATE TABLE  test(c enum_tp1);

On connection 1 create a type enum_tp1

Because of the catalog version issue for enum types mentioned above this will not end up notifying connection 2 to invalidate that cache entry.

CREATE TYPE enum_tp1 AS ENUM ('a', 'b');

On connection 2 try to use the type enum_tp1

This should now succeed but on this connection it will fail.

CREATE TABLE test(c enum_tp1);
ERROR:  type "enum_tp1" does not exist
LINE 1: CREATE TABLE  test(c enum_tp1);

To confirm, on connection 1 (or any connection where that negative cache entry wasn't added) this will work fine.

CREATE TABLE test(c enum_tp1);
CREATE TABLE

Example 2

Note: Better to use fresh connections (re-run General setup section above) to avoid issues related to example 1.

On connection 2 try to use a type t1.

As expected this will fail and also it will add a negative entry in the system catalog cache for that type name.

CREATE TABLE test2(c t1);
ERROR:  type "t1" does not exist
LINE 1: CREATE TABLE test2(c t1);

On connection 1 create a table t1

This will implicitly create a type t1 which will lead to same issue above -- this time due to CREATE TABLE (T_CreateStmt) not always incrementing catalog version.

CREATE TABLE t1(c1 int, c2 int);

On connection 2 try to use the type enum_tp1

This should now succeed but on this connection it will fail.

CREATE TABLE test2(c t1);
ERROR:  type "t1" does not exist
LINE 1: CREATE TABLE test2(c t1);

To confirm, on connection 1 (or any connection where that negative cache entry wasn't added) this will work fine.

CREATE TABLE test2(c t1);
CREATE TABLE
@m-iancu m-iancu added area/ysql Yugabyte SQL (YSQL) status/awaiting-triage Issue awaiting triage labels Nov 28, 2022
@yugabyte-ci yugabyte-ci added kind/bug This issue is a bug priority/medium Medium priority issue labels Nov 28, 2022
@yugabyte-ci yugabyte-ci removed the status/awaiting-triage Issue awaiting triage label Jan 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/ysql Yugabyte SQL (YSQL) kind/bug This issue is a bug priority/medium Medium priority issue
Projects
None yet
Development

No branches or pull requests

2 participants