On Thu, Oct 23, 2014 at 11:55 AM, Luigi Iemma <iemmalu...@gmail.com> wrote:
> Hi, > > SELECT TdoIdoc,RdoCart,RdoQuat > FROM Tesdoc > INNER JOIN Rigdoc ON RdoIdoc BETWEEN TdoIdoc*10000000 AND > TdoIdoc*10000000+9999999 > WHERE TdoTipo=60 AND TdoAnno BETWEEN 2014 AND 2014 > GROUP BY TdoIdoc > > When I run this query on 3.8.5 it takes 0.126 seconds, > when I run this query on 3.8.7 it takes 17.37 seconds > Version 3.8.7 (also version 3.8.6) is using a different query plan. Actually, 3.8.6 and 3.8.7 are making the better choice, based on the information at hand. The query planner just doesn't have sufficient information to make a good choice in this case. As Simon pointed out, you can run ANALYZE to give the query planner more information. Or you can give it hints. One possible hint is to add a "likelihood() function around the TdoTipo=60 constraint: SELECT TdoIdoc,RdoCart,RdoQuat FROM Tesdoc, Rigdoc WHERE RdoIdoc BETWEEN TdoIdoc*10000000 AND TdoIdoc*10000000+9999999 AND likelihood(TdoTipo=60, 0.01) ----<<< HERE AND TdoAnno BETWEEN 2014 AND 2014 GROUP BY TdoIdoc; -- D. Richard Hipp d...@sqlite.org _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users