Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Sql Query

Sql Query

Scheduled Pinned Locked Moved Database
databasehelpquestionlounge
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rkyawal
    wrote on last edited by
    #1

    I have problem with this query.. it is taking too much time to fetch the records .. can anybody tell me general solution on this. is their any problem in any join ? i have main problem in the following condition ( (b.cenid = c.cenidr and b.polyid = c.polyidr)or(b.cenid = c.cenidl and b.polyid = c.polyidl)) if only one condition is used then it gives result very fast so help me .. SELECT a.laname, a.cfcc, b.cenid, b.polyid, c.tlid, d.fename, d.fetype, d.frlong as d_frlong, d.frlat as d_frlat, d.tolong as d_tolong, d.tolat as d_tolat, p.polylong, p.polylat, p.water ,e.rtsq, e.long1, e.lat1, e.long2, e.lat2, e.long3, e.lat3, e.long4, e.lat4, e.long5, e.lat5, e.long6, e.lat6, e.long7, e.lat7, e.long8, e.lat8, e.long9, e.lat9, e.long10, e.lat10 FROM (((( ( rt7 as a inner join rt8 as b on a.land = b.land ) inner join rti c on ( (b.cenid = c.cenidr and b.polyid = c.polyidr)or(b.cenid = c.cenidl and b.polyid = c.polyidl)) ) inner join rt11 as d on c.tlid = d.tlid) inner join rtp as p on p.cenid = b.cenid and p.polyid = b.polyid )) left join rt2 as e on d.tlid = e.tlid WHERE a.laname like 'Mill Pond%' and (( 3958.682 ) * ( acos( sin( (d.frlat) * 0.01745 ) * sin( ( $latc ) * 0.01745 ) + cos( (d.frlat) * 0.01745 ) * cos( ( $latc) * 0.01745 ) * cos( (d.frlong - ($longc) ) * 0.01745 ) ) )) <=$mile ORDER BY a.laname

    C E 2 Replies Last reply
    0
    • R rkyawal

      I have problem with this query.. it is taking too much time to fetch the records .. can anybody tell me general solution on this. is their any problem in any join ? i have main problem in the following condition ( (b.cenid = c.cenidr and b.polyid = c.polyidr)or(b.cenid = c.cenidl and b.polyid = c.polyidl)) if only one condition is used then it gives result very fast so help me .. SELECT a.laname, a.cfcc, b.cenid, b.polyid, c.tlid, d.fename, d.fetype, d.frlong as d_frlong, d.frlat as d_frlat, d.tolong as d_tolong, d.tolat as d_tolat, p.polylong, p.polylat, p.water ,e.rtsq, e.long1, e.lat1, e.long2, e.lat2, e.long3, e.lat3, e.long4, e.lat4, e.long5, e.lat5, e.long6, e.lat6, e.long7, e.lat7, e.long8, e.lat8, e.long9, e.lat9, e.long10, e.lat10 FROM (((( ( rt7 as a inner join rt8 as b on a.land = b.land ) inner join rti c on ( (b.cenid = c.cenidr and b.polyid = c.polyidr)or(b.cenid = c.cenidl and b.polyid = c.polyidl)) ) inner join rt11 as d on c.tlid = d.tlid) inner join rtp as p on p.cenid = b.cenid and p.polyid = b.polyid )) left join rt2 as e on d.tlid = e.tlid WHERE a.laname like 'Mill Pond%' and (( 3958.682 ) * ( acos( sin( (d.frlat) * 0.01745 ) * sin( ( $latc ) * 0.01745 ) + cos( (d.frlat) * 0.01745 ) * cos( ( $latc) * 0.01745 ) * cos( (d.frlong - ($longc) ) * 0.01745 ) ) )) <=$mile ORDER BY a.laname

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      Writing a GIS System? From my experience trig functions are expensive so you should cut down the amount of data that has to be calculated. To do this, recreate your existing query (without the trig functions) as a subquery, replacing the trig functions with a very basic bounding box - this will cut out a vast quantity of data quickly. You are now left with just a subset of the original data, your outer query can now perform the trig operations on a much smaller set of data. As for the joins, I'm assuming that these id fields are all primary keys and indexed by default, you may want to index the foreign key side of them to see if it speeds up the query also. However, from experience, I'd say the trig functions are where your bottle neck is.


      "If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!

      1 Reply Last reply
      0
      • R rkyawal

        I have problem with this query.. it is taking too much time to fetch the records .. can anybody tell me general solution on this. is their any problem in any join ? i have main problem in the following condition ( (b.cenid = c.cenidr and b.polyid = c.polyidr)or(b.cenid = c.cenidl and b.polyid = c.polyidl)) if only one condition is used then it gives result very fast so help me .. SELECT a.laname, a.cfcc, b.cenid, b.polyid, c.tlid, d.fename, d.fetype, d.frlong as d_frlong, d.frlat as d_frlat, d.tolong as d_tolong, d.tolat as d_tolat, p.polylong, p.polylat, p.water ,e.rtsq, e.long1, e.lat1, e.long2, e.lat2, e.long3, e.lat3, e.long4, e.lat4, e.long5, e.lat5, e.long6, e.lat6, e.long7, e.lat7, e.long8, e.lat8, e.long9, e.lat9, e.long10, e.lat10 FROM (((( ( rt7 as a inner join rt8 as b on a.land = b.land ) inner join rti c on ( (b.cenid = c.cenidr and b.polyid = c.polyidr)or(b.cenid = c.cenidl and b.polyid = c.polyidl)) ) inner join rt11 as d on c.tlid = d.tlid) inner join rtp as p on p.cenid = b.cenid and p.polyid = b.polyid )) left join rt2 as e on d.tlid = e.tlid WHERE a.laname like 'Mill Pond%' and (( 3958.682 ) * ( acos( sin( (d.frlat) * 0.01745 ) * sin( ( $latc ) * 0.01745 ) + cos( (d.frlat) * 0.01745 ) * cos( ( $latc) * 0.01745 ) * cos( (d.frlong - ($longc) ) * 0.01745 ) ) )) <=$mile ORDER BY a.laname

        E Offline
        E Offline
        EdbertP
        wrote on last edited by
        #3

        Try using UNION to solve the INNER JOIN condition. Here's how it should be like: SELECT ... FROM ... INNER JOIN rtiC ON b.cenid = c.cenidr AND b.polyid = c.polyidr ... UNION SELECT ... FROM ... INNER JOIN rtiC ON b.cenid = c.cenidl AND b.polyid = c.polyidl ...

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups