-
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
sql: v23.1.8: relation × (67321): depends-on function × (67320) has no corresponding depended-on-by back reference #109414
Comments
I think I caused this error 🔥 Maybe some context here helps: I was trying to use a custom function in a check constraint to basically emulate a foreign key constraint where the related table is based on a column in the table. Imagine the table a has (account_type: string and account_id: uuid) the constraint would run a function that runs:
|
Got it to work by disabling the transaction that was constructed around my function creation and schema change query |
Thanks for the context @hendrikheil! I don't think I would have been able to reproduce this without the example you gave. I can repro on 2c1d4af with the following snippet: BEGIN;
CREATE TABLE accounts_a (id UUID NOT NULL);
CREATE TABLE accounts_b (id UUID NOT NULL);
CREATE TABLE a (
account_id UUID NOT NULL,
account_type TEXT NOT NULL
);
CREATE FUNCTION is_a_or_b(account_id UUID, account_type TEXT) RETURNS BOOL LANGUAGE SQL AS $$ SELECT (CASE
WHEN account_type = 'type_a' THEN (SELECT EXISTS(SELECT * FROM accounts_a WHERE id = account_id))
WHEN account_type = 'type_b' THEN (SELECT EXISTS(SELECT * FROM accounts_b WHERE id = account_id))
ELSE false
END) $$;
ALTER TABLE a ADD CONSTRAINT is_a_or_b CHECK (is_a_or_b(account_id, account_type));
COMMIT; Looks like the trick is referencing multiple tables within the UDF 😄 |
Previously, `ALTER TABLE ... ADD CONSTRAINT` statements that referenced a UDF did not appropriately update UDFs' `DependedOnBy` field to reference the table/constraint that utilized it. This would surface as the validation error reported in cockroachdb#109414, `relation X: depends-on function X has no corresponding depended-on-by back reference`. This commit ensures that the back references are updated by copying a hook from `CREATE TABLE`. Epic: None Fixes: cockroachdb#109414 Release note (bug fix): `ALTER TABLE ... ADD CONSTRAINT CHECK ...` statements that utilize a UDF in the CHECK no longer cause a validation error.
Previously, `ALTER TABLE ... ADD CONSTRAINT` statements that referenced a UDF did not appropriately update UDFs' `DependedOnBy` field to reference the table/constraint that utilized it. This would surface as the validation error reported in cockroachdb#109414, `relation X: depends-on function X has no corresponding depended-on-by back reference`. This commit ensures that the back references are updated by copying a hook from `CREATE TABLE`. Epic: None Fixes: cockroachdb#109414 Release note (bug fix): `ALTER TABLE ... ADD CONSTRAINT CHECK ...` statements that utilize a UDF in the CHECK no longer cause a validation error.
110130: sql: update UDF references in `ALTER TABLE` r=rafiss a=chrisseto Previously, `ALTER TABLE ... ADD CONSTRAINT` statements that referenced a UDF did not appropriately update UDFs' `DependedOnBy` field to reference the table/constraint that utilized it. This would surface as the validation error reported in #109414, `relation X: depends-on function X has no corresponding depended-on-by back reference`. This commit ensures that the back references are updated by copying a hook from `CREATE TABLE`. Epic: None Fixes: #109414 Release note (bug fix): `ALTER TABLE ... ADD CONSTRAINT CHECK ...` statements that utilize a UDF in the CHECK no longer cause a validation error. Co-authored-by: Chris Seto <[email protected]>
Previously, `ALTER TABLE ... ADD CONSTRAINT` statements that referenced a UDF did not appropriately update UDFs' `DependedOnBy` field to reference the table/constraint that utilized it. This would surface as the validation error reported in #109414, `relation X: depends-on function X has no corresponding depended-on-by back reference`. This commit ensures that the back references are updated by copying a hook from `CREATE TABLE`. Epic: None Fixes: #109414 Release note (bug fix): `ALTER TABLE ... ADD CONSTRAINT CHECK ...` statements that utilize a UDF in the CHECK no longer cause a validation error.
This issue was auto filed by Sentry. It represents a crash or reported error on a live cluster with telemetry enabled.
Sentry Link: https://cockroach-labs.sentry.io/issues/4417277648/?referrer=webhooks_plugin
Panic Message:
Stacktrace (expand for inline code snippets):
src/runtime/asm_arm64.s#L1171-L1173
cockroach/pkg/sql/pgwire/conn.go
Lines 309 to 311 in 2c1d4af
cockroach/pkg/sql/conn_executor.go
Lines 899 to 901 in 2c1d4af
cockroach/pkg/sql/conn_executor.go
Lines 2102 to 2104 in 2c1d4af
cockroach/pkg/sql/conn_executor.go
Lines 2185 to 2187 in 2c1d4af
cockroach/pkg/sql/conn_executor.go
Lines 2180 to 2182 in 2c1d4af
cockroach/pkg/sql/conn_executor_exec.go
Lines 140 to 142 in 2c1d4af
cockroach/pkg/sql/conn_executor_exec.go
Lines 2985 to 2987 in 2c1d4af
cockroach/pkg/sql/conn_executor_exec.go
Lines 141 to 143 in 2c1d4af
cockroach/pkg/sql/conn_executor_exec.go
Lines 767 to 769 in 2c1d4af
cockroach/pkg/sql/conn_executor_exec.go
Lines 1233 to 1235 in 2c1d4af
cockroach/pkg/sql/conn_executor_exec.go
Lines 1329 to 1331 in 2c1d4af
cockroach/pkg/sql/catalog/descs/validate.go
Lines 73 to 75 in 2c1d4af
cockroach/pkg/sql/catalog/descs/validate.go
Lines 39 to 41 in 2c1d4af
cockroach/pkg/sql/catalog/internal/validate/validate.go
Lines 108 to 110 in 2c1d4af
cockroach/pkg/sql/catalog/internal/validate/validate.go
Lines 201 to 203 in 2c1d4af
cockroach/pkg/sql/catalog/internal/validate/validate.go
Lines 113 to 115 in 2c1d4af
cockroach/pkg/sql/catalog/tabledesc/validate.go
Lines 248 to 250 in 2c1d4af
cockroach/pkg/sql/catalog/internal/validate/validate.go
Lines 185 to 187 in 2c1d4af
cockroach/pkg/sql/catalog/internal/validate/validate.go
Lines 255 to 257 in 2c1d4af
src/runtime/asm_arm64.s#L1171-L1173
cockroach/pkg/sql/pgwire/conn.go
Lines 309 to 311 in 2c1d4af
cockroach/pkg/sql/conn_executor.go
Lines 899 to 901 in 2c1d4af
cockroach/pkg/sql/conn_executor.go
Lines 2102 to 2104 in 2c1d4af
cockroach/pkg/sql/conn_executor.go
Lines 2185 to 2187 in 2c1d4af
cockroach/pkg/sql/conn_executor.go
Lines 2180 to 2182 in 2c1d4af
cockroach/pkg/sql/conn_executor_exec.go
Lines 140 to 142 in 2c1d4af
cockroach/pkg/sql/conn_executor_exec.go
Lines 2985 to 2987 in 2c1d4af
cockroach/pkg/sql/conn_executor_exec.go
Lines 141 to 143 in 2c1d4af
cockroach/pkg/sql/conn_executor_exec.go
Lines 767 to 769 in 2c1d4af
cockroach/pkg/sql/conn_executor_exec.go
Lines 1233 to 1235 in 2c1d4af
cockroach/pkg/sql/conn_executor_exec.go
Lines 1329 to 1331 in 2c1d4af
cockroach/pkg/sql/catalog/descs/validate.go
Lines 73 to 75 in 2c1d4af
cockroach/pkg/sql/catalog/descs/validate.go
Lines 39 to 41 in 2c1d4af
cockroach/pkg/sql/catalog/internal/validate/validate.go
Lines 108 to 110 in 2c1d4af
cockroach/pkg/sql/catalog/internal/validate/validate.go
Lines 201 to 203 in 2c1d4af
cockroach/pkg/sql/catalog/internal/validate/validate.go
Lines 113 to 115 in 2c1d4af
cockroach/pkg/sql/catalog/tabledesc/validate.go
Lines 248 to 250 in 2c1d4af
cockroach/pkg/sql/catalog/tabledesc/validate.go
Lines 356 to 358 in 2c1d4af
Tags
Jira issue: CRDB-30913
The text was updated successfully, but these errors were encountered: