cockroachdb / cockroach

CockroachDB — the cloud native, distributed SQL database designed for high availability, effortless scale, and control over data placement.
https://www.cockroachlabs.com
Other
30.12k stars 3.81k forks source link

sql: max_row_size guardrails miss indexed virtual computed columns #69540

Open michae2 opened 3 years ago

michae2 commented 3 years ago

The new max_row_size guardrails added in https://github.com/cockroachdb/cockroach/pull/67953 and https://github.com/cockroachdb/cockroach/pull/69457 miss large rows caused by indexed virtual computed columns. This is because they only check the size of primary key rows, not secondary index rows.

Here's one way to reproduce it:

SET CLUSTER SETTING sql.guardrails.max_row_size_err = '1KiB';
CREATE TABLE t (c CHAR, d STRING DEFAULT repeat('x', 2000), INDEX (d));
CREATE TABLE t2 (c CHAR, d STRING AS (repeat(c, 2000)) VIRTUAL, INDEX (d));
INSERT INTO t (c) VALUES ('x');
INSERT INTO t2 (c) VALUES ('x');

The first insert fails but the second does not. Both should fail.

demo@127.0.0.1:26257/defaultdb> INSERT INTO t (c) VALUES ('x');
ERROR: row larger than max row size: table 53 family 0 primary key /Table/53/1/688592352786874369/0 size 2023
SQLSTATE: 54000

demo@127.0.0.1:26257/defaultdb> INSERT INTO t2 (c) VALUES ('x');
INSERT 1

Time: 4ms total (execution 4ms / network 0ms)

demo@127.0.0.1:26257/defaultdb> SELECT c, pg_column_size(d) FROM t2;
  c | pg_column_size
----+-----------------
  x |           2003
(1 row)

Time: 1ms total (execution 1ms / network 0ms)

demo@127.0.0.1:26257/defaultdb> SELECT version();
                                                          version
----------------------------------------------------------------------------------------------------------------------------
  CockroachDB CCL v21.2.0-alpha.00000000-3740-g6700cf65e8 (x86_64-apple-darwin20.6.0, built 2021/08/29 04:36:22, go1.16.6)
(1 row)

Time: 0ms total (execution 0ms / network 0ms)

Jira issue: CRDB-9646

rytaft commented 2 years ago

Should this be a known limitation? Adding the label, but feel free to remove it if not.

github-actions[bot] commented 10 months ago

We have marked this issue as stale because it has been inactive for 18 months. If this issue is still relevant, removing the stale label or adding a comment will keep it active. Otherwise, we'll close it in 10 days to keep the issue queue tidy. Thank you for your contribution to CockroachDB!