New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Varchar computed column length stores incorrect and invalid values for field [CORE5857] #6117
Comments
Modified by: @mrotteveeldescription: When creating a computed column, the wrong values are stored in RDB$FIELDS for RDB$FIELD_LENGTH, RDB$CHARACTER_SET_ID (and possibly RDB$COLLATION_ID). This produces an invalid length, and applies the wrong character set. Reproduction (in a database with UTF8 as default characte set): CREATE TABLE TEST_COLUMN_METADATA ( RDB$FIELDS for these columns have For col_varchar_generated, RDB$FIELD_LENGTH = -2 which will likely break any tools that uses the length, and RDB$CHARACTER_SET_ID = 0 (NONE) instead of the expected values of 400 (length) and 4 (character set). In Firebird 3.0.3, this works as expected. => When creating a computed column, the wrong values are stored in RDB$FIELDS for RDB$FIELD_LENGTH, RDB$CHARACTER_SET_ID (and possibly RDB$COLLATION_ID). This produces an invalid length, and applies the wrong character set. Reproduction (in a database with UTF8 as default characte set): CREATE TABLE TEST_COLUMN_METADATA ( RDB$FIELDS for these columns have For col_varchar_default_user and col_varchar_default_literal: For col_varchar_generated: In Firebird 3.0.3, this works as expected. |
Commented by: @mrotteveel When selecting values, the column is described as having length 32765. |
Modified by: @mrotteveeldescription: When creating a computed column, the wrong values are stored in RDB$FIELDS for RDB$FIELD_LENGTH, RDB$CHARACTER_SET_ID (and possibly RDB$COLLATION_ID). This produces an invalid length, and applies the wrong character set. Reproduction (in a database with UTF8 as default characte set): CREATE TABLE TEST_COLUMN_METADATA ( RDB$FIELDS for these columns have For col_varchar_default_user and col_varchar_default_literal: For col_varchar_generated: In Firebird 3.0.3, this works as expected. => When creating a computed column, the wrong values are stored in RDB$FIELDS for RDB$FIELD_LENGTH, RDB$CHARACTER_SET_ID (and possibly RDB$COLLATION_ID). This produces an invalid length, and applies the wrong character set. Reproduction (in a database with UTF8 as default characte set): CREATE TABLE TEST_COLUMN_METADATA ( RDB$FIELDS for these columns have For col_varchar_default_user and col_varchar_default_literal: For col_varchar_generated: In Firebird 3.0.3, this works as expected. As an additional note, it would probably be better to expect a value of 804 for the length to account for the space added in the expression), but that doesn't match with the RDB$CHARACTER_LENGTH column that reports 200 (and not 201). A better fix would take that into account as well. If this is the result of a change that allows for a wider width for computed varchars, then I'd strongly suggest not to use negative values here, and the RDB$CHARACTER_LENGTH should also get a value that is more in line with the length. |
Commented by: @asfernandes The bug was temporary in not officially released kit, so I'm marking as cannot reproduce. |
Commented by: @pavel-zotov Consider script (adjust path and DB file name for your env.):set names utf8; recreate table test ( insert into test values(1, 'австралия', 'антарктида'); set list on; set count on; Last statement will finish with error: Statement failed, SQLSTATE = 22001 (checked in WI-V3.0.4.33000 and WI-T4.0.0.1040, on Win32; also in LI-T4.0.0.940 on CentOS 6.9 ) |
Commented by: @pavel-zotov BTW, if we comment 'default character set utf8' in 'CREATE DATABASE ...' (and thus it will be NONE) then no record can be obtained from table: select * from test where id = 1; Statement failed, SQLSTATE = 22001 This maybe because of: RDB$FIELD_NAME VC_GENERATED Could engine define proper character set of computed field ( "vc_generated" ) from columns which are referenced in its definition ? |
Modified by: @pavel-zotovstatus: Resolved [ 5 ] => Resolved [ 5 ] QA Status: No test => Done with caveats Test Details: See test code: temply disabled "select vc_generated from test where id = 2; " |
Modified by: @pcisarstatus: Resolved [ 5 ] => Closed [ 6 ] |
Commented by: @asfernandes Pavel, you pointed correct results. If one does not known what is doing, just let the type to be calculated automatically. |
Commented by: @mrotteveel Sorry about 200 vs 201 confusion, I forgot that I explicitly specified the type to avoid another issue. I have now reported that issues as CORE5862. |
Submitted by: @mrotteveel
When creating a computed column, the wrong values are stored in RDB$FIELDS for RDB$FIELD_LENGTH, RDB$CHARACTER_SET_ID (and possibly RDB$COLLATION_ID). This produces an invalid length, and applies the wrong character set.
Reproduction (in a database with UTF8 as default characte set):
CREATE TABLE TEST_COLUMN_METADATA (
col_varchar_default_user VARCHAR(100) DEFAULT USER,
col_varchar_default_literal VARCHAR(100) DEFAULT 'literal',
col_varchar_generated VARCHAR(200) COMPUTED BY (col_varchar_default_user || ' ' || col_varchar_default_literal)
)
RDB$FIELDS for these columns have
For col_varchar_default_user and col_varchar_default_literal:
RDB$FIELD_LENGTH = 400 and RDB$CHARACTER_SET_ID = 4
For col_varchar_generated:
RDB$FIELD_LENGTH = -2 which will likely break any tools that uses the length, and RDB$CHARACTER_SET_ID = 0 (NONE) instead of the expected values of 800 (length) and 4 (character set).
In Firebird 3.0.3, this works as expected.
As an additional note, it would probably be better to expect a value of 804 for the length to account for the space added in the expression), but that doesn't match with the RDB$CHARACTER_LENGTH column that reports 200 (and not 201). A better fix would take that into account as well.
If this is the result of a change that allows for a wider width for computed varchars, then I'd strongly suggest not to use negative values here, and the RDB$CHARACTER_LENGTH should also get a value that is more in line with the length.
====== Test Details ======
See test code: temply disabled "select vc_generated from test where id = 2; "
The text was updated successfully, but these errors were encountered: