i'm using TPC-H (SF 10) on my SQL Server 2014 database system. In order to improve query performance I decided to partition (same disk) two of the biggest tables (Lineitem and Orders) by the date column, cause many of those queries use a date range. First i decided to use a weekly partition scheme and afterwards i used a monthly scheme. I used on each table a clustered column store index. I executed the first TPC-H query:
SELECT L_RETURNFLAG,
L_LINESTATUS,
SUM(L_QUANTITY) AS SUM_QTY,
SUM(L_EXTENDEDPRICE) AS SUM_BASE_PRICE,
SUM(L_EXTENDEDPRICE*(1-L_DISCOUNT)) AS SUM_DISC_PRICE,
SUM(L_EXTENDEDPRICE*(1-L_DISCOUNT)*(1+L_TAX)) AS SUM_CHARGE,
AVG(L_QUANTITY) AS AVG_QTY,
AVG(L_EXTENDEDPRICE) AS AVG_PRICE,
AVG(L_DISCOUNT) AS AVG_DISC,
COUNT_BIG(*) AS COUNT_ORDER
FROM LINEITEM
WHERE L_SHIPDATE <= dateadd(dd, - 94, cast('1998-12-01'as date))
GROUP BY L_RETURNFLAG,
L_LINESTATUS
ORDER BY L_RETURNFLAG,
L_LINESTATUS;
I got the following results for the query above.
- weekly partitioning
- Partitions accessed 348 (1..348) ( Total 361 partitions)
- (862194 rows were not read cause they are in the last partitions)
- Logical reads: 1381
- Lob logical reads: 109005
- Lob physical reads: 1371
- Lob read-ahead reads: 200554
- Execution time: 2807 ms
- Compile CPU: 43
- Compile Time: 43
Compile Memory: 1408
monthly partitioning
- Partitions accessed 80 (1..80) ( Total 84 partitions)
- (881.087 rows were not read cause they are in the last partitions)
- Logical reads: 2902
- Lob logical reads: 617554
- Lob physical reads: 388
- Lob read-ahead reads: 260486
- Execution time: 2680 ms
- Compile CPU: 12
- Compile Time: 12
- Compile Memory: 872
The biggest difference between them is the number of batches which were used. There were around 333.201 Batches used for the execution of the index scan under weekly partitioning and just 191.275 under monthly partitioning.
I'm a bit confused about this results. I expected the first execution (weekly partition) would be faster than the second one cause of fewer reads operation. The lob logical reads on the monthly partitioned tables are significantly higher, but the execution time, compile CPU, time and memory are lower. So i would think that the monthly partitioning is more efficient. The results of the other queries look almost the same :( .Could anyone help me to understand whats happening here?
So, i just did the tests once again with maxdop 1. Here are my results:
Weekly partitioning
- logical reads: 1381
- lob logical reads: 108619
- lob physical reads: 1362
- lob read-ahead reads: 200664
Monthly partitioning
- logical reads: 739
- lob logical reads: 94901
- lob physical reads: 402
- lob read-ahead reads: 262598
This is the execution plan, it looks exactly the same for both exections, here are some further details:
https://i.stack.imgur.com/293oN.png
The difference between the number of read operations isn't as big as before and there are more physical reads under weekly partitioning. Furthermore there are more logical reads under weekly partitioning. That's exactly the opposite of what i expected :/.
Execution plan, (monthly partitioning) I created a CI first and a clustered columnstore index afterwards (with drop existing = on and maxdop 1)