MD5 correlated scalar subquery duplicates hash results
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 22/100
Research direction
Reproduce the wrong result on a local single-node cluster with cockroach sql, using the md5_source and md5_guard tables and the two queries in the issue. Run EXPLAIN on both queries to see where the correlated scalar subquery is planned differently from the plain join. Done means the correlated MD5 query returns the same two distinct hashes as the control query, with a regression test covering this GROUP BY shape.
Written by the indexing model from the issue text.
Description
Describe the problem
A correlated scalar subquery containing MD5 duplicates hash results under GROUP BY. The direct query produces one hash for alpha and one for beta. The correlated version returns each hash twice.
To Reproduce
The issue reproduces with the following sequence:
- Start a CockroachDB v26.3.0 cluster and connect with
cockroach sql. - Create the source and guard tables and insert the values shown in Additional data and screenshots.
- Run the control
MD5query and observe two distinct hashes. - Run the correlated
MD5query and observe that each hash appears twice.
Expected behavior
Both queries should return exactly two hashes. The correlated predicate uses the primary-key column input_value, so the scalar subquery returns exactly one MD5 value for each outer row.
Additional data and screenshots
The complete schema, test data, control query, affected query, and observed output are included below. No screenshot is required because the behavior is visible in the cockroach sql output.
Schema and test data
DROP TABLE IF EXISTS md5_guard;
DROP TABLE IF EXISTS md5_source;
CREATE TABLE md5_guard (
guard_value STRING
);
CREATE TABLE md5_source (
input_value STRING PRIMARY KEY
);
INSERT INTO md5_guard VALUES ('not-a-hash');
INSERT INTO md5_source VALUES ('alpha'), ('beta');
Control query
SELECT NULLIF(
MD5(s.input_value),
g.guard_value
) AS result
FROM md5_source AS s,
md5_guard AS g
GROUP BY s.input_value, g.guard_value
ORDER BY result;
Control output
result
----------------------------------
2c1743a391305fbf367df8e4f069f9f
987bcab01b929eb2c07877b224215c92
(2 rows)
Affected query
SELECT NULLIF(
(
SELECT MD5(x.input_value)
FROM md5_source AS x
WHERE x.input_value = s.input_value
),
g.guard_value
) AS result
FROM md5_source AS s,
md5_guard AS g
GROUP BY s.input_value, g.guard_value
ORDER BY result;
Actual output
result
----------------------------------
2c1743a391305fbf367df8e4f069f9f
2c1743a391305fbf367df8e4f069f9f
987bcab01b929eb2c07877b224215c92
987bcab01b929eb2c07877b224215c92
(4 rows)
Environment:
- CockroachDB version: CockroachDB CCL v26.3.0, built 2026-07-28
- Server OS: macOS on Apple Silicon
- CockroachDB build target:
aarch64-apple-darwin21.2 - Client application:
cockroach sql - Connection: local single-node test cluster at
127.0.0.1:26257
Additional context
This is a silent wrong-result issue. The duplicated hashes can affect deduplication, grouping, and application logic that assumes one result for each primary-key row.
Jira issue: CRDB-71128
- Dominant language
- Go
- Stars
- 32.6k
- Forks
- 4.2k
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from cockroachdb/cockroach
-
C-bug O-community X-blathers-untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
cockroachdb/cockroach#176245 · 1 comment ·
-
sql: pg_database.dattablespace is 0 but pg_tablespace.oid is 1663, so they no longer joinPossibly taken @1AbdullahButt claimed this 14 days ago. OpenC-bug O-community X-blathers-triaged X-move-internal
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
cockroachdb/cockroach#176228 · 1 comment ·
-
PG compat: overflow in integer power calculation triggers incompatible SQLSTATEMay be free again @darshpatel1052 claimed this 18 days ago, and no pull request is open. OpenC-bug O-community X-blathers-untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
cockroachdb/cockroach#176223 · 2 comments ·
-
util/log: bufferedSinkCloser.Close leaks a goroutine after timeoutPossibly taken @dajiaohuang claimed this 14 days ago. OpenC-bug O-community X-blathers-untriaged
Difficulty 1/5 Under an hour Newbie friendliness 84/100
cockroachdb/cockroach#176210 · 1 comment ·
-
C-bug O-community T-sql-queries X-blathers-triaged X-move-internal
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
cockroachdb/cockroach#176150 · 1 comment ·
All issues in cockroachdb/cockroach
Similar issues
-
area/import-export area/projects concern/ux
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
go-vikunja/vikunja#4455 · 1 comment ·
Maintainers usually reply within 2 days
-
Dependabot PRs no longer merge automaticallyPossibly taken @dwisiswant0 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
projectdiscovery/urlfinder#160 ·
Maintainers usually reply within 1 day
-
database
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
chnm/legal-modernism#450 ·
Maintainers usually reply within 1 day
-
tech-debt
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
bug ready-for-triage ready-to-code
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
RedHatInsights/insights-ingress-go#946 · 4 comments ·
Maintainers usually reply within 1 day