From 85b666ebd9c23814fee748ed82a4b0e1bac66ec1 Mon Sep 17 00:00:00 2001 From: Mark Sirek Date: Thu, 23 Mar 2023 08:22:56 -0700 Subject: [PATCH] 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 #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 #98322 Release note: None --- pkg/sql/randgen/type.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/sql/randgen/type.go b/pkg/sql/randgen/type.go index fd02ba64e37f..9f96d0e40081 100644 --- a/pkg/sql/randgen/type.go +++ b/pkg/sql/randgen/type.go @@ -40,6 +40,10 @@ var ( func init() { for _, typ := range types.OidToType { switch typ.Oid() { + case oid.T_regnamespace: + // Temporarily don't include this. + // TODO(msirek): Remove this exclusion once + // https://github.com/cockroachdb/cockroach/issues/55791 is fixed. case oid.T_unknown, oid.T_anyelement: // Don't include these. case oid.T_anyarray, oid.T_oidvector, oid.T_int2vector: