SQL Server Compact 查询运行了大约 45 分钟
SQL Server Compact query runs for around 45 mins
SELECT
tbl_sale.SALES_ID,
tbl_sale.Sales_Date,
tbl_sale.Sales_Time,
tbl_users.user_name,
tbl_sale.customer_id,
tbl_customer.customer_name,
tbl_sale.grand_disc,
tbl_sale.collection_full,
tbl_sale.term_of_payment,
tbl_sale.consin1,
tbl_sale.consin2,
tbl_sale.narration,
tbl_sale_details.item_id,
tbl_item.item_name,
tbl_sale_details.quantity,
tbl_sale_details.cost,
tbl_sale_details.price,
tbl_sale_details.vat,
tbl_sale_details.disc,
tbl_sale_details.total_cost,
tbl_sale_details.total_price,
tbl_sale_details.sub_total
FROM
tbl_customer
INNER JOIN
tbl_sale ON tbl_customer.customer_id = tbl_sale.customer_id
INNER JOIN
tbl_users ON tbl_sale.User_ID = tbl_users.User_ID
LEFT OUTER JOIN
tbl_item
INNER JOIN
tbl_sale_details ON tbl_item.item_id = tbl_sale_details.item_id
ON tbl_sale.SALES_ID = tbl_sale_details.SALES_ID
WHERE
(tbl_sale.Sales_Date >= '1/1/2018'
AND tbl_sale.Sales_Date <= ' 08/22/2018');
我是一名学习者。我有一个 C# 代码生成两个日期之间售出的所有项目的 crystal 报告。
当日期范围较小时,大约需要 3 分钟,而大约 8 个月。
大约需要 45 分钟以上。
CPU 在我的 8 核 CPU 上使用率只有 7%。
我使用 CompactView 来测试这个查询。执行此查询时,应用程序将无响应
我读到 SQL Server Compact Edition 内连接可能很慢并尝试了左连接
我尝试在数据库中的几乎所有列上创建索引以加快速度,但它只是略有改进
例如:
CREATE INDEX idxCustId ON tbl_customer(customer_id);
现在我已经 运行 没有技巧了..
任何人都可以就我可能做错的地方提出建议吗?
在没有实际数据的情况下,很难在我这边测试这段代码......但试试这个:
SELECT tbl_sale.SALES_ID,
tbl_sale.Sales_Date,
tbl_sale.Sales_Time,
tbl_users.user_name,
tbl_sale.customer_id,
tbl_customer.customer_name,
tbl_sale.grand_disc,
tbl_sale.collection_full,
tbl_sale.term_of_payment,
tbl_sale.consin1,
tbl_sale.consin2,
tbl_sale.narration,
tbl_sale_details.item_id,
tbl_item.item_name,
tbl_sale_details.quantity,
tbl_sale_details.cost,
tbl_sale_details.price,
tbl_sale_details.vat,
tbl_sale_details.disc,
tbl_sale_details.total_cost,
tbl_sale_details.total_price,
tbl_sale_details.sub_total
FROM tbl_customer
INNER JOIN tbl_sale ON tbl_customer.customer_id = tbl_sale.customer_id
and tbl_sale.Sales_Date between '1/1/2018' and ' 08/22/2018'
INNER JOIN tbl_users ON tbl_sale.User_ID = tbl_users.User_ID
INNER JOIN tbl_sale_details ON tbl_sale.SALES_ID = tbl_sale_details.SALES_ID
LEFT OUTER JOIN tbl_item ON tbl_item.item_id = tbl_sale_details.item_id
我基本上把内部连接放在第一位,并使 WHERE 子句成为连接的一部分。这只是您可以用来加速逻辑的一些技巧。
SELECT
tbl_sale.SALES_ID,
tbl_sale.Sales_Date,
tbl_sale.Sales_Time,
tbl_users.user_name,
tbl_sale.customer_id,
tbl_customer.customer_name,
tbl_sale.grand_disc,
tbl_sale.collection_full,
tbl_sale.term_of_payment,
tbl_sale.consin1,
tbl_sale.consin2,
tbl_sale.narration,
tbl_sale_details.item_id,
tbl_item.item_name,
tbl_sale_details.quantity,
tbl_sale_details.cost,
tbl_sale_details.price,
tbl_sale_details.vat,
tbl_sale_details.disc,
tbl_sale_details.total_cost,
tbl_sale_details.total_price,
tbl_sale_details.sub_total
FROM
tbl_customer
INNER JOIN
tbl_sale ON tbl_customer.customer_id = tbl_sale.customer_id
INNER JOIN
tbl_users ON tbl_sale.User_ID = tbl_users.User_ID
LEFT OUTER JOIN
tbl_item
INNER JOIN
tbl_sale_details ON tbl_item.item_id = tbl_sale_details.item_id
ON tbl_sale.SALES_ID = tbl_sale_details.SALES_ID
WHERE
(tbl_sale.Sales_Date >= '1/1/2018'
AND tbl_sale.Sales_Date <= ' 08/22/2018');
我是一名学习者。我有一个 C# 代码生成两个日期之间售出的所有项目的 crystal 报告。
当日期范围较小时,大约需要 3 分钟,而大约 8 个月。 大约需要 45 分钟以上。
CPU 在我的 8 核 CPU 上使用率只有 7%。
我使用 CompactView 来测试这个查询。执行此查询时,应用程序将无响应
我读到 SQL Server Compact Edition 内连接可能很慢并尝试了左连接
我尝试在数据库中的几乎所有列上创建索引以加快速度,但它只是略有改进
例如:
CREATE INDEX idxCustId ON tbl_customer(customer_id);
现在我已经 运行 没有技巧了..
任何人都可以就我可能做错的地方提出建议吗?
在没有实际数据的情况下,很难在我这边测试这段代码......但试试这个:
SELECT tbl_sale.SALES_ID,
tbl_sale.Sales_Date,
tbl_sale.Sales_Time,
tbl_users.user_name,
tbl_sale.customer_id,
tbl_customer.customer_name,
tbl_sale.grand_disc,
tbl_sale.collection_full,
tbl_sale.term_of_payment,
tbl_sale.consin1,
tbl_sale.consin2,
tbl_sale.narration,
tbl_sale_details.item_id,
tbl_item.item_name,
tbl_sale_details.quantity,
tbl_sale_details.cost,
tbl_sale_details.price,
tbl_sale_details.vat,
tbl_sale_details.disc,
tbl_sale_details.total_cost,
tbl_sale_details.total_price,
tbl_sale_details.sub_total
FROM tbl_customer
INNER JOIN tbl_sale ON tbl_customer.customer_id = tbl_sale.customer_id
and tbl_sale.Sales_Date between '1/1/2018' and ' 08/22/2018'
INNER JOIN tbl_users ON tbl_sale.User_ID = tbl_users.User_ID
INNER JOIN tbl_sale_details ON tbl_sale.SALES_ID = tbl_sale_details.SALES_ID
LEFT OUTER JOIN tbl_item ON tbl_item.item_id = tbl_sale_details.item_id
我基本上把内部连接放在第一位,并使 WHERE 子句成为连接的一部分。这只是您可以用来加速逻辑的一些技巧。