Skip to content

Conversation

@Hamkua
Copy link
Contributor

@Hamkua Hamkua commented Nov 13, 2025

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

Purpose

분석함수의 over 절 안에 어떠한 정렬 기준도 없는 경우, qexec_end_one_iteration () 에서 분석함수를 평가하도록 개선합니다.

Implementation

qexec_end_one_iteration 에서 분석함수를 평가할 수 있도록 수정했습니다.
qexec_execute_analytic 에서 이미 평가된 분석함수에 대해서는 정렬, 평가를 건너뛰도록 합니다.
전체 튜플을 읽을 필요가 없으면, limit 절에 명시된 만큼의 튜플을 읽고 멈출 수 있도록 개선합니다.

qexec_execute_analytic 에서 분석함수를 평가하기 위한 조건은 다음과 같습니다:

  1. limit 절 또는 rownum 조건을 포함해야 합니다.
  2. ROW_NUMBER, RANK, DENSE_RANK , IGNORE NULLS 없는 FIRST_VALUE
  3. 분석함수의 OVER 절에 PARTITION BY, ORDER BY 절이 없어야 합니다.

Remarks

N/A

@Hamkua Hamkua self-assigned this Nov 13, 2025
@Hamkua Hamkua requested a review from beyondykk9 as a code owner November 13, 2025 07:24
@Hamkua Hamkua marked this pull request as draft November 13, 2025 07:24
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@Hamkua
Copy link
Contributor Author

Hamkua commented Nov 18, 2025

/run sql medium

@Hamkua
Copy link
Contributor Author

Hamkua commented Nov 20, 2025

/run sql

@Hamkua
Copy link
Contributor Author

Hamkua commented Dec 1, 2025

/run sql

@Hamkua Hamkua marked this pull request as ready for review December 2, 2025 01:29
@chatgpt-codex-connector
Copy link

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@Hamkua
Copy link
Contributor Author

Hamkua commented Dec 2, 2025

/run all

@Hamkua
Copy link
Contributor Author

Hamkua commented Dec 3, 2025

/run sql medium

@Hamkua
Copy link
Contributor Author

Hamkua commented Dec 5, 2025

/run sql medium

return S_SUCCESS;
}

if (ev_res == V_FALSE && !(xasl->instnum_flag & XASL_INSTNUM_FLAG_SCAN_CHECK))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instnum_pred가 V_FALSE로 평가되고 XASL_INSTNUM_FLAG_SCAN_CHECK가 설정되지 않은 경우, 해당 튜플에 대해서도 분석함수를 평가해야 합니다.

이는 분석함수가 instnum 조건을 만족하지 않는 튜플을 포함하여 전체 결과 집합에 대해 평가되어야 하기 때문입니다.

select rownum() over() from t where rownum > 10 and rownum <= 20;

rownum > 10 시점부터 분석함수를 평가하는 경우, 다음과 같이 잘못된 결과가 출력됩니다.

===================================================
row_number() over ()    
1     
2     
3     
4     
5     
6     
7     
8     
9     
10     

@Hamkua
Copy link
Contributor Author

Hamkua commented Dec 8, 2025

/run all

parser_walk_tree (parser, select_node->info.query.q.select.list, mq_has_click_counter, &has_click_counter,
NULL, NULL);

if (has_click_counter)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 수정은 bug fix인가요? click counter가 있으면 REGU_VARIABLE_ANALYTIC_WINDOW을 설정하는 이유가 궁금합니다.

Copy link
Contributor Author

@Hamkua Hamkua Dec 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이전 수정사항과 관련 있습니다. 현재는 불필요하므로 fd7fe14 에서 제거했습니다.

REGU_VARIABLE_ANALYTIC_WINDOW 플래그는 분석함수 평가 결과를 담아두기 위해 사용될 a_outptr_list_interm 에 설정되며, 타입 캐스팅을 나중으로 미루는 역할을 합니다.
이 플래그가 없으면 분석함수를 평가할 때마다 타입 캐스팅이 수행되어 오버플로우가 발생하거나 쿼리 결과가 다르게 출력될 수 있습니다.

processing 단계에서 분석함수를 평가할 수 있는 경우 qexec_generate_tuple_descriptor() 의 인자로 a_outptr_list_interm을 사용하지 않고 xasl->outptr_list 를 사용하므로, 여기에도 REGU_VARIABLE_ANALYTIC_WINDOW를 설정해 주도록 했습니다.

다만, 이 문제는 SUM, AVG 처럼 값이 누적되는 분석함수에서만 발생합니다.
6020e81 에서 ROW_NUMBER, RANK, DENSE_RANK, FIRST_VALUE 로 제한했으므로, 위 코드는 제거해도 됩니다.

/* optimize analytic function list */
xasl->proc.buildlist.a_eval_list = pt_optimize_analytic_list (parser, &analytic_info, &no_optimization_done);

for (eval = xasl->proc.buildlist.a_eval_list; eval != NULL; eval = eval->next)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. is_sorted가 의미가 좀 불명확한 것 같습니다. 최적화 여부로 명명하는 게 좋아보입니다.
  2. eval마다 is_sorted를 따로 관리 해야하나요? 질의 기준으로 최적화가 된다면 비효율적인 것 같습니다.
  3. 최적화가능 여부를 함수화 하는 것이 가독성에 도움을 줄 것 같습니다.

Copy link
Contributor Author

@Hamkua Hamkua Dec 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fd7fe14 에서 수정했습니다.
1, 2. eval 마다 is_sorted를 관리할 필요가 없어 제거하였고, xasl->flag 에서 관리하도록 수정했습니다.
3. 함수로 분리했습니다.

src/query/xasl.h Outdated
QFILE_LIST_ID *push_list_id; /* file descriptor for push list */
OUTPTR_LIST *g_outptr_list; /* group_by output ptr list */
REGU_VARIABLE_LIST g_regu_list; /* group_by regu. list */
REGU_VARIABLE_LIST a_scan_regu_list;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

추가된 변수에 주석 넣어주세요. 변수의 사용 목적을 알 수 있으면 좋겠습니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fd7fe14 에서 수정했습니다.

@Hamkua
Copy link
Contributor Author

Hamkua commented Dec 11, 2025

/run sql medium

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.

2 participants