cockroach icon indicating copy to clipboard operation
cockroach copied to clipboard

opt: simplify lock over norows to norows

Open michae2 opened this issue 1 year ago • 0 comments

With the new SFU implementation (optimizer_use_lock_op_for_serializable) we now simplify cardinality=0 input to norows, but we still add the lock on top. We should be able to simplify this to norows. Here's the example from https://github.com/cockroachdb/cockroach/issues/73074:

[email protected]:26257/demoapp/defaultdb> CREATE TABLE oracle (a INT PRIMARY KEY);
CREATE TABLE

Time: 3ms total (execution 3ms / network 0ms)

[email protected]:26257/demoapp/defaultdb> EXPLAIN SELECT * FROM oracle WHERE a = 1 AND a = 2;
         info
-----------------------
  distribution: local
  vectorized: true

  • norows
(4 rows)

Time: 7ms total (execution 7ms / network 0ms)

[email protected]:26257/demoapp/defaultdb> SET optimizer_use_lock_op_for_serializable = true;
SET

Time: 1ms total (execution 0ms / network 0ms)

[email protected]:26257/demoapp/defaultdb> EXPLAIN SELECT * FROM oracle WHERE a = 1 AND a = 2 FOR UPDATE;
               info
----------------------------------
  distribution: local
  vectorized: true

  • lookup join (semi)
  │ estimated row count: 0
  │ table: oracle@oracle_pkey
  │ equality: (a) = (a)
  │ equality cols are key
  │ locking strength: for update
  │
  └── • norows
(11 rows)

Time: 1ms total (execution 1ms / network 0ms)

[email protected]:26257/demoapp/defaultdb> EXPLAIN (opt, verbose) SELECT * FROM oracle WHERE a = 1 AND a = 2 FOR UPDATE;
                info
------------------------------------
  lock oracle
   ├── columns: a:1
   ├── locking: for-update
   ├── cardinality: [0 - 0]
   ├── volatile, mutations
   ├── stats: [rows=0]
   ├── cost: 0.02
   ├── key: ()
   ├── fd: ()-->(1)
   ├── distribution: us-east1
   └── values
        ├── columns: a:1
        ├── cardinality: [0 - 0]
        ├── stats: [rows=0]
        ├── cost: 0.01
        ├── key: ()
        ├── fd: ()-->(1)
        └── distribution: us-east1
(18 rows)

Time: 2ms total (execution 1ms / network 0ms)

Jira issue: CRDB-33662 Epic: CRDB-34172

michae2 avatar Nov 20 '23 20:11 michae2