Skip to content

Fix DISTINCT on ENUM/SET columns by making enums/set hashable#17936

Merged
GuptaManan100 merged 3 commits intovitessio:mainfrom
codex-maintainers:gopoto/17676
Mar 20, 2025
Merged

Fix DISTINCT on ENUM/SET columns by making enums/set hashable#17936
GuptaManan100 merged 3 commits intovitessio:mainfrom
codex-maintainers:gopoto/17676

Conversation

@codex-maintainers
Copy link
Collaborator

@codex-maintainers codex-maintainers commented Mar 7, 2025

Description

Vitess’ DISTINCT (and grouping) primitives rely on evalengine.NullsafeHashcode
to deduplicate rows coming back from scatter queries. While most value types
implement the hashable interface so our default hashing can recognize them,
both evalEnum and evalSet did not. The result is that any query that tries
to sort or de-dup on an ENUM or SET column across shards would error out
with unexpected type ENUM.

This PR adds Hash implementations for both enum and set evals so that
DISTINCT, GROUP BY, hash join and similar code paths can hash these types
properly. For enum/set values we hash the numeric ordinal/bitset when all
values are known, and fall back to hashing the raw string under a binary
collation when we can't resolve the value.

To catch this in end-to-end tests, the aggregation test keyspace is updated
with a simple example table that has an enum column, and a new assertion is
added to the DISTINCT test to exercise SELECT DISTINCT foo FROM example;,
which fails prior to the hashable fix and passes afterwards.

Related Issue(s)

Fixes #17676

Checklist

  • "Backport to:" labels have been added if this change should be back‑ported to release branches
  • If this change is to be back‑ported to previous releases, a justification is included in the PR description
  • Tests were added or are not required
  • Did the new or modified tests pass consistently locally and on CI?
  • Documentation was added or is not required

Deployment Notes

None.


This PR was generated by an AI system in collaboration with maintainers @rbranson, @GuptaManan100, @rohit-nayak-ps, @systay.

@vitess-bot
Copy link
Contributor

vitess-bot bot commented Mar 7, 2025

Review Checklist

Hello reviewers! 👋 Please follow this checklist when reviewing this Pull Request.

General

  • Ensure that the Pull Request has a descriptive title.
  • Ensure there is a link to an issue (except for internal cleanup and flaky test fixes), new features should have an RFC that documents use cases and test cases.

Tests

  • Bug fixes should have at least one unit or end-to-end test, enhancement and new features should have a sufficient number of tests.

Documentation

  • Apply the release notes (needs details) label if users need to know about this change.
  • New features should be documented.
  • There should be some code comments as to why things are implemented the way they are.
  • There should be a comment at the top of each new or modified test to explain what the test does.

New flags

  • Is this flag really necessary?
  • Flag names must be clear and intuitive, use dashes (-), and have a clear help text.

If a workflow is added or modified:

  • Each item in Jobs should be named in order to mark it as required.
  • If the workflow needs to be marked as required, the maintainer team must be notified.

Backward compatibility

  • Protobuf changes should be wire-compatible.
  • Changes to _vt tables and RPCs need to be backward compatible.
  • RPC changes should be compatible with vitess-operator
  • If a flag is removed, then it should also be removed from vitess-operator and arewefastyet, if used there.
  • vtctl command output order should be stable and awk-able.

@vitess-bot vitess-bot bot added NeedsBackportReason If backport labels have been applied to a PR, a justification is required NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsIssue A linked issue is missing for this Pull Request NeedsWebsiteDocsUpdate What it says labels Mar 7, 2025
@github-actions github-actions bot added this to the v22.0.0 milestone Mar 7, 2025
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gopoto Looks like you accidentally committed a bunch of test files here that shouldn't be?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the vtroot_6701 tmp and topo directories that were committed in error; these logs and wal files were artifacts of a previous test run and shouldn't be in the tree.

Signed-off-by: Gene Parmesan Thomas <201852096+gopoto@users.noreply.github.com>
Signed-off-by: Gene Parmesan Thomas <201852096+gopoto@users.noreply.github.com>
@arthurschreiber
Copy link
Member

I guess this will have to be backported to oder versions as well? 🤔

@arthurschreiber
Copy link
Member

Is there a way to test the "unknown set" and "unknown enum" value cases?

@codecov
Copy link

codecov bot commented Mar 12, 2025

Codecov Report

Attention: Patch coverage is 78.94737% with 4 lines in your changes missing coverage. Please review.

Project coverage is 67.54%. Comparing base (526665e) to head (a98ee42).
Report is 33 commits behind head on main.

Files with missing lines Patch % Lines
go/vt/vtgate/evalengine/eval_enum.go 77.77% 2 Missing ⚠️
go/vt/vtgate/evalengine/eval_set.go 80.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #17936      +/-   ##
==========================================
- Coverage   67.56%   67.54%   -0.02%     
==========================================
  Files        1597     1597              
  Lines      259780   259851      +71     
==========================================
+ Hits       175516   175529      +13     
- Misses      84264    84322      +58     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Signed-off-by: Gene Parmesan Thomas <201852096+gopoto@users.noreply.github.com>
@systay systay added Type: Bug Component: Query Serving and removed NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsWebsiteDocsUpdate What it says NeedsIssue A linked issue is missing for this Pull Request NeedsBackportReason If backport labels have been applied to a PR, a justification is required labels Mar 14, 2025
@dbussink
Copy link
Member

@gopoto Is this ready for review?

@GuptaManan100 GuptaManan100 marked this pull request as ready for review March 20, 2025 08:53
@GuptaManan100 GuptaManan100 merged commit 0e54bd6 into vitessio:main Mar 20, 2025
110 of 111 checks passed
vitess-bot pushed a commit that referenced this pull request Mar 20, 2025
Signed-off-by: Gene Parmesan Thomas <201852096+gopoto@users.noreply.github.com>
vitess-bot pushed a commit that referenced this pull request Mar 20, 2025
Signed-off-by: Gene Parmesan Thomas <201852096+gopoto@users.noreply.github.com>
GuptaManan100 pushed a commit that referenced this pull request Mar 20, 2025
…ashable (#17936) (#17991)

Signed-off-by: Gene Parmesan Thomas <201852096+gopoto@users.noreply.github.com>
Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com>
GuptaManan100 added a commit that referenced this pull request Mar 20, 2025
…ashable (#17936) (#17990)

Signed-off-by: Gene Parmesan Thomas <201852096+gopoto@users.noreply.github.com>
Signed-off-by: Manan Gupta <manan@planetscale.com>
Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com>
Co-authored-by: Manan Gupta <manan@planetscale.com>
timvaillancourt added a commit to slackhq/vitess that referenced this pull request May 8, 2025
* [release-21.0] Bump to `v21.0.4-SNAPSHOT` after the `v21.0.3` release (vitessio#17766)

Signed-off-by: Rohit Nayak <rohit@planetscale.com>
Co-authored-by: Rohit Nayak <rohit@planetscale.com>

* [release-21.0] smartconnpool: Better handling for idle expiration (vitessio#17757) (vitessio#17781)

Signed-off-by: Vicent Marti <vmg@strn.cat>
Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com>

* [release-21.0] Fail assignment expressions with the correct message (vitessio#17752) (vitessio#17776)

Signed-off-by: Manan Gupta <manan@planetscale.com>
Co-authored-by: Manan Gupta <35839558+GuptaManan100@users.noreply.github.com>
Co-authored-by: Manan Gupta <manan@planetscale.com>

* [release-21.0] Multi-tenant workflow SwitchWrites: Don't add denied tables on cancelMigration() (vitessio#17782) (vitessio#17797)

Signed-off-by: Rohit Nayak <rohit@planetscale.com>
Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com>

* [release-21.0] VReplication Atomic Copy Workflows: fix bugs around concurrent inserts (vitessio#17772) (vitessio#17793)

Signed-off-by: Rohit Nayak <rohit@planetscale.com>
Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com>

* [release-21.0] Upgrade the Golang version to `go1.23.6` (vitessio#17699)

Signed-off-by: GitHub <noreply@github.com>
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Co-authored-by: frouioui <frouioui@users.noreply.github.com>
Co-authored-by: Florent Poinsard <florent.poinsard@outlook.fr>

* [release-21.0] Fix a potential connection pool leak. (vitessio#17807) (vitessio#17814)

Signed-off-by: Arthur Schreiber <arthurschreiber@github.com>
Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com>

* backport: support subqueries inside subqueries when merging (Release 21.0) (vitessio#17811)

Signed-off-by: Andres Taylor <andres@planetscale.com>

* [release-21.0] Fix vtcombo parsing flags incorrectly (vitessio#17743) (vitessio#17820)

Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
Co-authored-by: Dirkjan Bussink <d.bussink@gmail.com>

* [release-21.0] pool: reopen connection closed by idle timeout (vitessio#17818) (vitessio#17829)

* [release-21.0] Implement temporal comparisons (vitessio#17826) (vitessio#17854)

Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com>

* [release-21.0] evalengine: normalize types during compilation (vitessio#17887) (vitessio#17896)

Signed-off-by: Vicent Marti <vmg@strn.cat>
Signed-off-by: Andres Taylor <andres@planetscale.com>
Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com>
Co-authored-by: Vicent Marti <vmg@strn.cat>

* [release-21.0] Fix: Separate Lock for Keyspace to Update Controller Mapping in Schema Tracking (vitessio#17873) (vitessio#17885)

Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com>
Co-authored-by: Harshit Gangal <harshit@planetscale.com>

* [release-21.0] Upgrade the Golang version to `go1.23.7` (vitessio#17901)

Signed-off-by: GitHub <noreply@github.com>
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Co-authored-by: frouioui <frouioui@users.noreply.github.com>
Co-authored-by: Florent Poinsard <florent.poinsard@outlook.fr>

* [release-21.0] fix: race on storing schema engine last changed time (vitessio#17914) (vitessio#17917)

Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Co-authored-by: Harshit Gangal <harshit@planetscale.com>
Co-authored-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>

* [release-21.0] [VTAdmin] Insert into schema cache if exists already and not expired (vitessio#17908) (vitessio#17924)

Signed-off-by: Frances Thai <notfelineit@gmail.com>
Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com>

* [release-21.0] Bump golang.org/x/net from 0.34.0 to 0.36.0 (vitessio#17958) (vitessio#17960)

Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com>

* [release-21.0] fix flaky test on mysqlshell backup engine  (vitessio#17981)

Signed-off-by: Renan Rangel <rrangel@slack-corp.com>
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Co-authored-by: Renan Rangel <rvrangel@users.noreply.github.com>

* [release-21.0] DML test fix for duplicate column value  (vitessio#17980)

Signed-off-by: Harshit Gangal <harshit@planetscale.com>

* [release-21.0] Fix DISTINCT on ENUM/SET columns by making enums/set hashable (vitessio#17936) (vitessio#17991)

Signed-off-by: Gene Parmesan Thomas <201852096+gopoto@users.noreply.github.com>
Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com>

* [release-21.0] Fix tablet selection in `vtctld BackupShard` (vitessio#18002) (vitessio#18025)

Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com>

* [release-21.0] Set proper join vars type for the RHS field query in OLAP (vitessio#18028) (vitessio#18038)

Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Signed-off-by: Andres Taylor <andres@planetscale.com>
Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com>
Co-authored-by: Andres Taylor <andres@planetscale.com>

* [release-21.0] Use release branches for upgrade downgrade tests (vitessio#18029) (vitessio#18035)

Signed-off-by: Manan Gupta <manan@planetscale.com>
Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com>

* [release-21.0] Test: Increase query timeout to fix flaky test 'TestQueryTimeoutWithShardTargeting' (vitessio#18016) (vitessio#18040)

Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com>

* [release-21.0] fix: App and Dba Pool metrics (vitessio#18048) (vitessio#18084)

Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com>

* [release-21.0] Upgrade the Golang version to `go1.23.8` (vitessio#18092)

Signed-off-by: GitHub <noreply@github.com>
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Co-authored-by: frouioui <frouioui@users.noreply.github.com>
Co-authored-by: Florent Poinsard <florent.poinsard@outlook.fr>

* [release-21.0] bugfix: allow window functions when possible to push down (vitessio#18103) (vitessio#18105)

Signed-off-by: Andres Taylor <andres@planetscale.com>
Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com>
Co-authored-by: Andres Taylor <andres@planetscale.com>

* [release-21.0] VDiff: Fix logic for reconciling extra rows (vitessio#17950) (vitessio#18072)

Signed-off-by: Rohit Nayak <rohit@planetscale.com>
Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com>

* [release-21.0] VStream API: Reset stopPos in catchup (vitessio#18119) (vitessio#18122)

Signed-off-by: Noble Mittal <noblemittal@outlook.com>
Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com>

* [release-21.0] Fix `Reshard Cancel` behavior (vitessio#18020) (vitessio#18080)

Signed-off-by: Arthur Schreiber <arthurschreiber@github.com>
Co-authored-by: Arthur Schreiber <arthurschreiber@github.com>

* Fix backup shard copy paste error (vitessio#18100)

Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>

* [release-21.0] go/vt/vtgate: take routing rules into account for traffic mirroring (vitessio#17953) (vitessio#17994)

Signed-off-by: Max Englander <max@planetscale.com>
Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com>
Co-authored-by: Max Englander <max@planetscale.com>

* [release-21.0] Bugfix: Missing data when running vtgate outer joins (vitessio#18036) (vitessio#18044)

Signed-off-by: Andres Taylor <andres@planetscale.com>
Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com>

* [release-21.0] Filter out tablets with unknown replication lag when electing a new primary (vitessio#18004) (vitessio#18075)

Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Co-authored-by: Florent Poinsard <35779988+frouioui@users.noreply.github.com>

* [release-21.0] Fix: Ensure Consistent Lookup Vindex Handles Duplicate Rows in Single Query (vitessio#17974) (vitessio#18078)

Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Co-authored-by: Harshit Gangal <harshit@planetscale.com>

* [release-21.0] Code Freeze for `v21.0.4` (vitessio#18135)

Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>

* [release-21.0] Release of `v21.0.4` (vitessio#18136)

Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>

* test fix

Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>

* Revert "test fix"

This reverts commit 55aec5c.

---------

Signed-off-by: Rohit Nayak <rohit@planetscale.com>
Signed-off-by: Vicent Marti <vmg@strn.cat>
Signed-off-by: Manan Gupta <manan@planetscale.com>
Signed-off-by: GitHub <noreply@github.com>
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Signed-off-by: Arthur Schreiber <arthurschreiber@github.com>
Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Frances Thai <notfelineit@gmail.com>
Signed-off-by: Renan Rangel <rrangel@slack-corp.com>
Signed-off-by: Gene Parmesan Thomas <201852096+gopoto@users.noreply.github.com>
Signed-off-by: Noble Mittal <noblemittal@outlook.com>
Signed-off-by: Max Englander <max@planetscale.com>
Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
Co-authored-by: vitess-bot <139342327+vitess-bot@users.noreply.github.com>
Co-authored-by: Rohit Nayak <rohit@planetscale.com>
Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com>
Co-authored-by: Manan Gupta <35839558+GuptaManan100@users.noreply.github.com>
Co-authored-by: Manan Gupta <manan@planetscale.com>
Co-authored-by: frouioui <frouioui@users.noreply.github.com>
Co-authored-by: Florent Poinsard <florent.poinsard@outlook.fr>
Co-authored-by: Andrés Taylor <andres@planetscale.com>
Co-authored-by: Matt Lord <mattalord@gmail.com>
Co-authored-by: Dirkjan Bussink <d.bussink@gmail.com>
Co-authored-by: Harshit Gangal <harshit@planetscale.com>
Co-authored-by: Vicent Marti <vmg@strn.cat>
Co-authored-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Co-authored-by: Florent Poinsard <35779988+frouioui@users.noreply.github.com>
Co-authored-by: Renan Rangel <rvrangel@users.noreply.github.com>
Co-authored-by: Arthur Schreiber <arthurschreiber@github.com>
Co-authored-by: Max Englander <max@planetscale.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug Report: Unexpected type ENUM

5 participants