Skip to content
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

sql: oom in ilike operator due to huge operand #89749

Closed
cockroach-teamcity opened this issue Oct 11, 2022 · 8 comments
Closed

sql: oom in ilike operator due to huge operand #89749

cockroach-teamcity opened this issue Oct 11, 2022 · 8 comments
Assignees
Labels
branch-release-22.2 Used to mark GA and release blockers, technical advisories, and bugs for 22.2 C-test-failure Broken test (automatically or manually discovered). O-roachtest O-robot Originated from a bot. T-sql-queries SQL Queries Team
Milestone

Comments

@cockroach-teamcity
Copy link
Member

cockroach-teamcity commented Oct 11, 2022

roachtest.unoptimized-query-oracle/disable-rules=half failed with artifacts on release-22.2 @ 2c1f4db5d31e18a718b974f992701dfee9a8cdd8:

test artifacts and logs in: /artifacts/unoptimized-query-oracle/disable-rules=half/run_1
	query_comparison_util.go:237,query_comparison_util.go:66,unoptimized_query_oracle.go:54,test_runner.go:930: failed to set random seed. 31565 statements run: dial tcp 35.231.144.250:26257: connect: connection refused
		(1) attached stack trace
		  -- stack trace:
		  | github.com/cockroachdb/cockroach/pkg/cmd/roachtest/tests.(*queryComparisonHelper).makeError
		  | 	github.com/cockroachdb/cockroach/pkg/cmd/roachtest/tests/query_comparison_util.go:345
		  | github.com/cockroachdb/cockroach/pkg/cmd/roachtest/tests.runUnoptimizedQueryOracleImpl
		  | 	github.com/cockroachdb/cockroach/pkg/cmd/roachtest/tests/unoptimized_query_oracle.go:102
		  | github.com/cockroachdb/cockroach/pkg/cmd/roachtest/tests.registerUnoptimizedQueryOracle.func1.1
		  | 	github.com/cockroachdb/cockroach/pkg/cmd/roachtest/tests/unoptimized_query_oracle.go:57
		  | github.com/cockroachdb/cockroach/pkg/cmd/roachtest/tests.runOneRoundQueryComparison
		  | 	github.com/cockroachdb/cockroach/pkg/cmd/roachtest/tests/query_comparison_util.go:236
		  | github.com/cockroachdb/cockroach/pkg/cmd/roachtest/tests.runQueryComparison
		  | 	github.com/cockroachdb/cockroach/pkg/cmd/roachtest/tests/query_comparison_util.go:66
		  | github.com/cockroachdb/cockroach/pkg/cmd/roachtest/tests.registerUnoptimizedQueryOracle.func1
		  | 	github.com/cockroachdb/cockroach/pkg/cmd/roachtest/tests/unoptimized_query_oracle.go:54
		  | main.(*testRunner).runTest.func2
		  | 	main/pkg/cmd/roachtest/test_runner.go:930
		  | runtime.goexit
		  | 	GOROOT/src/runtime/asm_amd64.s:1594
		Wraps: (2) failed to set random seed. 31565 statements run
		Wraps: (3) dial tcp 35.231.144.250:26257
		Wraps: (4) connect
		Wraps: (5) connection refused
		Error types: (1) *withstack.withStack (2) *errutil.withPrefix (3) *net.OpError (4) *os.SyscallError (5) syscall.Errno

Parameters: ROACHTEST_cloud=gce , ROACHTEST_cpu=4 , ROACHTEST_encrypted=false , ROACHTEST_ssd=0

Help

See: roachtest README

See: How To Investigate (internal)

Same failure on other branches

/cc @cockroachdb/sql-queries

This test on roachdash | Improve this report!

Jira issue: CRDB-20416

@cockroach-teamcity cockroach-teamcity added branch-release-22.2 Used to mark GA and release blockers, technical advisories, and bugs for 22.2 C-test-failure Broken test (automatically or manually discovered). O-roachtest O-robot Originated from a bot. labels Oct 11, 2022
@cockroach-teamcity cockroach-teamcity added this to the 22.2 milestone Oct 11, 2022
@blathers-crl blathers-crl bot added the T-sql-queries SQL Queries Team label Oct 11, 2022
@msirek
Copy link
Contributor

msirek commented Oct 11, 2022

Reproduction:

CREATE TABLE table11 (
      col1_0 INT4 NULL,
      col1_1 OID NULL
);

insert into table11 values (616853617, NULL);

SELECT
        '':::VOID AS col_84422
FROM
        defaultdb.public.table11 AS tab_40339
WHERE
        'a ':::STRING ILIKE rpad('a':::STRING::STRING, tab_40339.col1_0::INT8)::STRING;

ERROR: rpad(): requested length too large, exceeds 128 MiB
SQLSTATE: 54000

@msirek
Copy link
Contributor

msirek commented Oct 11, 2022

@michae2 Let me know if you think the work you're planning to make query-oracle tests not halt when one of the statements errors would cover this issue? The erroring query in this case is only executed once, so I don't know if what you're planning would help this case.

@michae2
Copy link
Collaborator

michae2 commented Oct 12, 2022

Something strange is happening here. From dmesg.txt:

[ 5832.847028] oom_reaper: reaped process 29407 (cockroach), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB

So this was an OOM. I haven't been able to reproduce the OOM (or high memory usage) yet.

@michae2
Copy link
Collaborator

michae2 commented Oct 13, 2022

Ok, here's a repro of the OOM:

CREATE TABLE t (i) AS SELECT 82610433;
SELECT * FROM t WHERE 'a' ILIKE rpad('a', i);

This uses something like 13 GiB on my laptop. The problem is that 82610433 is below the rpad limit (128 MiB) but still way too high to compile into a regex for ILIKE. I think we need some more conservative limit on ILIKE and LIKE (or lower down, in the regex cache).

@michae2 michae2 assigned michae2 and unassigned msirek Oct 13, 2022
@michae2 michae2 changed the title roachtest: unoptimized-query-oracle/disable-rules=half failed sql: oom in ilike operator due to huge operand Oct 13, 2022
@michae2
Copy link
Collaborator

michae2 commented Oct 13, 2022

#89617 is the same but with lpad and !~ instead of rpad and ILIKE.

@mgartner
Copy link
Collaborator

In the case where there are no wildcard characters (% and _) on the RHS of the ILIKE, I think we can avoid compiling a regex altogether.

Even with the wildcards, there's some solution with reasonable space/time complexity because Postgres manages:

marcus=# CREATE TABLE t (i) AS SELECT 82610433;
SELECT 1

marcus=# SELECT * FROM t WHERE 'a' ILIKE rpad('%', i);
 i
---
(0 rows)

Time: 612.724 ms

@michae2
Copy link
Collaborator

michae2 commented Oct 17, 2022

(Note this also reproduces on 22.1 and 21.2.)

michae2 added a commit to michae2/cockroach that referenced this issue Nov 15, 2022
`eval.optimizedLikeFunc` has special cases for LIKE patterns that start and
end with wildcards `%` or `_` which can be evaluated without regular
expressions. Add support for patterns with no wildcards at all.

Fixes: cockroachdb#91887
Assists: cockroachdb#89749

Epic: None

Release note (performance improvement): Performance of the `LIKE` and
`ILIKE` operators using patterns without any wildcards has been
improved.
michae2 added a commit to michae2/cockroach that referenced this issue Nov 16, 2022
`eval.optimizedLikeFunc` has special cases for LIKE patterns that start and
end with wildcards `%` or `_` which can be evaluated without regular
expressions. Add support for patterns with no wildcards at all.

Fixes: cockroachdb#91887
Assists: cockroachdb#89749

Epic: None

Release note (performance improvement): Performance of the `LIKE` and
`ILIKE` operators using patterns without any wildcards has been
improved.
craig bot pushed a commit that referenced this issue Nov 16, 2022
91895: eval: add LIKE patterns without wildcards to optimizedLikeFunc r=DrewKimball,yuzefovich a=michae2

`eval.optimizedLikeFunc` has special cases for LIKE patterns that start and end with wildcards `%` or `_` which can be evaluated without regular expressions. Add support for patterns with no wildcards at all.

Fixes: #91887
Assists: #89749

Epic: None

Release note (performance improvement): Performance of the `LIKE` and `ILIKE` operators using patterns without any wildcards has been improved.

Co-authored-by: Michael Erickson <[email protected]>
@msirek msirek self-assigned this Jun 29, 2023
msirek pushed a commit to msirek/cockroach that referenced this issue Jun 30, 2023
`eval.optimizedLikeFunc` has special cases for LIKE patterns that start and
end with wildcards `%` or `_` which can be evaluated without regular
expressions. Add support for patterns with no wildcards at all.

Fixes: cockroachdb#91887
Assists: cockroachdb#89749

Epic: None

Release note (performance improvement): Performance of the `LIKE` and
`ILIKE` operators using patterns without any wildcards has been
improved.
@msirek
Copy link
Contributor

msirek commented Jun 30, 2023

Fixed by #105863

@msirek msirek closed this as completed Jun 30, 2023
@mgartner mgartner moved this to Done in SQL Queries Jul 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
branch-release-22.2 Used to mark GA and release blockers, technical advisories, and bugs for 22.2 C-test-failure Broken test (automatically or manually discovered). O-roachtest O-robot Originated from a bot. T-sql-queries SQL Queries Team
Projects
Archived in project
Development

No branches or pull requests

4 participants