DEV Community

ItsEvilDuck
ItsEvilDuck

Posted on Originally published at itsevilduck.gumroad.com

SQL OR to IN Refactor for Performance

I just shipped a small tool called SQL OR to IN Refactor for Performance. If you deal with large datasets, you might have run into queries using multiple OR conditions on the same column.

This snippet demonstrates a straightforward refactoring pattern that transforms queries from WHERE col = val1 OR col = val2 into WHERE col IN (val1, val2). Making this change often allows database query planners to utilize indexes much more efficiently, cutting down execution time for slow queries.

It is designed for backend developers, database administrators, and anyone writing raw SQL who needs a quick reference or a drop-in pattern to optimize query performance without overhauling their entire schema or application logic.

You can check out the details here: SQL OR to IN Refactor for Performance.

Top comments (0)