pingcap / pingcap/tiflash

Support cte shared scan in TiFlash

Open
#9,785 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type/enhancement
Dominant language
C++
Stars
1k
Forks
423
Avg merge
1d 15h
Merged PRs (30d)
24

Description

Enhancement

In TiDB if a cte is used more than 1 time in query, it will generate a cte shared scan executor, so the cte itself will only be calulated once, and each reader read the result from cte shared scan.

Currently, TiDB convert cte shared scan into exchange sender/receiver in MPP mode, but exchange sender/receiver actually require that all the exchange reciver read data from the same exchange sender at the same time, and cte reader actually does not meet this requirement.
For example:

with cte as xxx
select * from cte a join cte b where a.id = b.id

In the above query, both build and probe side read from the same cte, but probe side will begin to read afte build side is done, which mean build side will read all the data from cte, after that probe side begin to read. If we change cte shared scan into exchange sender with 2 exchange receivers, the exchange sender expect 2 exchange receiver read data at the same time, if only 1 exchange receiver read data, the exchange sender will be blocked by the other exchange reciever, which will makes the query hangs forever.

So we need to redesign TiFlash support of cte shared read.

Contributor guide

No contributing guide indexed for this repository

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.

Research direction

Start by tracing how TiFlash converts CTE shared scans into exchange sender/receiver operators in MPP mode. Reproduce the query pattern described in the issue and inspect the build/probe read ordering. Done means redesigning shared CTE reading so the query does not hang when readers run sequentially and the CTE is calculated only once.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
databases, distributed-systems
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.