dataset using IN ?
when passed an arrray of 1 argument, which could optimize to = ?
#2237
Replies: 1 comment 1 reply
-
It's possible, but should not be necessary. PostgreSQL should optimize it the same way:
Multiple entries in the array will change the query plan:
This appears to be the same behavior back to PostgreSQL 8.4. Maybe there are cases where the database doesn't perform the optimization? If you could provide a self-contained example, that would help. If there are cases it would help, I would open to shipping the feature in a Sequel extension. It's not a difficult change to make. The pg_auto_parameterize extension uses a similar optimization to change from |
Beta Was this translation helpful? Give feedback.
-
👋 not sure if an issue, so opening the discussion first.
I'm using sequel in a library where a list of ids is select with lock first (via
FOR UPDATE
); this list is then used to perform 2 operations on the resulting dataset,ds.where(id: ids).update...
andds.where(ids: ids).delete
.In a first version, an id was picked up at a time. I noticed that, for the mentioned operations, the resulting datasets would emit
UPDATE (?) FROM table WHERE id IN (?)
andDELETE FROM table WHERE id IN (?)
, which was somewhat suprising to me, but most noticeably was underperforming in the master replica; the production system uses postgresql 14, and it seems that such queries have some performance issues (I read something about improvements for groups in most recent pg 17), and queries should use= ?
instead for better performance. In fact, I managed to force it to use= ?
and stopped seeing the previous p95 spikes.I was wondering whether the sequel call for filter could inspect whether the parameter 1) is an array, and 2) is of size 1, and if so, apply the different operator. Is this something that makes sense? Or do you consider out of scope?
Beta Was this translation helpful? Give feedback.
All reactions