TXSQL count(expr)优化

Open
#49 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
52/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Quiet
Tech stack
cpp, sql

Research direction

Start by tracing count(expr) handling through the SQL engine's Item nullable and is_null checks, then follow how the storage engine converts columns into TABLE::record[0]. Verify the behavior for a NOT NULL column outside the inner side of a LEFT JOIN, and compare it with count(*) or count(0). Done means the eligible query path avoids the column conversion overhead and reproduces the reported performance improvement.

Written by the indexing model from the issue text.

Description

在TXSQL中,count star会转换为count(0),count star、count(0)、count(1)等价,表示计数时包含null值。而count(col)则不包含null值。
在存储引擎,count(col)需要转换col列到TABLE::record[0]中,因此存在格式转换开销。而count(0)不存在额外需要拷贝的列。
在SQL engine,通过Item判断nullable属性以及is_null属性。

如果count(expr)中的expr能够在优化阶段提前确定绝对不会为null,比如count(t.col),t不是left join内表,同时col定义为not null。此时
count(expr)实际可以转换为count star,从而也当作count(0)处理。从而可以减少格式转换开销。

下面是一个简单的测试:其中l_shipdate列定义为not null,而格式转换开销的消除使得查询变快了15%+。
Image

Dominant language
C++
Stars
712
Forks
428
Avg merge
5h 43m
Merged PRs (30d)
1

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from OpenTenBase/TXSQL

All issues in OpenTenBase/TXSQL

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.