I didn't get the point. ....
Q1 is slower (obviously) cause of the epoch() function and the additional 
filtering
Q1 with cache shows more or less the same duration as Q2 with cache. 
the key point is "even when the cache is enabled the first query is taking 
longer" ... longer than what ?
Q1 with cache is speedier that:
- Q1 without cache, and that's ok
- Q2 without cache, and that's ok
but it's slower than
- Q2 with cache 
however 3 ms (assuming those timings are in seconds) with all the moving 
parts of a memcache instance seems unfair to blame entirely on web2py


On Monday, March 25, 2013 9:48:14 AM UTC+1, Paolo valleri wrote:
>
> Dear all, I want to share with you some results. I implemented a query in 
> two different ways. Given the following common code:
> start = db.record.with_alias('start_point')
> end = db.record.with_alias('end_point')
> elapsed_time = end.gathered_on.epoch() - start.gathered_on.epoch()
>
> The first query is (the constrain is in the query):
> rows = db( query & (elapsed_time  < 86400) ).select(
> start.ALL, 
> end.ALL, 
> start.gathered_on.epoch(),
> end.gathered_on.epoch(),
> elapsed_time,
> orderby=start.gathered_on.epoch(),
> left=start.on( (start.mac == end.mac) & (start.gathered_on < 
> end.gathered_on)),
> cache=(cache.memcache, 3600),
> cacheable = True
> )
> The second one is (the constrain is explicitly tested latter):
> rows = db( query ).select(
> start.ALL, 
> end.ALL, 
> start.gathered_on.epoch(),
> end.gathered_on.epoch(),
> elapsed_time,
> orderby=start.gathered_on.epoch(),
> left=start.on( (start.mac == end.mac) & (start.gathered_on < 
> end.gathered_on)),
> cache=(cache.memcache, 3600),
> cacheable = True
> )
> rows2 = [r for r in rows if (r.end_point.gathered_on - 
> r.start_point.gathered_on < datetime.timedelta(days=1)) ]
>
> From the timing results I got that the second query is always faster, with 
> or without cache:
> Q_1: 0.273243904114 
> Q_1 with cache: 0.0182011127472
> Q_2: 0.250607967377
> Q_2 with cache: 0.0158171653748
>
> Beside the fact that they are just a few milliseconds of difference and 
> that all the rows satisfy the constrain, what is not clear to me is why 
> even when the cache is enabled the first query is taking longer. The 
> question that came to my mind is about computed columns, are they cached?
>
> Paolo
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to