I would like to optimize my query, I’m currently sub-querying a table loaded with a sequence of SMALLINT values from 0 to 9999.

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.
The only way you can tell for sure is to test it.
I did similar tests using PostgreSQL a few months ago. The question was whether it made sense to replace a calendar table with generate_series().
In our case, the table was faster. But if you test, you’ll probably find that generate_series() becomes faster at a certain number of rows. (That’s what we found, but the number of rows was well over anything we used.) My guess is that, at that point, the time it takes to generate the series becomes less than the time it takes to read the index and rows off the disk.
That’s a guess, because PostgreSQL’s EXPLAIN ANALYZE doesn’t give you much detail about disk I/O.