Reputation: 211
I ran the same query in a days gap and the execution time is different on the 1st execution run on Amazon Redshift. I set the cache for the session to FALSE for both runs.
The subsequent queries were faster(ran in milliseconds) for both the queries. I checked the query cache usage and there was no query cache used.
Question: Why and how did the subsequent queries run faster when no query cache was used? Why did the 1st execution take different times for the same query?
P.S. I have used same sorting, distribution and column encodings. Attached the image of my benchmarking of execution time.
Upvotes: 0
Views: 504
Reputation: 14035
Queries (technically query segments) in Redshift are compiled the first time they are executed. Subsequent executions (even with different predicates) usually do not require compilation and will run significantly faster by skipping that step. See the section "Code compilation" in the this document: Factors Affecting Query Performance
Also, please review the document "Compound and Interleaved Sort Keys" in our table design guide before choosing an Interleaved
sort key. This type of key is only recommended in specific scenarios and should not be used a default choice.
Upvotes: 2