This query has only 2000 matching rows and it returns the result in 2.9 seconds.
In the same query, if I remove one criteria alone (the bolded part), the result would still match only 2000 rows, but the result would come in 300 milliseconds even.
I used the PLAN statement and found that the query plan that the executor takes for the first query is a much complex path and it performs 3 joins for all the 35 lakh rows (i.e. before executing the criteria even) and hence the time has spiked to 3 seconds. May be the hot data of 35 lakh tuples would have not fit into the memory?? Not sure.
But if I remove the highlighted criteria, the executor evaluates the criteria first and it performs the joins for only 7000 rows and hence it is faster 1000 times.
Is this a bug?
Or is there any way to optimise my query to match the executor to choose the right plan?
I am looking on to install MonetDB in our production setup, but finding this as a showstopper.
Any help much appreciated. I could even demo this.