Skip to content

sql: vectorize COALESCE expressions #66015

@michae2

Description

@michae2

Continuing the campaign to vectorize all expressions, it would be great to have a vectorized implementation of CoalesceExpr. Here's a demonstration:

demo@127.0.0.1:26257/movr> EXPLAIN (VERBOSE) SELECT COALESCE(vehicle_city, start_address, end_address) FROM rides;
                                        info
-------------------------------------------------------------------------------------
  distribution: full
  vectorized: true

  • render
  │ columns: ("coalesce")
  │ estimated row count: 500
  │ render coalesce: COALESCE(vehicle_city, start_address, end_address)
  │
  └── • scan
        columns: (vehicle_city, start_address, end_address)
        estimated row count: 500 (100% of the table; stats collected 2 minutes ago)
        table: rides@primary
        spans: FULL SCAN
(13 rows)

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

demo@127.0.0.1:26257/movr> EXPLAIN (VEC, VERBOSE) SELECT COALESCE(vehicle_city, start_address, end_address) FROM rides;
                   info
-------------------------------------------
  │
  └ Node 1
    └ *colflow.BatchFlowCoordinator
      └ *colexec.Columnarizer
        └ *rowexec.noopProcessor
          └ *colexec.Materializer
            └ *colexecutils.CancelChecker
              └ *colfetcher.ColBatchScan
(8 rows)

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

If we had a vectorized CoalesceExpr we wouldn't need the wrapped rowexec.noopProcessor.

Jira issue: CRDB-7850

Metadata

Metadata

Assignees

Labels

A-sql-executionRelating to SQL execution.C-enhancementSolution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)E-starterMight be suitable for a starter project for new employees or team members.T-sql-queriesSQL Queries Team

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions