Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
randgen: disable generation of REGNAMESPACE type expressions
Casting an OID to REGNAMESPACE runs this SQL using the internal executor: ``` SELECT pg_namespace.oid, nspname FROM pg_catalog.pg_namespace WHERE oid = $1 ``` When the `GenerateConstrainedScans` rule is disabled, this returns no rows and so doesn't apply the cast. The same SQL, not run via an internal executor, but also with `GenerateConstrainedScans` disabled, behaves correctly. Disabling `GenerateConstrainedScans` all the time prevents the cluster from starting. The reason a full scan of pg_namespace doesn't find the OID is because it only checks for schemas in the current database: https://github.com/cockroachdb/cockroach/blob/7b341ffa678e4a22416e2274351fd56f415f5421/pkg/sql/virtual_schema.go#L602 https://github.com/cockroachdb/cockroach/blob/d10c3dd42c3dc40cad82792a30ae47fd2a663f43/pkg/sql/pg_catalog.go#L2099-L2106 https://github.com/cockroachdb/cockroach/blob/a7e9c4a68b81436d1f9382518d4267f74cbdac94/pkg/sql/information_schema.go#L2295-L2296 Whereas with a constrained scan, all descriptors are searched: https://github.com/cockroachdb/cockroach/blob/af6a72a622ae05f3733b5db637403b3eaa9455f1/pkg/sql/catalog/descs/descriptor.go#L168-L175 The correct result is from the constrained scan, because we currently allow cross-database references. Once cockroachdb#55791 is fixed, both results should match. The fix alternatives are: 1. disallow disabling of the `GenerateConstrainedScans` rule for internal SQL 2. turn off generation of REGNAMESPACE expressions in randgen to avoid hitting this problem in tests. The 2nd fix alternative is implemented to avoid losing any of the rule-disabling test coverage provided by the `testing_optimizer_disable_rule_probability` setting. Fixes cockroachdb#98322 Release note: None
- Loading branch information