![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I've got an application being put together with cake/php. *It's pretty nice, but their data pager does this: * * SELECT COUNT(*) AS COUNT * * FROM foo f * * LEFT JOIN bar b * * ON (f.asset_group_id = b.asset_group_id) * * WHERE 1 * * * * * * * * * *= 1 Any way possible to speed this up? Many TIA! Mark -- Mark Harrison Pixar Animation Studios |
#3
| |||
| |||
|
|
I've got an application being put together with cake/php. *It's pretty nice, but their data pager does this: * * SELECT COUNT(*) AS COUNT * * FROM foo f * * LEFT JOIN bar b * * ON (f.asset_group_id = b.asset_group_id) * * WHERE 1 * * * * * * * * * *= 1 Any way possible to speed this up? Many TIA! Mark -- Mark Harrison Pixar Animation Studios |
#4
| |||
| |||
|
|
On Nov 24, 7:22 pm, m... (AT) pixar (DOT) com wrote: I've got an application being put together with cake/php. It's pretty nice, but their data pager does this: SELECT COUNT(*) AS COUNT FROM foo f LEFT JOIN bar b ON (f.asset_group_id = b.asset_group_id) WHERE 1 = 1 Any way possible to speed this up? Many TIA! Mark -- Mark Harrison Pixar Animation Studios Mark, you tune a select count like you tune any other SQL statement. Start with the explain plan. Here is an article on how Oracle performs select count. Is there a good way of counting the number of rows in a table ? http://www.jlcomp.demon.co.uk/faq/count_rows.html The best optimization is not to perform the count. That is, if you are going to fetch the data anyway just go ahead and fetch it if possible. If you just need to know if a row exists but do not truely need to know how many you can use either where rownum = 1 or an exists subquery to cut the counting off when a row is found. That is, you get a count of 1 for a hit and zero where there are not hits (rows matching query criteria). In you your example why do you have where 1 = 1 ? Kind of unnecessary isn't it. |
#5
| |||
| |||
|
|
On Nov 24, 7:22*pm, m... (AT) pixar (DOT) com wrote: In you your example why do you have where 1 = 1 ? *Kind of unnecessary isn't it. |
#6
| |||
| |||
|
|
On Nov 25, 8:19 am, Mark D Powell <Mark.Powe... (AT) hp (DOT) com> wrote: On Nov 24, 7:22 pm, m... (AT) pixar (DOT) com wrote: In you your example why do you have where 1 = 1 ? Kind of unnecessary isn't it. I have an example pinned up on my cube of an OCI generated code that has 48 1=1 statements in it. It would be even more unnecessary for me to try to get rid of them. :-) I'm sure there must be more somewhere in this kind of code, that one just happened to catch my eye in EM one day. Doesn't seem to bother the optimizer at all. jg -- @home.com is bogus. Death of wikipedia, news at 11. http://news.cnet.com/8301-1023_3-10403467-93.html |
#7
| |||
| |||
|
|
I've got an application being put together with cake/php. It's pretty nice, but their data pager does this: SELECT COUNT(*) AS COUNT FROM foo f LEFT JOIN bar b ON (f.asset_group_id = b.asset_group_id) WHERE 1 = 1 Any way possible to speed this up? |
#8
| |||
| |||
|
|
Most times, these queries are generated by some tool that needs a where clause anyway, and 'AND's or 'OR's the user specified clauses to it, and they put in the 1=1 for when a user does not enter any condition.. |
#9
| |||
| |||
|
|
Shakespeare wrote: Most times, these queries are generated by some tool that needs a where clause anyway, and 'AND's or 'OR's the user specified clauses to it, and they put in the 1=1 for when a user does not enter any condition.. Surprisingly, the optimizer sometimes seems to do a bad job about such constant clauses. As in "where 1 = 2" resulting in a full table scan... |
#10
| |||
| |||
|
|
Shakespeare wrote: Most times, these queries are generated by some tool that needs a where clause anyway, and 'AND's or 'OR's the user specified clauses to it, and they put in the 1=1 for when a user does not enter any condition.. Surprisingly, the optimizer sometimes seems to do a bad job about such constant clauses. As in "where 1 = 2" resulting in a full table scan... |
![]() |
| Thread Tools | |
| Display Modes | |
| |