Skip to content

[CBRD-27246] Improve value transfer for domain-matching values - #7717

Draft
youngjinj wants to merge 2 commits into
CUBRID:developfrom
youngjinj:CBRD-27246
Draft

youngjinj wants to merge 2 commits into
CUBRID:developfrom
youngjinj:CBRD-27246

Conversation

@youngjinj

@youngjinj youngjinj commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

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

Purpose

heap_attrinfo_set 이 값마다 범용 절차를 전부 거친다. 표 조회, 대상 초기화, 도메인 대조, 함수 포인터 호출이 값이 이미 컬럼과 맞는 흔한 경우에도 그대로 난다. 타입이 맞는 값은 구조체 복사로 넘긴다.

Implementation

  • 컬럼 위치를 찾은 직후 값싼 직접 비교로 판정하고, 통과하면 구조체를 복사한 뒤 HEAP_WRITTEN_ATTRVALUE 로 표시하고 돌아간다. 어긋나면 기존 절차로 간다.
  • 대상은 고정폭 수치형과 CHAR·VARCHAR 다. 문자셋·정렬 규칙이 같고 is_max_string 이 아니어야 한다. NULL, 집합, LOB, 타입이 다른 값은 기존 절차를 그대로 거친다.
  • 길이 판정은 바이트 수를 먼저 본다. 글자 수는 바이트 수를 넘을 수 없으므로 바이트 수가 정밀도 이하면 확정이고, 넘을 때만 글자 수를 센다.
  • 복사한 값에 컬럼 정밀도를 찍는다. 형변환이 남겼을 값과 같게 만든다.

Remarks

  • need_clearfalse 로 명시해 해제 책임을 원본에 남긴다. 기존 절차도 비집합 타입은 setvalcopy == false 로 부르므로 소유 관계가 달라지지 않는다.
  • CHAR 의 공백 채우기는 값을 앉히는 시점이 아니라 mr_lengthval_char_internalmr_writeval_char_internal 이 쓰는 시점에 한다. 그 채우기가 값이 든 정밀도를 기준으로 하므로 위의 정밀도 도장이 CHAR 에서는 데이터 정합성 문제다. 없으면 정밀도가 -1 로 남아 채우기가 통째로 건너뛰어진다.
  • 앉힌 값과 레코드로 굽는 시점 사이에 그 값을 읽는 곳이 없다. 인덱스 키는 구워진 레코드에서 다시 읽고 REPLACE 는 자기 레코드를 먼저 굽는다.
  • 기존 절차를 지우지 않는다. 진입 조건이 TP_EXACT_MATCH 가 통과했을 조건과 같은 항목을 직접 비교하고, 하나라도 어긋나면 원래 코드가 그대로 실행된다. 다른 점은 정밀도를 더 넓게 본다는 것뿐이고, 그 차이는 컬럼 정밀도를 찍어 메운다.

youngjinj and others added 2 commits August 14, 2026 08:56
heap_attrinfo_set runs the full generic pipeline for every value of
every row -- attrvalue locate, type table lookup, domain re-init,
tp_domain_check, setval dispatch --
although the verdict is the same for every row of a multi-row INSERT.
A value that already fits the column domain is now handed over by
struct copy after the per-row guards (NULL, string length, codeset,
collation);
anything else keeps the generic path, so coercion and error semantics
are unchanged.
The slow path passes strings by reference as well (setval with
copy == false), so the shallow copy does not change ownership, and the
copy carries the column's precision the way the coercion would.

Precision counts characters, so byte size alone would exclude a
multi-byte value that fills the column; the character count is asked
for only when byte size does not already settle it, which is the case
the generic path would count as well.

Marginal cost per value drops from 0.77us to 0.40us
(1-column vs 9-column INSERT..SELECT scaling, 400k rows).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
CHAR was left out of the shortcut because the column keeps trailing-space
padding, and a struct copy does not pad. But the padding does not happen
when the value is placed -- it happens on the way out, in
mr_lengthval_char_internal and mr_writeval_char_internal, and it is keyed
off the precision the value carries.

So the shortcut only has to stamp the column precision, which it already
does for VARCHAR. Without the stamp the precision stays floating, which is
how both a literal and a bound value arrive, and the padding block is
skipped entirely -- for CHAR that stamp is data correctness, not display
consistency.

Nothing reads the value between heap_attrinfo_set and
heap_attrinfo_transform_to_disk: index keys are read back from the built
record, and REPLACE builds its own record first. So handing the value over
still unpadded is not observable.

heap_attrinfo_set drops from 0.78% to 0.22% of server samples on a bound
CHAR(120) + CHAR(60) insert, matching what VARCHAR already cost, and the
coercion symbols leave the profile.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

✅ TC Merge Gate — Merge Allowed

All TC PRs are merged, closed, or not present.

TC Repositories & Branches:

  • cubrid-testcases: No open TC PR (merged, closed, or not created)
  • cubrid-testcases-private-ex: No open TC PR (merged, closed, or not created)

@github-actions

github-actions Bot commented Aug 14, 2026

Copy link
Copy Markdown

🧪 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.

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.

1 participant