sql: support correlated subqueries in UPDATE #33641
Labels
A-sql-mutations
Mutation statements: UPDATE/INSERT/UPSERT/DELETE.
A-sql-optimizer
SQL logical planning and optimizations.
C-enhancement
Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)
O-community
Originated from the community
Summary
Correlated subqueries in update statements don't work.
Filing this example as requested here: https://www.cockroachlabs.com/docs/stable/subqueries.html#correlated-subqueries (in the Note section)
Related to #3288
Use Case
I need to create effecient counter cache on the tables with millions of row. It's possible to do this within application itself, but highly ineffecient and slow. Running a simple updates statement ( as listed below) is way faster.
This is common pattern in migrations in Rails/Sinatra for creating counter cache on related models.
Steps to reproduce
Actual statement in question
Expected Result
This works in MariaDB, MySQL and Postgres.
Actual Result
Doesn't seem to be supported yet?
Returns this error
I'm just trying out CDB coming from MariaDB/PostgreSQL, and I might be doing it wrong in CDb context, if so, what the supported SQL in Cockroach DB?
Thank you
The text was updated successfully, but these errors were encountered: