[web2py] Re: Do conditionals short circuit for DAL?

2016-11-27 Thread Anthony
On Saturday, November 26, 2016 at 5:39:49 PM UTC-5, Brian M wrote:
>
> Well even if you're writing the query using the DAL the actual data 
> processing is being done by the database itself so that's where the "short 
> circuiting" would need to happen and is dependent on the database's query 
> optimization. Try running a SQL version of the query directly against the 
> DB and see if it's any faster.
>

And as mentioned when this question was asked on Stack Overflow, the SQL 
generated by this query is:

SELECT count(*) FROM webhook_table WHERE ((webhook_table.status = 3) AND (
webhook_table.webhook_data LIKE '%form_id%'));

So, try running that outside of web2py and see if you get the same result. 
As Brian noted, the database handles any query optimization -- web2py 
simply generates the SQL and passes it to the Python driver.

Anthony

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
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/d/optout.


[web2py] Re: Do conditionals short circuit for DAL?

2016-11-26 Thread Brian M
Well even if you're writing the query using the DAL the actual data 
processing is being done by the database itself so that's where the "short 
circuiting" would need to happen and is dependent on the database's query 
optimization. Try running a SQL version of the query directly against the 
DB and see if it's any faster. You can try some optimizations in the 
database tables, for example setting up an index on webhook_table.status 
may help.

On Friday, November 25, 2016 at 10:11:38 PM UTC-6, Albert Rothman wrote:
>
> Do conditionals short circuit in DAL queries? Is there a way to force them 
> to. For example I have the following query:
> count = db((db.webhook_table.status==3) & (db.webhook_table.webhook_data.
> contains(premsys.form_id))).count()
> None of the entries have a status of 3, so I expect the query to return 0 
> very quickly. I expect the contains function to run fairly slowly since it 
> has to check every string, but I was expecting the status=3 portion to 
> short-circuit the conditional and make the query execute fast. Is there a 
> way to force short circuiting? 
>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
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/d/optout.