我正在开发一个数据库,目前总共存储了788个数据并且随着时间的推移不断增加。
我的代码如下:
// Export TO CSV
$('#button2').click(function () {
var chart = $('#container').highcharts();
chart.downloadCSV();
});
// Export TO XLS
$('#button3').click(function () {
var chart = $('#container').highcharts();
chart.downloadXLS();
});
每次运行此代码时,加载所有值总是需要10分钟或更长时间。我尝试制作相同代码的SQL视图,但是当我运行它时,错误exporting: {
filename: 'chart'
}
总是显示。
我想知道:
我正在努力学习优化,因为我注意到当我进行查询时,通常需要花费大量时间来加载并有时产生错误SELECT DISTINCT R.remarks, R.payerId, R.payername, R.payeraddress, R.collectorName, R.serialno, OOI.phone_no, CR.cr_no, F.application_no, R.series, R.txndate, R.amount, T.toda_name, B.brand_name, M.motor_no, M.chassis_no,
M.plate_no, F.date_issue, M.year_model, M.body_color, OOI.ice_person_name, OOI.ice_person_address, OOI.ice_person_contact_no, M.motor_id, F.franchise_id, LEFT(R.remarks, 4) AS franchise_no, SUBSTRING(R.remarks,
CHARINDEX('|', R.remarks) + 1, LEN(R.remarks)) AS motor_noremarks
FROM etracs_tayabas.dbo.Receipt AS R INNER JOIN
etracs_tayabas.dbo.ReceiptItem AS RI ON RI.parentid = R.objid INNER JOIN
etracs_tayabas.dbo.IncomeAccount AS IA ON IA.objid = RI.acctid LEFT OUTER JOIN
dbo.vfTA_tblMotor AS M ON M.motor_no = SUBSTRING(R.remarks, CHARINDEX('|', R.remarks) + 1, LEN(R.remarks)) LEFT OUTER JOIN
dbo.vfTA_tblOperatorOtherInfo AS OOI ON OOI.operator_id = R.payerId LEFT OUTER JOIN
dbo.vfTA_tblCertificateOfRegistration AS CR ON CR.motor_id = M.motor_id LEFT OUTER JOIN
dbo.vfTA_tblFranchise AS F ON F.or_id = R.objid LEFT OUTER JOIN
dbo.vfTA_tblTODA AS T ON T.toda_id = M.toda_id LEFT OUTER JOIN
dbo.vfTA_tblReconciledTaxpayer AS RT ON RT.payer_id = R.payerId LEFT OUTER JOIN
dbo.vfTA_tblBrand AS B ON B.brand_id = M.brand_id
WHERE (IA.objid = 'FTFA00000242') AND (F.franchise_id IS NULL) AND (R.voidId IS NULL) AND (R.remarks IS NOT NULL) AND (RT.rtp_id IS NULL)
我目前对此很新。提前谢谢。
答案 0 :(得分:0)
我认为对这么多列使用DISTINCT会花费很多。这对你的查询真的有用吗?
我也想知道以下部分。
LEFT OUTER JOIN dbo.vfTA_tblMotor AS M ON M.motor_no = SUBSTRING(R.remarks, CHARINDEX('|', R.remarks) + 1, LEN(R.remarks))
这意味着没有办法将INDEX用于此关系。如何将列添加到表etracs_tayabas.dbo.Receipt,其中存储子字符串结果,并在将记录插入/更新到表时计算它。通过这种方式,您可以为此关系创建INDEX,并可以优化JOIN的那一部分。