Showing posts with label aggregation. Show all posts
Showing posts with label aggregation. Show all posts

Monday, March 19, 2012

Aggregations...

Here is 2 different version's of practically the same aggregation.

See images below please.

Version 1.) Smaller aggregation file size.

Version 2.) Process Index is twice as fast.

Both version's queries take the same amount of time because it seems even though I create two versions of the aggregation, SSAS creates the same aggregation data set. Any idea whats going on here, there's plus and minus' to both versions...thanks.

Version1: http://img405.imageshack.us/img405/7673/vers1og4.jpg

Version2: http://img255.imageshack.us/img255/2488/vers2mo0.jpg

Hate to bump, but no one knows whats going on here? We are using version 2...it processes much faster so we can create more aggregations.

Aggregations in Analysis Services STANDARD edition

I have fields in my cube where SUM is not a good aggregation (rate fields for example). I thought I should just set them to No aggregation, but it tells me that semi-additive aggregations are not available in Standard Edition (?). So, two questions...

1) How do I avoid representing these fields incorrectly in Standard Edition? What aggregation should they be set to? I don't want users to point Excel to them and get this big meaningless number!

2) How/Where do I produce Averages, etc? (I'm thinking that I can only do this in the Report or Excel - that it can't be done in the cube, is that right?)

Thanks for you help...

- Jim

You're correct that Standard Edition does not support semi-additive aggregations. These functions include ByAccount, AverageOfChildren, LastChild, FirstChild, LastNonEmpty, and FirstNonEmpty. If these are the right aggregations to use, you might be able to set up a calculated member that gives you something similar by going to the leaf level and then controlling the aggregation to the level your interested in. If you do this, make the measure you are "replacing" not visible to your users.

Regarding averages, store a SUM and a COUNT measure and do a ratio in a calculated member.

Good luck,
Bryan

|||

If you don't have enterprise edition, then this workaround might help:

http://solidqualitylearning.com/Blogs/dejan/archive/2006/11/08/3439.aspx

or

http://lorentsnv.spaces.live.com/blog/cns!235C78448ABCFC07!134.entry

AggregationFunction=NONE

Hello,

I want to use the AggregationFunction=None, but when I browse my cube, there are no data. Anyone ever use this aggregation function?

Thank you,
Guillaume.

Hi Guillaume,

For a measure with AggregationFunction=None, you'll only see values at the leaf level cells of the measure group, unless you're loading non-leaf fact data. Furthermore, if there are multiple fact records for a leaf-level cell, the measure value at that leaf is the sum. What I also found with a test cube is that the leaf-level values became null when I added the fact table (degenerate) dimension to the cube (maybe because the fact dimension gets added to the leaf-level?).

So, if you're working on your original problem, I would still suggest separating the max and min values into separate fields: you can then apply Max and Min aggregation functions to them.

http://msdn2.microsoft.com/en-us/library/ms175623.aspx#AggFunction

>>

None

Nonadditive

No aggregation is performed, and all values for leaf and nonleaf members in a dimension are supplied directly from the fact table for the measure group that contains the measure. If no value can be read from the fact table for a member, the value for that member is set to null.

>>

AggregationFunction = None

Hi,

this is what I find about the AggregationFunction "none":

No aggregation is performed, and all values for leaf and nonleaf members in a dimension are supplied directly from the fact table for the measure group that contains the measure. If no value can be read from the fact table for a member, the value for that member is set to null.

I understand that there will no calculated aggregation (this is quite obvious). But how can I retrieve a aggregation from a fact table? How should I design a fact table including aggregates and how do I work with that?

Thanks,

Look at:

http://www.sqlserveranalysisservices.com/default.htm

In the white paper titled: "Load Aggregate Data". I think this talks about the circumstances you are interested in.

_-_-_ Dave

|||

Dave,

thanks, I think this was the right link for me...

Aggregation within Dimension Attribute

I am trying to create kind of a running sum in a calculated member in a cube down a dimension attribute. In other words, if I had values 1-5, I would want to sum the corresponding financial values as I go down the list. See example below

Dimension Value Financial Value New Calc

1 100 525

2 50 425

3 75 375

4 100 300

5 200 200

Has anyone done anything like this?

Some more business details might help us understand your question. How does this strike you?

with
member [Measures].[New Calc] as Sum({null:[YourDimension].[Dimension Value].CurrentMember},[Measures].[Financial Value])
select {[Measures].[Financial Value], [Measures].[New Calc]} on columns,
[YourDimension].[Dimension Value].[Dimension Value].Members on rows
from YourCube

Aggregation utility for AS 2005

I've heard that an aggregation utility for "manual" aggregation design is available after installing SP2 but I did not find it. How can I run it?Hey Maxim,

Download the latest samples for SQLServer 2k5, install them, broswe to the samples directory and you'll find it. (for me it was C:\Program Files\Microsoft SQL Server\90\Samples\Analysis Services\Administrator\AggregationManager).

Chris.
|||Thank you very much!|||Could you please give a short explanation about how this works?|||Check page 117 of the Performance guide.

Aggregation utility for AS 2005

I've heard that an aggregation utility for "manual" aggregation design is available after installing SP2 but I did not find it. How can I run it?Hey Maxim,

Download the latest samples for SQLServer 2k5, install them, broswe to the samples directory and you'll find it. (for me it was C:\Program Files\Microsoft SQL Server\90\Samples\Analysis Services\Administrator\AggregationManager).

Chris.
|||Thank you very much!|||Could you please give a short explanation about how this works?|||Check page 117 of the Performance guide.

Aggregation Utility

Reading the interesting document Microsoft SQL Server 2005 Analysis Services Performance Guide, I discover the existence of an Aggregation Utility.

Wher can I download it ?

What the name of the executable ... and where it is ?

Cosimo

It's called Aggregation Manager and you can download it here as part of the SQL 2005 samples:

http://www.microsoft.com/downloads/details.aspx?familyid=e719ecf7-9f46-4312-af89-6ad8702e4e6e&displaylang=en

HTH,

Chris

|||

We have an improved version of the Agg Manager incorporated into BIDSHelper too

www.codeplex.com/bidshelper

aggregation using lastchild

Hi there

I'm using the following MDX function and it works perfect.

iif([Ledger Date].CurrentMember.Level.Name = "Year", ", [Ledger Date].CURRENTMEMBER.LASTCHILD, ([Ledger Date].CURRENTMEMBER, [Measures].[Value]))

But now I want to add another dimension namely Accout Type to the scenario containing Asset, Liabilities, Income and Expence. The lastchild must only work for "Year", "Liabilities" and "Assets"

How do I achive this?

Thank you in advance.


Try :

iif( ([Ledger Date].CurrentMember.Level.Name = "Year" and [Account Type].CurrentMember is [Account Type].[Liabilities]) or ([Ledger Date].CurrentMember.Level.Name = "Year" and [Account Type].CurrentMember is [Account Type].[Assets]) , ", [Ledger Date].CURRENTMEMBER.LASTCHILD, ([Ledger Date].CURRENTMEMBER, [Measures].[Value]))

|||

i've adjusted your suggestion to the following:

iif(([Ledger Date].CurrentMember.Level.Name = "Year" and [Ledger Entries].CurrentMember is [Ledger Entries].[Account Type].&[Asset]) ,[Ledger Date].CURRENTMEMBER.LASTCHILD, ([Ledger Date].CURRENTMEMBER, [Measures].[Value]))

but then I get the following error:

Infinite recursion detected during execution of calculated member.

any idea why?

thanks again.

Aggregation that results two columns

Hi,
I have following data coming from prior transformations.

Id Unit Name NewFlag
_

1 JacuzziBox 1
2 Hummer H2 0
3 Waste dumper 0

and so on.

I want aggregate task to result 2 fields (without any GROUP BY-ing), so that one contains total number of rows or records, and one contain total number of records with NewFlag=1.

Just wondering if it is possible by using Aggregate and how.

Thanks for your help in advance,The Aggregate transform does not support calculations based on a conditional. However, since you are using 0 and 1 as values for the NewFlag, just sum that column and you should have the right result. You'll also need to select the count(*) aggregation in the dialog. Don't select any other columns, and you will get one row with the first column containing the total rows, and the second containing the NewFlag count.

Aggregation table

Hi all

i need to create aggregation table from 2 tables group by date, any one have any idea how to create it by using SSIS

thanks & regards

Use a merge join or union all to bring your two tables together and then use the aggregate component.

Aggregation Storage Question

Hi,

I have built a cube in which the aggregation storage is about 45
GB, the cube size is 2 GB. When I look into the data folder in the
directory where Analysis Services is installed, I just see the size of
the folder corresponding to the database as 2GB. I am not able to
understand at what location the aggragations are stored, can some one
please help on this.

Also is there a way to change the location of where the cube data is
stored, let's say I want to change the storage location to a different
drive on the server, how can I accomplish that.

Thanks

Aggregation wizard allows you to specify target size of aggregations. That doesnt mean aggregations will take that much space.
In your case looks like they didnt. Or you didnt processed your aggregations after designing them. You can ether fully reprocess your partitions or you can use ProcessIndex to process only aggregations and indexes.
Here is whitepaper talking about processing options http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsql90/html/sql2k5_asprocarch.asp

Now, even after you process your aggregations, you are not guaranteed the size of real aggregations will match the estimate you saw in Aggregation Desing Wizard. The wizard only operates with estimates and not the real numbers.

As for the second question. You can change locations for partitions storage using StorageLocation property of the partition. Change it, then reprocess your partition and you see partition data located in the directory specified.

Edward.
--
This posting is provided "AS IS" with no warranties, and confers no rights.

|||

Edward,

Thanks for the response.... I now understand that the aggregations that I see in the wizard are essentially estimates however if I process them where are they physically stored, I am just trying to get to the location on the server. Also I am using Analysis Services 2000 are the aggregations stored differently from 2005 , because the article you sent me references 2005.

Thanks

|||

Aggregations are stored as part of partition storage. That is true for AS2000 and AS2005.

With AS2000 you dont have option to store partitions outside of the data folder. My previous post referred to AS2000.

Edward.
--
This posting is provided "AS IS" with no warranties, and confers no rights.

aggregation question

Aggregation SUM adds the numbers together. Is there a similar aggregation function that returns the product of all the numbers?

Thanks

No, there is no built-in PRODUCT aggregate. One thing you could try is taking the exponent of the sum of the logs of the individual rows; however, this will tend to cause arithmetic execution errors if any of the individual rows have zero for a value.

Here is a similar discussion:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=355075&SiteID=1

|||

Do you mean 'product' as in factorial?

|||

Check out the link below for a solution that uses the built-in aggregates to compute product:

http://www.umachandar.com/technical/SQL6x70Scripts/Main21.htm

You can also write a SQLCLR aggregate in SQL Server 2005 to do the same.

Aggregation Question

Let's say we have 2 attributes: a and b. Each consists of the defaulthierarchy of an all-level and a leaflevel consisting of the leaves 1 and 2. If I add an aggregation on (a,b) then questions such as

SELECT [SomeMeasure] ON 0

FROM [Cube]

WHERE (b.b.2)

should yield an answer that is preaggregated, right? I.e. the coordinates (a.all,b.1),(a.all,b.2),(a.all,b.all),(a.1,b.1),(a.1,b.2),(a.1,b.all),(a.2,b.1),(a.2,b.2),(a.2,b.all) should contain preaggregated values for all measures. Except my cube has 5 times worse queryperformance with aggregates enabled...

So have I misunderstood something here? Do the levels not mix here so only (a.all,b.all),(a.1,b.1),(a.1,b.2),(a.2,b.1),(a.2,b.2) becomes preaggregated?

Looks like the query you are trying to optimize is hitting some other attributes.

Try running SQL Profiler against Analysis Server.

QuerySubcubeVerbose event should show you the set of attributes that were needed for you query.

Edward.
--
This posting is provided "AS IS" with no warranties, and confers no rights.

|||

Thanks for the help (yet again ) - didn't know about those profiler options - also found the "Get Data From Aggregation" event to see when and which aggregation is used. The problem still remains though as it seems it picks the correct attributes and the best aggregation corresponding to it just fine. However using a single aggregation of all attributes does significantly worse then using none at all.

Using smaller partial aggregations such as those storage designer chooses is of course even better then no aggregations and perfectly fine for the queries where they're applicable but the performance for the queries they don't cover isn't good enough.

I can imagine a large enough aggregation would take some time to navigate (as it seems to spend almost all it's effort reading from disk) but it seems very strange that it wouldn't take even more time to read all the underlying data. Furthermore this aggregation is only a few hundred mb and there's no others - not exactly huge in my book.

Anyway thanks - a lot easier to test further with those profileroptions. Any further thoughts are much appreciated though.

|||

To make your aggregations more efficient you need to try and define relationships between attributes.

Take a look for instance at what you get after you migrate FoodMart 2000 sample cube. You will see that almost all attributes in all dimensions are in hierarchies and there are relationships defined between them. Having right set of relationships will help single aggregation to answer more queries.

Edward.
--
This posting is provided "AS IS" with no warranties, and confers no rights.

|||

All the attributes in the model need to be fully filterable on (simultaneously) and thus I've made a separate dimension for each attribute with just that attribute in it. As each attribute has the default all-member it (if I understand it correctly) has a default attribute relationship from the leaf-level of an attribute to the all-level of the same attribute but I haven't defined any in addition to that. Is there any other way I could structure this and still keep the independence between the attributes that allows full filtering?

I want to add hierarchies later to allow faster multiselection but right now I have these problems even for very simple queries of the type:

SELECT ([attr1]) ON 0,

[Some Measure] ON 1

FROM [cube]

WHERE ([att2].[some leaf member],[att3].[all], [att4].[all], etc...)

Having experimented a little further with the profiler (with a cube with 4x dimensions with 16384 members, one with 11 and one with 5) I noticed that almost the entire performancedrop comes when adding 2 of the big-member attributes to the same aggregation. Any additional attributes after that does degrade performance as well but only slightly. I'm assuming this has something to do with much more empty cells showing up in the aggregation in the latter cases as I (for testingpurposes) use only 1 million factrows. Luckily the wizard also ignores any aggregations that large but as I need filtering on all attributes that doesn't help me.

As I've changed the XMLA for the aggregations directly and recreated the cube there's no change in the relationsships here so it seems that it's the pure size of the aggregation that makes the difference when it comes to queryperformance. 16384x11x5 is 4-5 times faster then unaggregated but 16384x16384x11x5 takes 5-10x longer then the unaggregated one.

|||

Besides trying to desing "good" set of aggregations for your cube you should look into partitioning it.

If you create say monthly parittions and your query is only asking for the last month of data, you will benefit greatly. Analysis Server is only going to scan last partition of data to retreive answer for you query.

Edward.
--
This posting is provided "AS IS" with no warranties, and confers no rights.

Aggregation Question

Let's say we have 2 attributes: a and b. Each consists of the defaulthierarchy of an all-level and a leaflevel consisting of the leaves 1 and 2. If I add an aggregation on (a,b) then questions such as

SELECT [SomeMeasure] ON 0

FROM [Cube]

WHERE (b.b.2)

should yield an answer that is preaggregated, right? I.e. the coordinates (a.all,b.1),(a.all,b.2),(a.all,b.all),(a.1,b.1),(a.1,b.2),(a.1,b.all),(a.2,b.1),(a.2,b.2),(a.2,b.all) should contain preaggregated values for all measures. Except my cube has 5 times worse queryperformance with aggregates enabled...

So have I misunderstood something here? Do the levels not mix here so only (a.all,b.all),(a.1,b.1),(a.1,b.2),(a.2,b.1),(a.2,b.2) becomes preaggregated?

Looks like the query you are trying to optimize is hitting some other attributes.

Try running SQL Profiler against Analysis Server.

QuerySubcubeVerbose event should show you the set of attributes that were needed for you query.

Edward.
--
This posting is provided "AS IS" with no warranties, and confers no rights.

|||

Thanks for the help (yet again ) - didn't know about those profiler options - also found the "Get Data From Aggregation" event to see when and which aggregation is used. The problem still remains though as it seems it picks the correct attributes and the best aggregation corresponding to it just fine. However using a single aggregation of all attributes does significantly worse then using none at all.

Using smaller partial aggregations such as those storage designer chooses is of course even better then no aggregations and perfectly fine for the queries where they're applicable but the performance for the queries they don't cover isn't good enough.

I can imagine a large enough aggregation would take some time to navigate (as it seems to spend almost all it's effort reading from disk) but it seems very strange that it wouldn't take even more time to read all the underlying data. Furthermore this aggregation is only a few hundred mb and there's no others - not exactly huge in my book.

Anyway thanks - a lot easier to test further with those profileroptions. Any further thoughts are much appreciated though.

|||

To make your aggregations more efficient you need to try and define relationships between attributes.

Take a look for instance at what you get after you migrate FoodMart 2000 sample cube. You will see that almost all attributes in all dimensions are in hierarchies and there are relationships defined between them. Having right set of relationships will help single aggregation to answer more queries.

Edward.
--
This posting is provided "AS IS" with no warranties, and confers no rights.

|||

All the attributes in the model need to be fully filterable on (simultaneously) and thus I've made a separate dimension for each attribute with just that attribute in it. As each attribute has the default all-member it (if I understand it correctly) has a default attribute relationship from the leaf-level of an attribute to the all-level of the same attribute but I haven't defined any in addition to that. Is there any other way I could structure this and still keep the independence between the attributes that allows full filtering?

I want to add hierarchies later to allow faster multiselection but right now I have these problems even for very simple queries of the type:

SELECT ([attr1]) ON 0,

[Some Measure] ON 1

FROM [cube]

WHERE ([att2].[some leaf member],[att3].[all], [att4].[all], etc...)

Having experimented a little further with the profiler (with a cube with 4x dimensions with 16384 members, one with 11 and one with 5) I noticed that almost the entire performancedrop comes when adding 2 of the big-member attributes to the same aggregation. Any additional attributes after that does degrade performance as well but only slightly. I'm assuming this has something to do with much more empty cells showing up in the aggregation in the latter cases as I (for testingpurposes) use only 1 million factrows. Luckily the wizard also ignores any aggregations that large but as I need filtering on all attributes that doesn't help me.

As I've changed the XMLA for the aggregations directly and recreated the cube there's no change in the relationsships here so it seems that it's the pure size of the aggregation that makes the difference when it comes to queryperformance. 16384x11x5 is 4-5 times faster then unaggregated but 16384x16384x11x5 takes 5-10x longer then the unaggregated one.

|||

Besides trying to desing "good" set of aggregations for your cube you should look into partitioning it.

If you create say monthly parittions and your query is only asking for the last month of data, you will benefit greatly. Analysis Server is only going to scan last partition of data to retreive answer for you query.

Edward.
--
This posting is provided "AS IS" with no warranties, and confers no rights.

Aggregation Queries with > 80.000.000 rows

Hi,
We have a logging database with a table "Logs" that hold 80.000.000 log rows
(about 1 year of application logs). We need to analyze this data in for
variable time periods, so we cannot simply split the table. The table
contains a column "LogID" (Identity INT and the only member of the clustered
PK) and a column "Time" (datetime there exists an index for this column).
The query
SELECT *
FROM Logs WITH (nolock)
WHERE LogID > 110385284
takes 2 seconds and returns about 3000 rows.
The query
SELECT MAX(Time), MIN(Time)
FROM Logs WITH (nolock)
WHERE LogID > 110385284
takes more than a minute (I've cancelled the query after a minute).
How can this be? The query analyzer shows me a really simple query plan for
the first query using the PK. For the second query, the query plan shows me
no usage of the PK, but usage of the index for the column "Time" (two time,
one for min and one for max).
Even more strange is this query:
SELECT MAX(Logs1.Time), MIN(Logs1.Time)
FROM Logs Logs1 WITH (nolock)
INNER JOIN Logs Logs2 WITH (nolock) ON Logs1.LogID = Logs2.LogID
WHERE Logs1.LogID > 110385284
the query finishes in less than a second, and is using the PK.
Also specifying the PK as an index hint solves the problem, but I don't like
to specify query hints, because this may prevent an updated query processor
to use a better query plan.
Another problem is that we also have less expirienced programmers that need
to deal with such tables, so at the moment I need to review each and every
"slow" query and insert query hints. Will there be a fix that "optimizes" the
query engine of sql server?
CU,
Sven
Matzen
Yes, SQL Server needs to do some extra work when you specify an aggregate
functions.
Look, you may want to use INDEX hint to dictate the query optimizer to use
PK,but generally speaking it's not a good idea because the Optimizer is
smart enough to create much more efficient execution plan.
Also,you may create a clustered index on Time column and see how it does the
work.
"Matzen" <Matzen@.discussions.microsoft.com> wrote in message
news:ADAE2C5C-C301-4F72-966C-C6AB4EAB9FF7@.microsoft.com...
> Hi,
> We have a logging database with a table "Logs" that hold 80.000.000 log
rows
> (about 1 year of application logs). We need to analyze this data in for
> variable time periods, so we cannot simply split the table. The table
> contains a column "LogID" (Identity INT and the only member of the
clustered
> PK) and a column "Time" (datetime there exists an index for this column).
> The query
> SELECT *
> FROM Logs WITH (nolock)
> WHERE LogID > 110385284
> takes 2 seconds and returns about 3000 rows.
> The query
> SELECT MAX(Time), MIN(Time)
> FROM Logs WITH (nolock)
> WHERE LogID > 110385284
> takes more than a minute (I've cancelled the query after a minute).
> How can this be? The query analyzer shows me a really simple query plan
for
> the first query using the PK. For the second query, the query plan shows
me
> no usage of the PK, but usage of the index for the column "Time" (two
time,
> one for min and one for max).
> Even more strange is this query:
> SELECT MAX(Logs1.Time), MIN(Logs1.Time)
> FROM Logs Logs1 WITH (nolock)
> INNER JOIN Logs Logs2 WITH (nolock) ON Logs1.LogID = Logs2.LogID
> WHERE Logs1.LogID > 110385284
> the query finishes in less than a second, and is using the PK.
> Also specifying the PK as an index hint solves the problem, but I don't
like
> to specify query hints, because this may prevent an updated query
processor
> to use a better query plan.
> Another problem is that we also have less expirienced programmers that
need
> to deal with such tables, so at the moment I need to review each and every
> "slow" query and insert query hints. Will there be a fix that "optimizes"
the
> query engine of sql server?
> CU,
> Sven
|||Hi Uri,
As you can see in my post, the query including the hint performs at least 60
times better than without it (without > 1 minute, with hint less than a
second).
With the clustered index ... well 80 million rows are currently clustered by
ID, resorting them to sort by another column may take a while ... may be next
year.
My "problem" is that I cannot belive that a query optimizer like the one of
sql server does not recognize that the "where" statement reduces the amount
of data to be processed from 80 million to 3000 (table statistics are up to
date), because this analysis is not really compex:
1) the "where" does contain an identity field, that is equal to the
clustered PK
2) the condition in the where stament eleminates > 90% of the data to be
processed
This must be a bug, so I assume this to be removed in the next service pack.
CU,
Sven
"Uri Dimant" wrote:

> Matzen
> Yes, SQL Server needs to do some extra work when you specify an aggregate
> functions.
> Look, you may want to use INDEX hint to dictate the query optimizer to use
> PK,but generally speaking it's not a good idea because the Optimizer is
> smart enough to create much more efficient execution plan.
> Also,you may create a clustered index on Time column and see how it does the
> work.
>
>
>
>
> "Matzen" <Matzen@.discussions.microsoft.com> wrote in message
> news:ADAE2C5C-C301-4F72-966C-C6AB4EAB9FF7@.microsoft.com...
> rows
> clustered
> for
> me
> time,
> like
> processor
> need
> the
>
>
|||Matzen wrote:
> Hi Uri,
> As you can see in my post, the query including the hint performs at
> least 60 times better than without it (without > 1 minute, with hint
> less than a second).
> With the clustered index ... well 80 million rows are currently
> clustered by ID, resorting them to sort by another column may take a
> while ... may be next year.
> My "problem" is that I cannot belive that a query optimizer like the
> one of sql server does not recognize that the "where" statement
> reduces the amount of data to be processed from 80 million to 3000
> (table statistics are up to date), because this analysis is not
> really compex: 1) the "where" does contain an identity field, that is
> equal to the clustered PK
> 2) the condition in the where stament eleminates > 90% of the data to
> be processed
> This must be a bug, so I assume this to be removed in the next
> service pack.
> CU,
> Sven
>
The problem you are seeing is not really a bug, but a known issue with
the query optimizer. Many times SQL Server decides that based on the
number of rows likely to be returned from a query that using an index
(index seek + bookmark lookup for a non-clustered index or just a
clustered index seek for a clustered index) is actually more work than
scanning the table.
It's my understanding that SQL Server fails over to a table scan /
clustered index scan operation too soon in some cases. Your case just
may be one of those. I would keep the index hint and just keep an eye on
the query.
David Gugick
Imceda Software
www.imceda.com

Aggregation Queries with > 80.000.000 rows

Hi,
We have a logging database with a table "Logs" that hold 80.000.000 log rows
(about 1 year of application logs). We need to analyze this data in for
variable time periods, so we cannot simply split the table. The table
contains a column "LogID" (Identity INT and the only member of the clustered
PK) and a column "Time" (datetime there exists an index for this column).
The query
SELECT *
FROM Logs WITH (nolock)
WHERE LogID > 110385284
takes 2 seconds and returns about 3000 rows.
The query
SELECT MAX(Time), MIN(Time)
FROM Logs WITH (nolock)
WHERE LogID > 110385284
takes more than a minute (I've cancelled the query after a minute).
How can this be? The query analyzer shows me a really simple query plan for
the first query using the PK. For the second query, the query plan shows me
no usage of the PK, but usage of the index for the column "Time" (two time,
one for min and one for max).
Even more strange is this query:
SELECT MAX(Logs1.Time), MIN(Logs1.Time)
FROM Logs Logs1 WITH (nolock)
INNER JOIN Logs Logs2 WITH (nolock) ON Logs1.LogID = Logs2.LogID
WHERE Logs1.LogID > 110385284
the query finishes in less than a second, and is using the PK.
Also specifying the PK as an index hint solves the problem, but I don't like
to specify query hints, because this may prevent an updated query processor
to use a better query plan.
Another problem is that we also have less expirienced programmers that need
to deal with such tables, so at the moment I need to review each and every
"slow" query and insert query hints. Will there be a fix that "optimizes" the
query engine of sql server?
CU,
SvenMatzen
Yes, SQL Server needs to do some extra work when you specify an aggregate
functions.
Look, you may want to use INDEX hint to dictate the query optimizer to use
PK,but generally speaking it's not a good idea because the Optimizer is
smart enough to create much more efficient execution plan.
Also,you may create a clustered index on Time column and see how it does the
work.
"Matzen" <Matzen@.discussions.microsoft.com> wrote in message
news:ADAE2C5C-C301-4F72-966C-C6AB4EAB9FF7@.microsoft.com...
> Hi,
> We have a logging database with a table "Logs" that hold 80.000.000 log
rows
> (about 1 year of application logs). We need to analyze this data in for
> variable time periods, so we cannot simply split the table. The table
> contains a column "LogID" (Identity INT and the only member of the
clustered
> PK) and a column "Time" (datetime there exists an index for this column).
> The query
> SELECT *
> FROM Logs WITH (nolock)
> WHERE LogID > 110385284
> takes 2 seconds and returns about 3000 rows.
> The query
> SELECT MAX(Time), MIN(Time)
> FROM Logs WITH (nolock)
> WHERE LogID > 110385284
> takes more than a minute (I've cancelled the query after a minute).
> How can this be? The query analyzer shows me a really simple query plan
for
> the first query using the PK. For the second query, the query plan shows
me
> no usage of the PK, but usage of the index for the column "Time" (two
time,
> one for min and one for max).
> Even more strange is this query:
> SELECT MAX(Logs1.Time), MIN(Logs1.Time)
> FROM Logs Logs1 WITH (nolock)
> INNER JOIN Logs Logs2 WITH (nolock) ON Logs1.LogID = Logs2.LogID
> WHERE Logs1.LogID > 110385284
> the query finishes in less than a second, and is using the PK.
> Also specifying the PK as an index hint solves the problem, but I don't
like
> to specify query hints, because this may prevent an updated query
processor
> to use a better query plan.
> Another problem is that we also have less expirienced programmers that
need
> to deal with such tables, so at the moment I need to review each and every
> "slow" query and insert query hints. Will there be a fix that "optimizes"
the
> query engine of sql server?
> CU,
> Sven|||Hi Uri,
As you can see in my post, the query including the hint performs at least 60
times better than without it (without > 1 minute, with hint less than a
second).
With the clustered index ... well 80 million rows are currently clustered by
ID, resorting them to sort by another column may take a while ... may be next
year.
My "problem" is that I cannot belive that a query optimizer like the one of
sql server does not recognize that the "where" statement reduces the amount
of data to be processed from 80 million to 3000 (table statistics are up to
date), because this analysis is not really compex:
1) the "where" does contain an identity field, that is equal to the
clustered PK
2) the condition in the where stament eleminates > 90% of the data to be
processed
This must be a bug, so I assume this to be removed in the next service pack.
CU,
Sven
"Uri Dimant" wrote:
> Matzen
> Yes, SQL Server needs to do some extra work when you specify an aggregate
> functions.
> Look, you may want to use INDEX hint to dictate the query optimizer to use
> PK,but generally speaking it's not a good idea because the Optimizer is
> smart enough to create much more efficient execution plan.
> Also,you may create a clustered index on Time column and see how it does the
> work.
>
>
>
>
> "Matzen" <Matzen@.discussions.microsoft.com> wrote in message
> news:ADAE2C5C-C301-4F72-966C-C6AB4EAB9FF7@.microsoft.com...
> > Hi,
> >
> > We have a logging database with a table "Logs" that hold 80.000.000 log
> rows
> > (about 1 year of application logs). We need to analyze this data in for
> > variable time periods, so we cannot simply split the table. The table
> > contains a column "LogID" (Identity INT and the only member of the
> clustered
> > PK) and a column "Time" (datetime there exists an index for this column).
> >
> > The query
> > SELECT *
> > FROM Logs WITH (nolock)
> > WHERE LogID > 110385284
> > takes 2 seconds and returns about 3000 rows.
> >
> > The query
> > SELECT MAX(Time), MIN(Time)
> > FROM Logs WITH (nolock)
> > WHERE LogID > 110385284
> > takes more than a minute (I've cancelled the query after a minute).
> >
> > How can this be? The query analyzer shows me a really simple query plan
> for
> > the first query using the PK. For the second query, the query plan shows
> me
> > no usage of the PK, but usage of the index for the column "Time" (two
> time,
> > one for min and one for max).
> > Even more strange is this query:
> > SELECT MAX(Logs1.Time), MIN(Logs1.Time)
> > FROM Logs Logs1 WITH (nolock)
> > INNER JOIN Logs Logs2 WITH (nolock) ON Logs1.LogID = Logs2.LogID
> > WHERE Logs1.LogID > 110385284
> > the query finishes in less than a second, and is using the PK.
> >
> > Also specifying the PK as an index hint solves the problem, but I don't
> like
> > to specify query hints, because this may prevent an updated query
> processor
> > to use a better query plan.
> >
> > Another problem is that we also have less expirienced programmers that
> need
> > to deal with such tables, so at the moment I need to review each and every
> > "slow" query and insert query hints. Will there be a fix that "optimizes"
> the
> > query engine of sql server?
> >
> > CU,
> > Sven
>
>|||Matzen wrote:
> Hi Uri,
> As you can see in my post, the query including the hint performs at
> least 60 times better than without it (without > 1 minute, with hint
> less than a second).
> With the clustered index ... well 80 million rows are currently
> clustered by ID, resorting them to sort by another column may take a
> while ... may be next year.
> My "problem" is that I cannot belive that a query optimizer like the
> one of sql server does not recognize that the "where" statement
> reduces the amount of data to be processed from 80 million to 3000
> (table statistics are up to date), because this analysis is not
> really compex: 1) the "where" does contain an identity field, that is
> equal to the clustered PK
> 2) the condition in the where stament eleminates > 90% of the data to
> be processed
> This must be a bug, so I assume this to be removed in the next
> service pack.
> CU,
> Sven
>
The problem you are seeing is not really a bug, but a known issue with
the query optimizer. Many times SQL Server decides that based on the
number of rows likely to be returned from a query that using an index
(index seek + bookmark lookup for a non-clustered index or just a
clustered index seek for a clustered index) is actually more work than
scanning the table.
It's my understanding that SQL Server fails over to a table scan /
clustered index scan operation too soon in some cases. Your case just
may be one of those. I would keep the index hint and just keep an eye on
the query.
David Gugick
Imceda Software
www.imceda.com

Aggregation Queries with > 80.000.000 rows

Hi,
We have a logging database with a table "Logs" that hold 80.000.000 log rows
(about 1 year of application logs). We need to analyze this data in for
variable time periods, so we cannot simply split the table. The table
contains a column "LogID" (Identity INT and the only member of the clustered
PK) and a column "Time" (datetime there exists an index for this column).
The query
SELECT *
FROM Logs WITH (nolock)
WHERE LogID > 110385284
takes 2 seconds and returns about 3000 rows.
The query
SELECT MAX(Time), MIN(Time)
FROM Logs WITH (nolock)
WHERE LogID > 110385284
takes more than a minute (I've cancelled the query after a minute).
How can this be? The query analyzer shows me a really simple query plan for
the first query using the PK. For the second query, the query plan shows me
no usage of the PK, but usage of the index for the column "Time" (two time,
one for min and one for max).
Even more strange is this query:
SELECT MAX(Logs1.Time), MIN(Logs1.Time)
FROM Logs Logs1 WITH (nolock)
INNER JOIN Logs Logs2 WITH (nolock) ON Logs1.LogID = Logs2.LogID
WHERE Logs1.LogID > 110385284
the query finishes in less than a second, and is using the PK.
Also specifying the PK as an index hint solves the problem, but I don't like
to specify query hints, because this may prevent an updated query processor
to use a better query plan.
Another problem is that we also have less expirienced programmers that need
to deal with such tables, so at the moment I need to review each and every
"slow" query and insert query hints. Will there be a fix that "optimizes" th
e
query engine of sql server?
CU,
SvenMatzen
Yes, SQL Server needs to do some extra work when you specify an aggregate
functions.
Look, you may want to use INDEX hint to dictate the query optimizer to use
PK,but generally speaking it's not a good idea because the Optimizer is
smart enough to create much more efficient execution plan.
Also,you may create a clustered index on Time column and see how it does the
work.
"Matzen" <Matzen@.discussions.microsoft.com> wrote in message
news:ADAE2C5C-C301-4F72-966C-C6AB4EAB9FF7@.microsoft.com...
> Hi,
> We have a logging database with a table "Logs" that hold 80.000.000 log
rows
> (about 1 year of application logs). We need to analyze this data in for
> variable time periods, so we cannot simply split the table. The table
> contains a column "LogID" (Identity INT and the only member of the
clustered
> PK) and a column "Time" (datetime there exists an index for this column).
> The query
> SELECT *
> FROM Logs WITH (nolock)
> WHERE LogID > 110385284
> takes 2 seconds and returns about 3000 rows.
> The query
> SELECT MAX(Time), MIN(Time)
> FROM Logs WITH (nolock)
> WHERE LogID > 110385284
> takes more than a minute (I've cancelled the query after a minute).
> How can this be? The query analyzer shows me a really simple query plan
for
> the first query using the PK. For the second query, the query plan shows
me
> no usage of the PK, but usage of the index for the column "Time" (two
time,
> one for min and one for max).
> Even more strange is this query:
> SELECT MAX(Logs1.Time), MIN(Logs1.Time)
> FROM Logs Logs1 WITH (nolock)
> INNER JOIN Logs Logs2 WITH (nolock) ON Logs1.LogID = Logs2.LogID
> WHERE Logs1.LogID > 110385284
> the query finishes in less than a second, and is using the PK.
> Also specifying the PK as an index hint solves the problem, but I don't
like
> to specify query hints, because this may prevent an updated query
processor
> to use a better query plan.
> Another problem is that we also have less expirienced programmers that
need
> to deal with such tables, so at the moment I need to review each and every
> "slow" query and insert query hints. Will there be a fix that "optimizes"
the
> query engine of sql server?
> CU,
> Sven|||Hi Uri,
As you can see in my post, the query including the hint performs at least 60
times better than without it (without > 1 minute, with hint less than a
second).
With the clustered index ... well 80 million rows are currently clustered by
ID, resorting them to sort by another column may take a while ... may be nex
t
year.
My "problem" is that I cannot belive that a query optimizer like the one of
sql server does not recognize that the "where" statement reduces the amount
of data to be processed from 80 million to 3000 (table statistics are up to
date), because this analysis is not really compex:
1) the "where" does contain an identity field, that is equal to the
clustered PK
2) the condition in the where stament eleminates > 90% of the data to be
processed
This must be a bug, so I assume this to be removed in the next service pack.
CU,
Sven
"Uri Dimant" wrote:

> Matzen
> Yes, SQL Server needs to do some extra work when you specify an aggregate
> functions.
> Look, you may want to use INDEX hint to dictate the query optimizer to use
> PK,but generally speaking it's not a good idea because the Optimizer is
> smart enough to create much more efficient execution plan.
> Also,you may create a clustered index on Time column and see how it does t
he
> work.
>
>
>
>
> "Matzen" <Matzen@.discussions.microsoft.com> wrote in message
> news:ADAE2C5C-C301-4F72-966C-C6AB4EAB9FF7@.microsoft.com...
> rows
> clustered
> for
> me
> time,
> like
> processor
> need
> the
>
>|||Matzen wrote:
> Hi Uri,
> As you can see in my post, the query including the hint performs at
> least 60 times better than without it (without > 1 minute, with hint
> less than a second).
> With the clustered index ... well 80 million rows are currently
> clustered by ID, resorting them to sort by another column may take a
> while ... may be next year.
> My "problem" is that I cannot belive that a query optimizer like the
> one of sql server does not recognize that the "where" statement
> reduces the amount of data to be processed from 80 million to 3000
> (table statistics are up to date), because this analysis is not
> really compex: 1) the "where" does contain an identity field, that is
> equal to the clustered PK
> 2) the condition in the where stament eleminates > 90% of the data to
> be processed
> This must be a bug, so I assume this to be removed in the next
> service pack.
> CU,
> Sven
>
The problem you are seeing is not really a bug, but a known issue with
the query optimizer. Many times SQL Server decides that based on the
number of rows likely to be returned from a query that using an index
(index seek + bookmark lookup for a non-clustered index or just a
clustered index seek for a clustered index) is actually more work than
scanning the table.
It's my understanding that SQL Server fails over to a table scan /
clustered index scan operation too soon in some cases. Your case just
may be one of those. I would keep the index hint and just keep an eye on
the query.
David Gugick
Imceda Software
www.imceda.com

Aggregation Processing Use of All Processors Issue

In 2000 when MSAS wanted to create aggs it did a great job without me doing anything of using all available processors pretty darn near or at 100%. In SSAS 2005 I have an 8-processor box (4 dual cores actually) and its only using 1 of the 8. Anyone know how to unlock that? Some property perhaps?

If you split the cube into several partions by using dates, AS2005 will use more than one processor.

Regards

/Thomas

|||

Based on 8 processors I used 8 partitions and it did better, but not much. Then I tried 16 partitions (many programs use 4X threads per processor to maximize parellelization, but if something is well written 1x should be sufficient) and I think it helped - utilization is up to 30 or 40 percent during the cube process part, but the aggregation part is still pretty low - 20-30% overall.

How many procs do you have and what utilization are you seeing during agg processing?

|||

The cubes I work with are small and they run on a four CPU box. By using partitions I was able to reduce the the processing time by 50 percent for one of the cubes.

I have not measured utilization, only processing time.

You will have to consider your I/O system as well and memory setting for SSAS2005. Maybe your low utilization depends on bottlenecks in memory or I/O?

Regards

Thomas

Aggregation Problem with Hours and Minutes in Time Dimension

For the first time, I have created a time dimension that includes hours and minutes, in addition to the Year, Quarter, Month, and Date that I am familiar with.

I want to display the average of my measures at whatever level of Time the user chooses. I thus chose "AverageOfChildren" as the aggregation method for these measures.

Unfortunately, SSAS aggregates these measures by Sum over Hours and Minutes, and then by AverageOfChildren over Date, Month, Quarter, and Year.

I am confused.

How can I force it to perform an "AverageOfChildren" at all levels ?

First, have a look at this document(http://www.microsoft.com/technet/prodtechnol/sql/2005/realastd.mspx) and think about your design a second time(on page 34-35 in the word version)

Next. This is only a guess but how are your attribute relations between minutes, hours, date,quarter and year defined, if they are included in the same user hierarchy?

HTH

Thomas Ivarsson