<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[FrontAccounting forum — Slow query in Invoice Against Sales Delivery menu]]></title>
	<link rel="self" href="https://frontaccounting.com/punbb/extern.php?action=feed&amp;tid=4528&amp;type=atom" />
	<updated>2013-11-22T06:38:03Z</updated>
	<generator>PunBB</generator>
	<id>https://frontaccounting.com/punbb/viewtopic.php?id=4528</id>
		<entry>
			<title type="html"><![CDATA[Re: Slow query in Invoice Against Sales Delivery menu]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=18517#p18517" />
			<content type="html"><![CDATA[<p>Updated <a href="https://github.com/apmuthu/frontaccounting/commit/854c8067faa29399b655ac317d0d1ace48c3c622">my personal GitHub Repo</a>.</p><p>Patch attached here.</p>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2013-11-22T06:38:03Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=18517#p18517</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Slow query in Invoice Against Sales Delivery menu]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=18515#p18515" />
			<content type="html"><![CDATA[<p>Thank you for your response. Now I feel confident to add the index into my production system.</p><p>I&#039;ll try to implement the query optimization too.</p>]]></content>
			<author>
				<name><![CDATA[mfaa98]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=17843</uri>
			</author>
			<updated>2013-11-22T04:46:14Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=18515#p18515</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Slow query in Invoice Against Sales Delivery menu]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=18501#p18501" />
			<content type="html"><![CDATA[<p>Must we now add the following in:<br /></p><div class="codebox"><pre><code>ALTER TABLE `0_debtor_trans` ADD INDEX `Order` (`order_`);</code></pre></div><p>We also need to optimise the query in the function at line 364 in <strong>sales/includes/db/cust_trans_db.inc</strong> to be:<br /></p><div class="codebox"><pre><code>function get_sql_for_sales_deliveries_view($selected_customer, $selected_stock_item=null)
{
    $sql = &quot;SELECT trans.trans_no,
            debtor.name,
            branch.branch_code,
            branch.br_name,
            sorder.deliver_to,
            trans.reference,
            sorder.customer_ref,
            trans.tran_date,
            trans.due_date,
            (ov_amount+ov_gst+ov_freight+ov_freight_tax) AS DeliveryValue,
            debtor.curr_code,
            Sum(line.quantity-line.qty_done) AS Outstanding,
            Sum(line.qty_done) AS Done
        FROM &quot;
         .TB_PREF.&quot;sales_orders as sorder LEFT JOIN &quot;
         .TB_PREF.&quot;debtor_trans as trans 
            ON (sorder.order_no = trans.order_) LEFT JOIN &quot;
         .TB_PREF.&quot;debtor_trans_details as line 
            ON (line.debtor_trans_no = trans.trans_no
                AND line.debtor_trans_type = trans.type) LEFT JOIN &quot;
         .TB_PREF.&quot;debtors_master as debtor
            ON (trans.debtor_no = debtor.debtor_no) LEFT JOIN &quot;
         .TB_PREF.&quot;cust_branch as branch 
            ON (trans.branch_code = branch.branch_code
                AND trans.debtor_no = branch.debtor_no)
        WHERE
            trans.type = &quot;.ST_CUSTDELIVERY;</code></pre></div>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2013-11-21T16:37:49Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=18501#p18501</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Slow query in Invoice Against Sales Delivery menu]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=18442#p18442" />
			<content type="html"><![CDATA[<p>I have problem in Invoice Against Sales Delivery menu. It displays correctly, but the query is long (in my localhost experience, about 9 seconds).</p><p>After looking at the query and the database, there was small issues in the field order_ at table debtor_trans. The order_ field is not indexed. So after I add the index, the query now run normally (under half second)</p><p>Is it intended not to create index for field order_ or is it a performance bug?</p><p>Thank you.<br />Sorry for my bad English.</p>]]></content>
			<author>
				<name><![CDATA[mfaa98]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=17843</uri>
			</author>
			<updated>2013-11-13T23:29:03Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=18442#p18442</id>
		</entry>
</feed>
