Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Your goal should be to use only sargable[1] operators, and eliminate any functions, in all your WHERE clauses and JOINs.

Or just use indexes properly; it's fairly common for modern databases to support indexes on functions of column values; using an indexed (deterministic) function in WHERE/JOIN criteria isn’t problematic. The Wikipedia article you link addresses valid concerns, but the specifics it suggests don't seem accurate for the features of modern RDBMSs.



Also common for ancient RDBMSes


Really seems like you don’t know what sargable means (and didn’t bother to find out if this is your reply).


I think it might be the other way around.


No, its pretty clear from reading his entire response that he understands exactly what sargable means. "just use indexes properly" is pretty ambiguous, but the rest of his comment provides context. It doesn't make much sense to me to be indexing on fn(x) for predicates unless an alternative sargable predicate is too complex or not possible, but that doesn't mean that it's never the best solution.


> unless an alternative sargable predicate is too complex or not possible...

As you note, functional indexes can sometimes be the best solution - some common examples: when working with different geospatial projections in PostGIS; when building a full-text index using `to_tsvector`. For anyone who works with relational databases that support this, definitely a good tool to have in your toolkit!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: