Question

I have a PHP application that pulls order information based on a scanned/entered order number for order pulling purposes. We're using Pervasive SQL but syntax is identical to MS SQL.

I have a couple of smaller queries used to break kit items down into component items that are called as needed, but they're simple and fast to execute. My problem is our main query that most needed information is stuffed into. It's fast for most orders since they're relatively small (1-15 items or so). My problem is with large orders (e.g. wholesale) that may end up being 100+ items.

I realize that the more information needed the longer it will take to execute a query, but I'm hoping there is room in my query to optimize it further.

Does anyone see anything in the following query that I can optimize to speed things up for large orders?

SELECT 
    oeordh.orduniq, 
    oeordh.customer, 
    oeordh.ordnumber, 
    oeordh.orddate, 
    oeordh.salesper1, 
    oeordd.orduniq, 
    oeordd.item, 
    oeordd.pickseq, 
    oeordd.location, 
    oeordd.origqty, 
    arcus.idcust, 
    arcus.idgrp 

FROM oeordh 
    INNER JOIN oeordd ON oeordh.orduniq = oeordd.orduniq
    INNER JOIN arcus ON oeordh.customer = arcus.idcust

WHERE 
    oeordh.ordnumber = '".$_POST['barcode']."' 

ORDER BY oeordd.pickseq`
Was it helpful?

Solution

You can't get it better than that, check that every value you look up on (including joins) have indices and that you don't run a query for every item, make sure you request all the items (that are pertinent to the current page) at the same time and then process them on the client side.

Basically, it's not a query issue, it's either your code that uses the query results or the database design (or the network, but that's most likely beyond your control).

I feel I should mention the glaring security hole in that line of code also, but I'm sure you get that a lot.

Edit: I actually thought of something, if those fields aren't varchar, you should rtrim() them on the server side instead of sending thousands and thousands (or more) of spaces at the end of every column.

OTHER TIPS

You probably can't get better than that. My professor in a database course once said "Don't try to be clever. The RDMS is good at optimizing" - except for one thing, RDMS doesn't sets indexes automagically. So, Be sure that you have indexes on those fields you are sorting on, joining on and selects on (selects like in the "where" clause).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top