Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #7482 (closed defect: fixed)

Opened 2 years ago

Last modified 1 year ago

[PATCH] AR incorrectly quotes ids inside IN clause

Reported by: tmacedo Assigned to: jeremy@bitsweat.net
Priority: low Milestone: 1.x
Component: ActiveRecord Version: edge
Severity: minor Keywords: tiny
Cc:

Description

AR incorrectly quotes ids inside an IN clause. This happens when using include and limit clauses over a has_many relationship. An example and patch follows.

The ids using in the IN clause shouldn't be quoted as they are integers and not quoting them should improve the performance (by coping better with indexes).

Banner Load Including Associations (0.006802) SELECT (...) FROM banners LEFT OUTER JOIN blocks ON blocks.banner_id = banners.id WHERE (banner_id = banners.id and blocks.status = 0 and blocks.percentage_sold < 100) AND banners.id IN ('15', '13', '11') ORDER BY created_at DESC

After the patch to the select_limited_ids_list function this no longer occurs.

Banner Load Including Associations (0.004319) SELECT (...) FROM banners LEFT OUTER JOIN blocks ON blocks.banner_id = banners.id WHERE (banner_id = banners.id and blocks.status = 0 and blocks.percentage_sold < 100) AND banners.id IN (15, 13, 11) ORDER BY created_at DESC

Attachments

select_limited_ids_quote_fix.diff (1.3 kB) - added by tmacedo on 02/05/07 15:12:58.
patch
select_limited_ids_quote_fix_v2.diff (1.4 kB) - added by tmacedo on 02/07/07 16:18:57.
new version

Change History

02/05/07 15:12:58 changed by tmacedo

  • attachment select_limited_ids_quote_fix.diff added.

patch

02/05/07 15:15:08 changed by tmacedo

A test that verifies the bug existence and the fix is included.

02/07/07 13:37:45 changed by bitsweat

If you pass the appropriate column to connection.quote you don't have to explicitly .to_i the value, breaking compatibility with non-integer primary keys.

02/07/07 16:18:57 changed by tmacedo

  • attachment select_limited_ids_quote_fix_v2.diff added.

new version

03/13/07 22:22:51 changed by josh

  • keywords set to tiny.
  • summary changed from [PATCH][TINY] AR incorrectly quotes ids inside IN clause to [PATCH] AR incorrectly quotes ids inside IN clause.

09/22/07 22:13:02 changed by david

  • owner changed from core to jeremy@bitsweat.net.

09/22/07 23:51:06 changed by bitsweat

  • status changed from new to closed.
  • resolution set to fixed.

(In [7588]) Correctly quote id list for limited eager loading. Closes #7482.