Skip to content

[CBRD-27826] [Backport-11.0.17] Coerce an empty or whitespace-only string to NUMERIC 0, the same as the other numeric types - #8331

Merged
jongmin-won merged 5 commits into
CUBRID:release/11.0from
jongmin-won:11.0.17-CBRD-27826
Oct 30, 2026
Merged

jongmin-won merged 5 commits into
CUBRID:release/11.0from
jongmin-won:11.0.17-CBRD-27826

Conversation

@jongmin-won

@jongmin-won jongmin-won commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

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

Backport of #8326 to 11.0.17. (엔진 C 코드만 해당, 11.0에는 PL/CSQL이 없어 Java 변경 없음)

Purpose

  • CBRD-26749에서 NUMERIC 문자열 변환 검증을 강화하면서, 빈 문자열('')과 공백만 있는 문자열(' ')도 에러로 바뀌었습니다.
  • 다른 숫자 타입(SMALLINT, INT, FLOAT, DOUBLE, MONETARY)은 같은 입력을 0으로 변환하고, NUMERIC도 26749 이전에는 NULL로 저장됐습니다.
  • 그래서 26749가 적용된 버전으로 올린 사이트에서 기존에 성공하던 INSERT가 실패합니다. (SUPPORT-1206)
  • NUMERIC도 다른 숫자 타입처럼 0으로 변환하고, 26749 이전 동작(NULL)이 필요한 사이트를 위해 히든 파라미터를 추가합니다.

Implementation

  1. numeric_coerce_string_to_num ()

    • 숫자가 하나도 없는 문자열 중 부호도 소수점도 없는 경우('', ' ')를 나머지와 분리했습니다.
    • 기본은 0, numeric_empty_string_as_null = yes이면 NULL입니다.
    • 0 패딩 문자열('0', '000')은 파라미터와 관계없이 지금처럼 0입니다.
    • 그 밖에 숫자가 없는 문자열('+', '-', '.', '+.')은 지금처럼 에러입니다.
  2. 히든 파라미터 numeric_empty_string_as_null 추가 (bool, 기본값 no)

    • 플래그: PRM_FOR_SERVER | PRM_FOR_CLIENT | PRM_FOR_QRY_STRING | PRM_HIDDEN
      • PRM_FOR_QRY_STRING: 값이 기본값과 다르면 XASL 캐시 키에 들어가, 값이 다른 클라이언트끼리 캐시된 플랜(상수 계산 결과 포함)을 공유하지 않습니다. (oracle_style_empty_string과 같음)
    • cubrid.conf에 설정하고 재시작해야 적용됩니다. (SET SYSTEM PARAMETERS로 변경 불가)
    • 클라이언트(CAS, csql)와 서버가 각자 자기 cubrid.conf에서 읽습니다.
      • 클라이언트의 상수 계산·바인드 변환과 서버의 실행 중 변환이 같은 값을 쓰도록, 브로커를 별도 호스트에 둔 경우에는 양쪽 conf에 같은 값을 설정해야 합니다.
    • PRM_FORCE_SERVER(접속 시 서버 값을 클라이언트에 전달)는 쓰지 않습니다.
      • 서버는 이 플래그가 붙은 파라미터를 ID로 보내고 클라이언트는 그 ID로 자기 파라미터 배열을 바로 찾기 때문에, 이 패치가 없는 11.0 클라이언트가 패치된 서버에 접속하면 배열 범위를 벗어납니다.

Result

drop table if exists t1;
create table t1 (c_int int, c_double double, c_num numeric(15,0));

insert into t1 values ('', '', '');
insert into t1 values ('   ', '   ', '   ');

select * from t1;

Before

oracle_style_empty_string 입력 c_int c_double c_num
no '' 0 0 에러 (Cannot coerce '' to type numeric.)
no ' ' 0 0 에러
yes '' NULL NULL NULL
yes ' ' 0 0 에러

c_num 변환이 실패한 행은 INSERT 전체가 실패해서 저장되지 않습니다.

After

oracle_style_empty_string numeric_empty_string_as_null 입력 c_int c_double c_num
no no '' 0 0 0
no no ' ' 0 0 0
yes no '' NULL NULL NULL
yes no ' ' 0 0 0
no yes '' 0 0 NULL
no yes ' ' 0 0 NULL
yes yes '' NULL NULL NULL
yes yes ' ' 0 0 NULL

리터럴, 바인드, CAST, UPDATE, NUMERIC(p,s), 정밀도 없는 NUMERIC 모두 같은 결과입니다. (11.0 release 빌드, SA로 확인)

Remarks

numeric_empty_string_as_null = yes로 설정할 때

  • ''와 공백 문자열만 26749 이전처럼 NULL이 됩니다.
    • 26749 이전에 함께 NULL이던 '+', '-', '.'은 계속 에러입니다.
  • ''·공백 문자열은 변환 후에야 NULL이 되므로, 변환 전 값으로 NULL을 판단하던 아래 경우를 함께 처리했습니다. (26749 이전부터 있던 결함)
    • INSERT ... SELECT, UPDATE ... SET n = (SELECT ...), ON DUPLICATE KEY UPDATE, REPLACE로 NOT NULL·PK 컬럼에 넣으면 NULL이 저장되던 것을 NOT NULL 위반 에러로 막습니다. (heap_attrinfo_set ())
      • return_null_on_function_errors=yes에서 변환에 실패해 NULL이 된 값도 같은 경로라 함께 막힙니다. (타입 무관)
    • 다중 컬럼 인덱스 검색 키로 쓰이면 debug 빌드가 assert로 종료되던 것을, NULL 키와 같이 맞는 행 없음으로 처리합니다. (scan_dbvals_to_midxkey ())
    • ALTER TABLE ... MODIFY로 문자열 컬럼을 NUMERIC으로 바꾸면 debug 빌드가 assert로 종료되던 것을 막습니다. (heap_object_upgrade_domain ())
      • ''·공백 행은 26749 이전처럼 NULL이 됩니다. NOT NULL 컬럼이면 변환 실패와 같이 alter_table_change_type_strict=yes에서는 에러, no에서는 타입 기본값(0)입니다. (원래 NOT NULL인 컬럼 포함)
  • 이 파라미터가 없는 이전 빌드로 되돌릴 때는 cubrid.conf에서 이 줄을 지워야 합니다.
    • 모르는 파라미터는 에러라 서버와 클라이언트가 시작되지 않습니다.
  • 저장된 값은 저장할 때의 결과를 유지합니다.
    • 파라미터 값을 바꿔도 다시 계산되지 않습니다.
    • NUMERIC 컬럼의 DEFAULT '' (DDL 시점에 변환되어 저장)

바뀌지 않는 것

  • oracle_style_empty_string = yes이면 ''는 변환 전에 NULL이 되므로 모든 숫자 타입이 NULL입니다.
  • TO_NUMBER(''), TO_NUMBER(' ')는 자체 형식 해석을 거쳐 지금처럼 에러입니다. (9.3부터 같음)
  • 11.0의 BIGINT는 '', ' '를 0으로 바꾸지 않고 에러를 냅니다. 11.0의 기존 동작이며 이번 범위가 아닙니다. (11.4는 0)

jongmin-won and others added 3 commits October 29, 2026 17:22
…the same as the other numeric types

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

CBRD-26749 made an empty string ('') and a whitespace-only string ('   ')
an error when coerced to NUMERIC, while the other numeric types coerce them
to 0 and NUMERIC itself stored NULL before CBRD-26749 (SUPPORT-1206).

- Coerce them to NUMERIC 0 in numeric_coerce_string_to_num ().
- Add hidden parameter numeric_empty_string_as_null (default no, applied on
  restart); yes coerces them to NULL as before CBRD-26749.

A zero-padded string ('000') stays 0, and the other strings without a digit
('+', '-', '.') stay an error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…added NUMERIC string

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

When no digit is found, fill num_string with a single '0' and let it take the
common terminator and conversion, instead of building 0 in two branches.
No change in behavior.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ull parameter

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

- Drop PRM_FORCE_SERVER. The server sends every FORCE_SERVER parameter to a
  connecting client by id, and a client without this parameter would index
  past its parameter table. Client and server now read their own
  cubrid.conf, and PRM_FOR_QRY_STRING keeps clients with different values
  from sharing a cached plan.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jongmin-won jongmin-won self-assigned this Oct 29, 2026
@jongmin-won
jongmin-won marked this pull request as ready for review October 29, 2026 11:37
@jongmin-won jongmin-won changed the title [CBRD-27826] [Backport-11.0.17] Coerce an empty or whitespace-only string to NUMERIC 0, the same as the other numeric types- #8326 [CBRD-27826] [Backport-11.0.17] Coerce an empty or whitespace-only string to NUMERIC 0, the same as the other numeric types Oct 29, 2026
@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in Greptile

[Medium impact] The change reaches shared string-to-numeric conversion paths.

C API에서도 새 NULL 변환 설정이 동작하도록 수정한 뒤 병합해야 합니다.

Reviews (1) · Last reviewed commit: "[CBRD-27826] Drop PRM_FORCE_SERVER from ..." · Reviewed by Greptile

Comment thread src/query/numeric_opfunc.c Resolved
jongmin-won and others added 2 commits October 30, 2026 14:55
…he coercion

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

With numeric_empty_string_as_null=yes, '' and a whitespace-only string are
NULL as NUMERIC only after the coercion, after the checks that assume a
non-NULL value stays non-NULL. Handle that NULL where the coercion happens.

- heap_attrinfo_set (): a non-NULL value that is NULL after the coercion to a
  NOT NULL attribute is a NOT NULL violation. INSERT ... SELECT, UPDATE with
  a subquery, ON DUPLICATE KEY UPDATE and REPLACE checked the constraint
  before the coercion and stored NULL, also into a primary key.
- scan_dbvals_to_midxkey (): a key value that is NULL after the coercion
  matches no row, the same as a NULL key value. A multi-column index scan
  with such a value hit an assertion.
- heap_object_upgrade_domain (): allow this NULL in the assertion when
  ALTER changes a string attribute to NUMERIC. ALTER to NOT NULL is
  rejected by the existing check after the upgrade.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n attribute already NOT NULL in ALTER

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

- heap_object_upgrade_domain (): ALTER checks existing NULL values only when
  NOT NULL is newly added, so an attribute already NOT NULL stored NULL when
  '' became NULL as NUMERIC with numeric_empty_string_as_null. Treat it as a
  conversion failure: an error with alter_table_change_type_strict, and the
  default value of the domain otherwise.
- heap_attrinfo_set (): drop the always-true !DB_IS_NULL (attr_val), and note
  that a failed coercion with return_null_on_function_errors is also NULL.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jongmin-won
jongmin-won merged commit 139b149 into CUBRID:release/11.0 Oct 30, 2026
7 checks passed
@jongmin-won
jongmin-won deleted the 11.0.17-CBRD-27826 branch October 30, 2026 08:51
jongmin-won added a commit that referenced this pull request Nov 19, 2026
…ing to NUMERIC 0, the same as the other numeric types (#8421)

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

Backport of #8326 (11.4) to 11.3.7, the same change as #8331 (11.0).
11.3 has no PL/CSQL, so only the engine C code is changed.

CBRD-26749 made an empty string ('') and a whitespace-only string ('   ')
an error when coerced to NUMERIC, while the other numeric types coerce them
to 0 and NUMERIC itself stored NULL before CBRD-26749 (SUPPORT-1206).

- Coerce them to NUMERIC 0 in numeric_coerce_string_to_num (). A zero-padded
  string ('000') stays 0, and a string without a digit ('+', '-', '.') stays
  an error.
- Add the hidden parameter numeric_empty_string_as_null (default no, applied
  on restart). With yes, they are NULL as before CBRD-26749.
- With the parameter, the NULL appears only after the coercion. Handle it
  where the coercion happens:
  - heap_attrinfo_set (): a NULL into a NOT NULL attribute is a NOT NULL
    violation. INSERT ... SELECT, UPDATE with a subquery, ON DUPLICATE KEY
    UPDATE and REPLACE stored NULL, also into a primary key. A failed
    coercion with return_null_on_function_errors is caught as well.
  - scan_dbvals_to_midxkey (): a NULL key value matches no row, instead of
    an assertion on a multi-column index scan.
  - heap_object_upgrade_domain (): ALTER to NUMERIC keeps the NULL. For an
    attribute already NOT NULL, it is a conversion failure: an error with
    alter_table_change_type_strict, and the default value otherwise.
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