【发布时间】:2017-08-16 07:37:47
【问题描述】:
我有一个非常简单的查询,我正在 Azure SQL 数据仓库中运行,但它需要大约 40 秒才能执行。
表定义:
CREATE TABLE dbo.orders
(
location_code VARCHAR(8) NOT NULL,
order_date DATETIME NOT NULL,
order_status_code INT NOT NULL,
order_type_code VARCHAR(1) NULL,
coupon_code VARCHAR(8) NULL,
coupon_amount MONEY NOT NULL,
subtotal MONEY NOT NULL,
total_amount MONEY NULL,
order_number INT NOT NULL,
customer_code INT NOT NULL
)
WITH
(
DISTRIBUTION = ROUND_ROBIN,
CLUSTERED COLUMNSTORE INDEX
)
查询是:
SELECT location_code,
order_date,
order_status_code,
order_type_code,
coupon_code,
coupon_amount,
subtotal,
total_amount,
order_number,
customer_code
FROM orders WITH (nolock)
WHERE order_date >= '2016-04-01'
AND order_date <= '2016-04-30'
AND order_status_code < 99
表中有 13,083,667 条记录。任何人都可以帮助我优化这个。我为此提供了 100 个 DWU。
提前致谢。
【问题讨论】:
-
在 ssms 中,右键单击表并“将其编写为创建到新查询窗口的脚本”。也请发布该脚本,以便我们可以看到表 def 和索引
-
也共享执行计划,表中的行数
-
你好 caius,请在下面找到表的结构:创建表 Orders( [Location_Code] [varchar](8) NOT NULL,[Order_Date] [datetime] NOT NULL,[Order_Status_Code] [int] NOT NULL,[Order_Type_Code] [varchar](1) NULL,[Coupon_Code] [varchar](8) NULL, [Coupon_Amount] [money] NOT NULL,[SubTotal] [money] NOT NULL,[Total_Amount] [money] NULL ,[Order_Number] [int] NOT NULL,[Customer_Code] [int] NOT NULL) WITH(DISTRIBUTION = ROUND_ROBIN,CLUSTERED COLUMNSTORE INDEX)
-
@thegameiswar 表中的行数为 13083667。
-
@Deepanshu:请看这个链接,了解如何改进问题:spaghettidba.com/2015/04/24/…
标签: sql azure azure-sql-database sql-data-warehouse