临时表来加速此查询

时间:2016-08-09 15:45:32

标签: sql sql-server performance

将job_price_line加入job_price_hdr后,此基本查询抛出System.OutOfMemoryException错误

创建临时表会加快此查询吗?我不理解我在这个主题上读过的其他解释。谢谢!

select
oe_line.qty_invoiced,
invoice_hdr.invoice_no,
invoice_hdr.invoice_date,
invoice_line.unit_price,
invoice_line.item_desc,
invoice_line.customer_part_number,
invoice_line.pricing_unit,
invoice_hdr.ship_to_id,
invoice_hdr.po_no,
invoice_hdr.ship_to_id,
invoice_line.item_id,
invoice_hdr.customer_id,
job_price_hdr.contract_no,
job_price_hdr.cancelled,
job_price_line.line_no,
invoice_hdr.sales_location_id

from invoice_hdr

join invoice_line on invoice_line.invoice_no = invoice_hdr.invoice_no
join oe_line on  oe_line.order_no = invoice_hdr.order_no

join job_price_hdr on job_price_hdr.corp_address_id = invoice_hdr.corp_address_id
join job_price_line on job_price_line.job_price_hdr_uid = job_price_hdr.job_price_hdr_uid

where invoice_hdr.invoice_date between ('2016-05-02') and ('2016-05-03')
and job_price_hdr.cancelled = 'N'
and invoice_hdr.sales_location_id = '200'

1 个答案:

答案 0 :(得分:1)

无论速度如何都能解决内存不足异常。看起来您的上一次加入已经大大增加了您返回的记录数量。尝试使用count(*)替换字段列表,以查看您首先获取的记录数。