简体   繁体   English

SQL查询优化(Pervasive)

[英]SQL query optimization (Pervasive)

I have a PHP application that pulls order information based on a scanned/entered order number for order pulling purposes. 我有一个PHP应用程序,它根据扫描/输入的订单号提取订单信息,以便进行订单提取。 We're using Pervasive SQL but syntax is identical to MS SQL. 我们使用的是Pervasive SQL,但语法与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). 大多数订单都很快,因为它们相对较小(1-15件左右)。 My problem is with large orders (eg wholesale) that may end up being 100+ items. 我的问题是大订单(例如批发)可能最终成为100多件商品。

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`

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. 编辑:我实际上想到了一些东西,如果这些字段不是varchar ,你应该在服务器端rtrim()它们而不是在每一列的末尾发送成千上万的(或更多)空格。

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. 我在数据库课程中的教授曾经说过“不要试图变得聪明.RTMS擅长优化” - 除了一件事,RDMS不会自动设置索引。 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). 因此,请确保您在要排序的那些字段上有索引,加入并选择(在“where”子句中选择)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM