Skip to content

Conversation

@a5-stable
Copy link
Collaborator

@a5-stable a5-stable commented Sep 17, 2025

citusdata/activerecord-multi-tenant#223

  • Tried to fix the issue where delete_all and update_all would turn into subqueries when using LIMIT.
  • The tenant condition was missing from the outer query.

Before

UPDATE "projects" SET "name" = "new"
WHERE "projects"."id" IN (
  SELECT "projects"."id" FROM "projects"
  WHERE "projects"."account_id" = 1 LIMIT 5
)

After

UPDATE "projects" SET "name" = "new"
WHERE "projects"."id" IN (
  SELECT "projects"."id" FROM "projects"
  WHERE "projects"."account_id" = 1 LIMIT 5
) AND "projects"."account_id" = 1

However, Subqueries are added even when they are unnecessary.

Example

Projects.update_all
# => UPDATE "projects" SET "name" = "new"
#    WHERE "projects"."id" IN (
#      SELECT "projects"."id" FROM "projects"
#      WHERE "projects"."account_id" = 1
#    ) AND "projects"."account_id" = 1

Investigation

@a5-stable a5-stable marked this pull request as draft September 17, 2025 02:17
@a5-stable a5-stable changed the title Refactor tenant enforcement to use Arel visitor pattern [WIP] Refactor tenant enforcement to use Arel visitor pattern Sep 17, 2025
@a5-stable a5-stable force-pushed the leave-query-to-rails branch 3 times, most recently from 61d0079 to e938a43 Compare September 22, 2025 01:27
@a5-stable a5-stable marked this pull request as ready for review September 30, 2025 06:11
@a5-stable a5-stable marked this pull request as draft September 30, 2025 06:13
@a5-stable a5-stable marked this pull request as ready for review September 30, 2025 06:25
@a5-stable a5-stable marked this pull request as draft September 30, 2025 06:25
@a5-stable a5-stable marked this pull request as ready for review October 1, 2025 07:28
@a5-stable a5-stable marked this pull request as draft October 1, 2025 07:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants