Skip to content

[CBRD-26524] Improving analytic function execution by reading only required rows#6901

Merged
Hamkua merged 11 commits intoCUBRID:developfrom
Hamkua:CBRD-26524
Apr 1, 2026
Merged

[CBRD-26524] Improving analytic function execution by reading only required rows#6901
Hamkua merged 11 commits intoCUBRID:developfrom
Hamkua:CBRD-26524

Conversation

@Hamkua
Copy link
Copy Markdown
Contributor

@Hamkua Hamkua commented Mar 12, 2026

http://jira.cubrid.org/browse/CBRD-26524

Purpose

큐브리드는 정렬이 필요한 분석함수가 있다면 테이블의 전체 행을 읽는 비효율이 있습니다.

인덱스를 활용하여 정렬을 생략할 수 있는 분석함수로만 구성된 쿼리는 전체 튜플을 스캔하지 않고 필요한 만큼만 스캔하도록 개선합니다.

  • LIMIT 절 또는 ROWNUM 조건을 포함해야 합니다. (where rownum < 10, limit 10)
  • 분석함수의 정렬 기준(PARTITION BY, ORDER BY) 인덱스의 선두 컬럼과 일치하여 정렬을 생략할 수 있어야 합니다.
  • a_eval_list 의 길이가 1 이어야 합니다.
    • a_eval_list : 하나의 쿼리에 여러 분석 함수가 포함된 경우, 각 함수마다 매번 정렬한다면 효율이 낮아질 것입니다. CUBRID는 이러한 비효율을 줄이기 위해 동일한 정렬 기준(SORT_LIST)으로 처리 가능한 분석 함수들을 하나의 묶음으로 관리하는데, 이 묶음의 단위가 바로 a_eval_list입니다.
    • a_eval_list의 길이가 1이라는 것은 해당 쿼리 내 모든 분석 함수가 동일한 정렬 기준을 공유하며, 단 한 번의 정렬만으로 처리가 가능한 상태임을 의미합니다.

대상 분석 함수 ( pt_check_analytic_limit_optimization() ) :

  • ROW_NUMBER()
  • RANK()
  • DENSE_RANK()
  • FIRST_VALUE() (IGNORE NULLS 제외)

Implementation

  • 정렬을 생략할 수 있고, limit 절 최적화가 가능하다면 processing 단계에서 instnum 을 평가하도록 수정

  • a_outptr_list_ex->valptrp 에 instnum 함수를 삽입할 때, 순서가 잘못되는 문제를 함께 수정

Remarks

N/A

@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Mar 12, 2026

Last reviewed commit: 226bc5c

Comment thread src/parser/xasl_generation.c
Comment thread src/query/query_executor.c Outdated
@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Mar 12, 2026

Last reviewed commit: dc48ba5

Comment thread src/query/query_executor.c Outdated
@Hamkua
Copy link
Copy Markdown
Contributor Author

Hamkua commented Mar 16, 2026

/run sql medium

@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Mar 17, 2026

Last reviewed commit: c8bf449

Comment thread src/parser/xasl_generation.c
@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Mar 18, 2026

Last reviewed commit: "코드 리뷰 반영"

Comment thread src/parser/xasl_generation.c
Comment thread src/query/query_executor.c
Comment thread src/query/query_executor.c Outdated
Comment thread src/query/query_dump.c Outdated
Comment thread src/query/query_executor.c Outdated
@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Mar 24, 2026

Reviews (5): Last reviewed commit: "Merge branch 'CUBRID:develop' into CBRD-..." | Re-trigger Greptile

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Mar 27, 2026

Reviews (9): Last reviewed commit: "Merge remote-tracking branch 'upstream/d..." | Re-trigger Greptile

@Hamkua
Copy link
Copy Markdown
Contributor Author

Hamkua commented Mar 30, 2026

/run all

@Hamkua
Copy link
Copy Markdown
Contributor Author

Hamkua commented Apr 1, 2026

/run all

@Hamkua Hamkua closed this Apr 1, 2026
@Hamkua Hamkua reopened this Apr 1, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 1, 2026

🗑️ TC Branch Finalized for cubrid-testcases

Engine PR was closed (not merged).

Cleanup Results:

TC base branch is ready for the next PR.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 1, 2026

🗑️ TC Branch Finalized for cubrid-testcases-private-ex

Engine PR was closed (not merged).

Cleanup Results:

TC base branch is ready for the next PR.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 1, 2026

🧪 TC Test Environment Ready

CircleCI Testing:

  • CircleCI will automatically test using the branches below.

TC Repositories & Branches:

Next Steps:

  1. Wait for CircleCI tests to complete
  2. If CircleCI tests failed, please check the test results and fix the issues.
  3. When ready to merge this PR, please merge the TC PR first, then merge this PR.

@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Apr 1, 2026

Reviews (10): Last reviewed commit: "Merge remote-tracking branch 'upstream/d..." | Re-trigger Greptile

@Hamkua
Copy link
Copy Markdown
Contributor Author

Hamkua commented Apr 1, 2026

/run all

@Hamkua Hamkua merged commit f868d03 into CUBRID:develop Apr 1, 2026
25 checks passed
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 1, 2026

TC Branch Finalized for cubrid-testcases

Engine PR was merged.

Cleanup Results:

TC base branch is ready for the next PR.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 1, 2026

TC Branch Finalized for cubrid-testcases-private-ex

Engine PR was merged.

Cleanup Results:

TC base branch is ready for the next PR.

hyunikn added a commit to hyunikn/cubrid that referenced this pull request Apr 1, 2026
hyunikn added a commit to hyunikn/cubrid that referenced this pull request Apr 1, 2026
hgryoo pushed a commit to cubrid-systems/cubrid that referenced this pull request Apr 8, 2026
…quired rows (CUBRID#6901)

http://jira.cubrid.org/browse/CBRD-26524

Improve index-based sort queries to scan only the necessary amount of tuples.
This optimization applies when the query's analytic functions consist only of:
- ROW_NUMBER()
- RANK()
- DENSE_RANK()
- FIRST_VALUE() (excluding IGNORE NULLS)
H2SU pushed a commit to H2SU/cubrid that referenced this pull request Apr 13, 2026
…quired rows (CUBRID#6901)

http://jira.cubrid.org/browse/CBRD-26524

Improve index-based sort queries to scan only the necessary amount of tuples.
This optimization applies when the query's analytic functions consist only of:
- ROW_NUMBER()
- RANK()
- DENSE_RANK()
- FIRST_VALUE() (excluding IGNORE NULLS)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants