简体   繁体   English

PHP的SQL Fetch查询优化

[英]php sql fetch query optimization

I am working with PHP and Oracle. 我正在使用PHP和Oracle。 While executing queries I am using oci_set_prefetch() method before oci_execute() for fast fetching. 在执行查询我使用oci_set_prefetch()方法之前oci_execute()快速抓取。 As my output is large I am setting it to 1000 . 由于我的输出很大,因此将其设置为1000 Though time for whole execution is now less but still not satisfactory. 虽然整个执行的时间现在减少了,但仍然不能令人满意。 Same query if run on database directly brings data in 2-3 seconds whereas while executing through PHP methods it takes much more time. 如果在数据库上运行,则相同的查询将在2-3秒内直接带来数据,而通过PHP方法执行则需要更多时间。

Is there any other method for reducing this fetch time ? 还有其他减少此获取时间的方法吗?

Thanks in advance 提前致谢

Your setting of the oci_set_prefetch parameter is increasing the latency of your query; 您对oci_set_prefetch参数的设置增加了查询的延迟。 that is, the delay between the time you issue the query and the time you get your first results. 也就是说,从发出查询到获得第一个结果之间的延迟。 You've instructed Oracle to wait until it has 1000 rows of data before starting to send them to PHP. 您已经指示Oracle等待直到它具有1000行数据,然后才能开始将它们发送到PHP。 It is diligently following your instructions. 它正在严格按照您的指示进行。

You see a fast result in sql*plus or whatever interactive query client you're using because you see the first row of your resultset fairly quickly, and you're fooled into thinking the whole query is fast because the results are spewing past you. 您会在sql * plus或正在使用的任何交互式查询客户端中看到快速结果,因为您很快就看到了结果集的第一行,并且由于结果冒出了您而愚蠢地认为整个查询都是快速的。

Do you need the whole thousand rows? 您需要整行吗? Try turning off the prefetch parameter and see if you get more favorable results. 尝试关闭prefetch参数,看看是否获得了更好的结果。 Try limiting the length of your resultset with AND ROWNUM <= 10 or some such thing, and see if it helps. 尝试使用AND ROWNUM <= 10或类似的方法限制结果集的长度,然后查看是否有帮助。

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

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