How to do SQL inner queries through SQLAlchemy?

Help with optimizing SQL queries...?

  • Hi, I am struggling a bit with optimizing some of my SQL queries....any help would be appreciated. Some of my queries are: select srcip,count(*) from ((select srcip from packets,tcp where tcp.id=packets.id and tcp.destport!=445) UNION ALL (select srcip from packets where packettype IN (1,17))) as list group by list.srcip order by count desc (SELECT srcip,count(*) as count FROM packets WHERE packettype=6 GROUP BY srcip ORDER BY count desc LIMIT 20) INTERSECT (SELECT srcip,count(*) as count FROM packets WHERE packettype=17 GROUP BY srcip ORDER BY count desc LIMIT 20) select srcip,count(*), LOG(256,abs(srcip - inet '192.4.2.128')) from packets,tcp WHERE packettype=6 AND packets.id=tcp.id AND tcp.destport=22 group by srcip order by count desc Limit 20 Thanks...

  • Answer:

    For the first one you could replace the UNION ALL with an outer join but there's no way that I can tell whether or not that will be any better. But general help: ensure join columns are indexed, try to do everything in 1 query rather than combining results with UNION ALL or INTERSECT, sorting is expensive try to avoid it if possible. For some Oracle SQL tuning tips see http://www.asktheoracle.net/oracle-sql-tutorial.html

spiderpi... at Yahoo! Answers Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.