June 28, 2010 at 1:16 pm
I have a table with about two billion rows in it, every night we query for the row count. It takes about 5-6mins for it to come back. Here is the query I use:
SELECT SUM(1)
FROM BALEOD2009 (nolock)
WHERE EODDate >= 20081228
I know you can use sys index views to get this also but have read it isnt very accurate. Any suggestions on speeding this up? It is already indexed, I haven't partitioned the table yet though.
June 28, 2010 at 2:02 pm
Simply way Through Management studio you ca get the row count.
right click on the table ->properties -> Storage -> General -> Row count.
You will get the row count very quickly through UI.
Regards
Hema.,
Regards
Hema.,
June 28, 2010 at 2:15 pm
Any particular reason for not using COUNT(*)?
But more interestingly: is there any index available supporting the WHERE clause?
If not, can you change it to benefit from an existing index (e.g. get the corresponding edit: clustered narrow index value for EODDate = 20081228) and use the clustered index column in your WHERE clause?
June 28, 2010 at 2:20 pm
lmu92 (6/28/2010)
Any particular reason for not using COUNT(*)?But more interestingly: is there any index available supporting the WHERE clause?
If not, can you change it to benefit from an existing index (e.g. get the corresponding edit:
clusterednarrow index value for EODDate = 20081228) and use theclusteredindex column in your WHERE clause?
And what's the datatype of the EODDate column... INT?
--Jeff Moden
Change is inevitable... Change for the better is not.
June 28, 2010 at 2:22 pm
There is no gain with using Count(*), yup everything is running on an index
June 28, 2010 at 2:23 pm
EODDate is an int atm, I am working on some tests to see if changing it will help but the date is used as an int thoughout the database. I have another post.
June 28, 2010 at 2:45 pm
Jason Messersmith (6/28/2010)
There is no gain with using Count(*), yup everything is running on an index
Can you post the create index script for the related index?
June 28, 2010 at 2:50 pm
lmu92 (6/28/2010)
Jason Messersmith (6/28/2010)
There is no gain with using Count(*), yup everything is running on an indexCan you post the create index script for the related index?
Here is the table:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[BALEOD2009](
[SkuNumber] [bigint] NOT NULL,
[Store] [int] NOT NULL,
[OnHand] [float] NULL,
[RecieptAmtPTD] [float] NULL,
[RecieptAmtYTD] [float] NULL,
[AverageCost] [float] NULL,
[RegCstAmtPTD] [float] NULL,
[RegCstAmtYTD] [float] NULL,
[AdCstAmtPTD] [float] NULL,
[AdCstAmtYTD] [float] NULL,
[AverageCost1] [float] NULL,
[LandedCost] [float] NULL,
[IsType] [varchar](50) NULL,
[IATRB4] [varchar](50) NULL,
[EODDate] [int] NOT NULL,
[ProcessDate] [int] NULL,
[CounterType] [varchar](50) NULL,
[RegularRetail] [float] NULL,
[PromoRetail] [float] NULL,
[IATRB1] [varchar](50) NULL,
[IFINLN] [varchar](50) NULL,
[INTRANSIT] [float] NULL,
[StoreSelect] [varchar](50) NULL,
[LastUpdateDate] [datetime] NULL
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
ALTER TABLE [dbo].[BALEOD2009] ADD CONSTRAINT [DF_BALEOD20091_LastUpdateDate] DEFAULT (getdate()) FOR [LastUpdateDate]
GO
The index:
CREATE NONCLUSTERED INDEX [Idx_BALEOD20091EODDate] ON [dbo].[BALEOD2009]
(
[EODDate] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
The plan is also attached.
June 28, 2010 at 3:02 pm
Is the table a heap or did you just omit the clustered index?
June 28, 2010 at 3:04 pm
Lamprey13 (6/28/2010)
Is the table a heap or did you just omit the clustered index?
The other index on it is clustered,
CREATE UNIQUE CLUSTERED INDEX [Idx_BALEOD20091SkuStoreEOD] ON [dbo].[BALEOD2009]
(
[EODDate] ASC,
[Store] ASC,
[SkuNumber] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
June 28, 2010 at 3:20 pm
Jason Messersmith (6/28/2010)
EODDate is an int atm, I am working on some tests to see if changing it will help but the date is used as an int thoughout the database. I have another post.
Except for the fact that I'm generally against using INT to store ISO dates, there's no need to change it here because it won't help for this particular task. I just wanted to make sure we didn't have any implicit conversions going on in the table side.
--Jeff Moden
Change is inevitable... Change for the better is not.
June 28, 2010 at 3:26 pm
The SQLPlan you posted seems to be an "estimated" plan... can you include an "Actual" plan?
--Jeff Moden
Change is inevitable... Change for the better is not.
June 28, 2010 at 3:29 pm
Jeff Moden (6/28/2010)
@Jason,The SQLPlan you posted seems to be an "estimated" plan... can you include an "Actual" plan?
done.
June 28, 2010 at 3:35 pm
Jeff Moden (6/28/2010)
Except for the fact that I'm generally against using INT to store ISO dates, there's no need to change it here because it won't help for this particular task. I just wanted to make sure we didn't have any implicit conversions going on in the table side.
I'm not sure if in this case storing EODDate as SQL2008 DATE format would help since it would "shrink" the index pages to be scanned by 25% (4 byte for INT vs. 3 byte for DATE). Maybe even based on a persisted computed column, if the additional space can be tolerated...
June 28, 2010 at 3:43 pm
lmu92 (6/28/2010)
Jeff Moden (6/28/2010)
Except for the fact that I'm generally against using INT to store ISO dates, there's no need to change it here because it won't help for this particular task. I just wanted to make sure we didn't have any implicit conversions going on in the table side.
I'm not sure if in this case storing EODDate as SQL2008 DATE format would help since it would "shrink" the index pages to be scanned by 25% (4 byte for INT vs. 3 byte for DATE). Maybe even based on a persisted computed column, if the additional space can be tolerated...
The indexes are 40gb, however the table its self is 330+gb
Viewing 15 posts - 1 through 15 (of 33 total)
You must be logged in to reply to this topic. Login to reply