processwire / processwire-requests

ProcessWire feature requests.
39 stars 0 forks source link

Use SQL NOT IN instead of multiple != to improve query performance. #479

Closed adrianbj closed 1 year ago

adrianbj commented 1 year ago

Short description of the enhancement

Instead of

$pages->find('id!=2187|1921|1101')

generating queries like:

SELECT pages.id
FROM `pages`
WHERE (pages.id!=2187 AND pages.id!=1921 AND pages.id!=1101)

it appears to be significantly quicker to go with:

SELECT pages.id
FROM `pages`
WHERE pages.id NOT IN (2187, 1921, 1101)

Why would the enhancement be useful to users?

In my testing with ~350 IDs it went from 0.2 s to 0.01 s

ryancramerdesign commented 1 year ago

@adrianbj Thanks, I have added this.

adrianbj commented 1 year ago

Thanks @ryancramerdesign - should be a nice speed bump in certain situations.