Help Optimizing Query

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default Help Optimizing Query

    Just looking to see if anyone has any pointers on how i can optimize this
    query... it is taking about a minute to show the data, and even though its not
    terribly long, it would still be better if it was quicker ( i am hearing
    reports that people are trying to refresh the page after 30 secs or so. ive
    tried to figure out if i can "flush" something, but i dont know if its possible
    to flush during a query or even output. i flush it in the begining and display
    a message that says "Wait..." which i would love to get rid of after the data
    is ready, not sure how to do this but, i think it would need to be a layer or
    something that shows and hides the layer. But without further ado... the query.



    <cfquery name="rsGetApplicants" datasource="standard">
    SELECT * FROM
    informix.styhmpf f, OUTER informix.styemplr e
    WHERE f.empl_code = e.empl_code
    ORDER BY FIRST_NAME, LAST_NAME, hmpfID
    </cfquery>

    elDonrico Guest

  2. Similar Questions and Discussions

    1. Help in optimizing a slow query...
      Hello, I'm trying since weeks (with no luck...) to optimize a query which is "killing" my site on peak times (100+ visitors simultaneously). I...
    2. Tools for optimizing mysql query
      I have googled a lot, but couldn't find it. But, I hope that there will be a tool for query optimization (a tool that can automatically detect the...
    3. Optimizing PDF
      Hey, I have a pdf that i am trying to optimize because it is 14 megs in size. WHen i use the pdf optimizer, i get an message that says "THe...
    4. Optimizing for CD playback
      I'm working on a Director Movie the final will be distributed on a CD as a projector file. The presentation is 4-5 minutes long and will consist...
    5. Optimizing Query
      Can anybody tell me how to improve the performance of this query? SELECT NID, LEVEL, VALUE FROM DATA WHERE DID=2 AND STATUS=0 The value of...
  3. #2

    Default Re: Help Optimizing Query

    SELECT * may be the culprit. Do you really need every field from the table? Is your database on the ColdFusion server? If not, what is the bandwidth between the CF server and the Informix server?
    jdeline Guest

  4. #3

    Default Re: Help Optimizing Query

    ok, i can understand that... i need every field from styhmpf (the name is my
    way of rebelling against the YAT, yet another table, which i felt was
    unnecessary - hmpf) but, i only really need the person's name out of the
    styemplr table.

    and no, the cf server is a win 2003 zeon and the informix db is a win NT4 on
    dual P3 the connection is 100BaseT (is 1000 that much better folks?)


    elDonrico Guest

  5. #4

    Default Re: Help Optimizing Query

    Not familiar with informix but possibly some of the following could help:
    1.Did you check how much time takes for query itself using debagger ot iin
    database?
    2.Check if empl_code is indexed column in both tables and if not index them.
    3.Do you really need to order by FIRST_NAME?

    CF_Oracle Guest

  6. #5

    Default Re: Help Optimizing Query

    sorry to sound like an idiot, but i have no idea how to index a column... i'lve
    never used CFDebugger, but, i'll check it out and see what i can come up with
    .... and does it really take more time to order it by the first name? i would
    suppose than that the ID would be the quickest than?


    thanks for the tips.

    elDonrico Guest

  7. #6

    Default Re: Help Optimizing Query

    First, get rid of the select * as was mentioned earlier. Second, how may records are there? It could be that the query is quick but you are returning so much data that the browser is slow.
    Dan Bracuk Guest

  8. #7

    Default Re: Help Optimizing Query

    i'm already doing this to time it

    <cfset tick = GetTickCount()>
    <cfquery>... </cfquery>

    <cfset tock = GetTickCount()>
    <cfset total = (tock - tick)/1000>
    <cfif total GTE 60>
    <cfset timetook = total/60>
    <cfelse>
    <cfset timetook = total>
    </cfif>

    and the #total# is the same as if i had a stopwatch on it. its like once the
    data is there, its outputted.

    elDonrico Guest

  9. #8

    Default Re: Help Optimizing Query

    so Dan,

    is it that even though you are only displaying like 200 on the first page which i am, it has to wait on the other 2000 for the other pages?
    elDonrico Guest

  10. #9

    Default Re: Help Optimizing Query

    HOLY $#17

    taking out the * moved it to 27.3 sec... thanks guys... thats what i was looking for.
    elDonrico Guest

  11. #10

    Default Help Optimizing Query

    I am using Access. I have two tables, Categpries and Items. I have 4 categories
    and 11 items. The Categories are referenced through the Items table by their
    ID. I want the query to pull only the Categories that have active Items
    available. I know that I have 4 active Categories and all are referenced in 11
    active Items. Thus, the following query pulls 11 records instead of 4. The idea
    is that if there are 4 Categories in the Table, but one of them does not have
    any active items associated, it will not be a part of the query.

    <cfquery name="getCatalogCategories" datasource="#DSN#">
    SELECT CatalogCategories.*, CatalogItems.ImageFile AS ItemImageFile FROM
    CatalogCategories, CatalogItems WHERE CatalogCategories.Active = yes AND
    CatalogItems.Active AND CatalogCategories.CategoryID =
    CatalogItems.CategoryReference ORDER BY CatalogCategories.Name
    </cfquery>

    Thanks in advance for your help.

    UpstateWeb Guest

  12. #11

    Default Re: Help Optimizing Query

    Try something like the code below.



    <CFQUERY NAME="getCategories" ...>
    SELECT DISTINCT CatalogItems.categoryId FROM CatalogItems
    </CFQUERY>
    <CFSET activeCategories = ValueList(getCategories.categoryId)>
    <!--- you can now use activeCategories in the WHERE clause of your query, or
    you can include this above query into your WHERE clause. --->

    jdeline Guest

  13. #12

    Default Re: Help Optimizing Query

    Wouldn't you want to check to see if <b>CatalogItems.Active = Yes</b>? You
    aren't doing that in your query, at least as posted:

    <cfquery name="getCatalogCategories" datasource="#DSN#">
    SELECT CatalogCategories.*,
    CatalogItems.ImageFile AS ItemImageFile
    FROM CatalogCategories, CatalogItems
    WHERE CatalogCategories.Active = yes
    AND CatalogItems.Active <b><---------right here</b>
    AND CatalogCategories.CategoryID = CatalogItems.CategoryReference
    ORDER BY CatalogCategories.Name
    </cfquery>

    Phil

    paross1 Guest

  14. #13

    Default Re: Help Optimizing Query

    I did add the =active and it didn't change the outcome. Thanks any way....
    UpstateWeb Guest

  15. #14

    Default Re: Help Optimizing Query

    Well, I guess I was looking for a solution that was more complicated then it
    needed to be. Although, I had to run 3 queries to get it to all work. I still
    think there is a way to use only one query and optimize it.

    Thanks for your help,

    David G. Moore, Jr.

    UpstateWeb Guest

  16. #15

    Default Re: Help Optimizing Query

    Look into LEFT JOINS and use a WHERE right-hand side match-key IS NOT NULL. This will return ONLY left-sides that actually have something on the right.
    JMGibson3 Guest

  17. #16

    Default Re: Help Optimizing Query

    <blockquote>quote:<br><hr><i>Originally posted by: <b><b>UpstateWeb</b></b></i>
    Well, I guess I was looking for a solution that was more complicated then it
    needed to be. Although, I had to run 3 queries to get it to all work. I still
    think there is a way to use only one query and optimize it.
    Thanks for your help,
    David G. Moore, Jr.<hr></blockquote>
    Like this?
    select somefields
    from catalogcategory -- but not catalogitems
    where categoryid in
    (select categoryid
    from catalogitems)

    If you only want one row for each category, do not select anything from the
    items table.


    Dan Bracuk Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139