I wonder if SELECT * FROM foo will execute faster than SELECT * FROM foo WHERE name LIKE '%' assuming name is NOT NULL?
Any references to documentation?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Both of your queries will scan the entire table. Whether or not name is NOT NULL is only important in extremely rare circumstances where there is (1) an index on name and (2) it is very, very sparse. Only then will PostgreSQL consider looking up the records from the name index.
In all other situations, this SQLFiddle shows that the LIKE version adds a filter, which must be checked. PostgreSQL has no optimization to remove
LIKE '%'against a not-null varchar column, as much as it seems sensible.Table SELECT * all rows
Table SELECT * all rows with `LIKE ‘%’`