Showing posts with label query. Show all posts
Showing posts with label query. Show all posts

Thursday, March 22, 2012

Analysis Server 2005 (SP2, Version 9.0.3042) returns wrong results (from cache)

In some cases the Analysis Server returns wrong results: If You at first make
a query containing several restrictions and after that make a similar query with less
restrictions, You sometimes get the result of the first query (which is wrong
for the second query).

Of course this error does not occur in every situation. In our environment it occurs
when CustomRollupFormulas of ParentChild-Dimensions are involved.

My questions:
- Has anyone seen this error before?
- Is there a way to report this as an error to microsoft?
- Are bug fixes or workaround available?
(At the moment we have SQL Server 2005 SP2, Version 9.0.3042)

Any help is welcome.


The following contains a description of a small sample where this error occurs.
(A Cubedefinition and the underlying Datawarehouse can be provided).
Detailled Description:
=====================

The OLAP-Database contains:
- A Year dimension with one member '2007'
(to make this example simple we have no quarters, months and so on)
- An Account dimension with Attributes "Key", "UserKey" and "Type" and 3 elements:
Key: UserKey: Type:
1 "1000" A
2 "2000" B
3 "3000" C
- A dimension for KPIs with Attributes "Key" and "Parent". "Parent" is a ParentChild
Dimension. This dimension has a CustomRollupColumn with MDX-Formulas.
The dimension has two elements:
Key: Designation: Parent: MDX-Forumula
-1 All NULL NULL
1 KPI 1 NULL Sum(
Filter(
CrossJoin(
{
([Account].[UserKey].&[1000]:
[Account].[UserKey].&[3000])
},
[KPI].[Parent].&[-1]
),
[Measures].CurrentMember > 0
)
)
- A fact-table with 3 lines:
AccountKey: Amount: Year: KPIKey
1 1000.00 2007 -1
2 2000.00 2007 -1
3 -4000.00 2007 -1

We use two Queries:
- Query 1:
SELECT {[Measures].[Amount]} ON 0,
NON EMPTY
AddCalculatedMembers(
Hierarchize(
Descendants(
{[Year].[Key].&[2007]},
[Year].[Key].[Key],
SELF_AND_BEFORE
)
)
)
DIMENSION PROPERTIES PARENT_UNIQUE_NAME,MEMBER_TYPE ON 1
FROM [PRO110530]
WHERE(
{
[Account].[Type].&[Type A],
[Account].[Type].&[Type C]
},
[KPI].[Parent].&[1]
);

This query first restricts the accounts to "1000" (Type A) und "3000" (Type C)
and the formula of "KPI 1" filters out account "3000".

The correct result is "1000.00".

- Query 2:
SELECT {[Measures].[Amount]} ON 0,
NON EMPTY
AddCalculatedMembers(
Hierarchize(
Descendants(
{[Year].[Key].&[2007]},
[Year].[Key].[Key],
SELF_AND_BEFORE
)
)
)
DIMENSION PROPERTIES PARENT_UNIQUE_NAME,MEMBER_TYPE ON 1
FROM [PRO110530]
WHERE(
[KPI].[Parent].&[1]
);
This query is nearly the same as query 1, but the accounts are not filtered out
by their type. Therefore the formula of "KPI 1" applies to all accounts and
only account "3000" is filtered out.

The correct result is "3000.00" (Sum of accounts "1000" and "2000")

Analysis Server returns this result if You run Query 2 as first query.

The error occurs in the following case:
- Process the cube (or restart) the Analysis Server.
- Connect to the database.
- Run Query1:
The server returns result: "1000.00". That's correct.
- Run Query2 (on the same connection):
The server returns result: "1000.00". That's wrong.

The error does not occur in the following cases:
- If you restart the server between Query1 and Query2.
(That is no pratical workaround).
- If You do not put the Year-dimension on Axis 1
(In real life that is no practical workaround, because we have a more complex
Time-dimension and want for instance to see two years on Axis 1)
- If You use different connections for the two Queries
(That is no workaround for us, because we use a third-party tool, which
calls the Analysis Server)
- If You add the VisualTotals-function to the MDX for Axis 1
(That is a bad workaround, because the runtime of complex KPIs rises up significantly)

It's hard to tell, but it almost feels like an issue with the formula cache.

Your options would be

1. Ring Product Support - If you need to get a fix in a timely manner, then this is your best bet. You would have to check when you call, but I think you would get your fee refunded if the call is confirmed as a bug in the product.

2. You could log the bug in the SQL Server section on the connect website connect.microsoft.com, but you are not guarenteed of a timely response (the product team does go through these issues, but there is just no telling when this will happen)

It could be something to do with the CustomRollup formulas, have you tried turning off the custom rollups and moving the calc into a scope statement in the calc script? If this work around does fix your issue I would still encourage you to log a bug on connect.

|||

Other than filing a bug, if you need an immediate workaround, try issuing the following ClearCache command through XML/A between the two queries.

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">

<Body>

<Execute xmlns="urnTongue Tiedchemas-microsoft-com:xml-analysis">

<Command>

<Batch xmlns="http://schemas.microsoft.com/analysisservices/2003/engine">

<ClearCache>

<Object>

<DatabaseID>Your Database ID</DatabaseID>

</Object>

</ClearCache>

</Batch>

</Command>

<Properties/>

</Execute>

</Body>

</Envelope>

|||

Good idea Jeffrey, I did think of this, but forgot to mention it. If it is a cache issue this would probably work too. The only issue being that you cannot "chain" this command onto the start or the end of a query, so the problem then becomes "how do we know when to run this command".

I also have a variation on this command wrapped in a stored proc on the AS Stored Procedure project on codeplex www.codeplex.com/asstoredprocedures - it is not part of the lastest release, you would have to download the source and compile it (we are planning to compile another release soon), there is docmentation on this command on the codeplex site.

|||

Darren and Jeffrey,

thank Your for the replies.

Unfortunately I can't clear the cache, because I only fill the OLAP-Database and the Database is called by a third party tool.

Therefore I will report this problem to Microsoft Product Support at next.

Hopefully they know a workaround or have a hotfix.

|||

We reported the error to Microsoft report. I'm citing from the answer:

"...the problem is really because of the CustomRollupFormula, where we are seeing performance issues as well as problems like yours. Our developer team recommended that these people should start using “Cache Policy = 9” with SP2 in order to obtain better performance (connection string setting). Now, Cache Policy is not doable in SSMS or BIDS, so what you can do is to change this setting server wide by changing inside the msmdsrv.ini: <CalculationCoverPolicy>9</CalculationCoverPolicy> Rebooting the server will use this new setting. Something to remember is that this will change the behavior of the query engine. So, some of your queries will go faster and some slower. So, remember that and monitor the server."

We changed this setting and the error does not occur anymore. Moreover the performance of some testcases which use custom rollup formulas was significantly better. I hope the overall performance of the system remains OK with this setting.

My question at this point is: Custom Rollup Formulas are a very powerful part of Analysis Services -- You can create very interesting solutions with them. But it seems to me that the use of Custom Rollup Formulas is not in the main focus of the Analysis Services development team. Otherwise I could not explain the error and performance problems in SP2 (the performance in SP1 was better!). Perhaps it would help, if Microsoft has real-life examples of the usage of this feature. Is it possible to establish a deeper contact between the development team and users of custom rollup formulas to exchange testcases and experiences for this topic?

|||have you written any custom aggregations - either through xlma or the aggregation design wizard?

Analysis Server 2005 (SP2, Version 9.0.3042) returns wrong results (from cache)

In some cases the Analysis Server returns wrong results: If You at first make
a query containing several restrictions and after that make a similar query with less
restrictions, You sometimes get the result of the first query (which is wrong
for the second query).

Of course this error does not occur in every situation. In our environment it occurs
when CustomRollupFormulas of ParentChild-Dimensions are involved.

My questions:
- Has anyone seen this error before?
- Is there a way to report this as an error to microsoft?
- Are bug fixes or workaround available?
(At the moment we have SQL Server 2005 SP2, Version 9.0.3042)

Any help is welcome.


The following contains a description of a small sample where this error occurs.
(A Cubedefinition and the underlying Datawarehouse can be provided).
Detailled Description:
=====================

The OLAP-Database contains:
- A Year dimension with one member '2007'
(to make this example simple we have no quarters, months and so on)
- An Account dimension with Attributes "Key", "UserKey" and "Type" and 3 elements:
Key: UserKey: Type:
1 "1000" A
2 "2000" B
3 "3000" C
- A dimension for KPIs with Attributes "Key" and "Parent". "Parent" is a ParentChild
Dimension. This dimension has a CustomRollupColumn with MDX-Formulas.
The dimension has two elements:
Key: Designation: Parent: MDX-Forumula
-1 All NULL NULL
1 KPI 1 NULL Sum(
Filter(
CrossJoin(
{
([Account].[UserKey].&[1000]:
[Account].[UserKey].&[3000])
},
[KPI].[Parent].&[-1]
),
[Measures].CurrentMember > 0
)
)
- A fact-table with 3 lines:
AccountKey: Amount: Year: KPIKey
1 1000.00 2007 -1
2 2000.00 2007 -1
3 -4000.00 2007 -1

We use two Queries:
- Query 1:
SELECT {[Measures].[Amount]} ON 0,
NON EMPTY
AddCalculatedMembers(
Hierarchize(
Descendants(
{[Year].[Key].&[2007]},
[Year].[Key].[Key],
SELF_AND_BEFORE
)
)
)
DIMENSION PROPERTIES PARENT_UNIQUE_NAME,MEMBER_TYPE ON 1
FROM [PRO110530]
WHERE(
{
[Account].[Type].&[Type A],
[Account].[Type].&[Type C]
},
[KPI].[Parent].&[1]
);

This query first restricts the accounts to "1000" (Type A) und "3000" (Type C)
and the formula of "KPI 1" filters out account "3000".

The correct result is "1000.00".

- Query 2:
SELECT {[Measures].[Amount]} ON 0,
NON EMPTY
AddCalculatedMembers(
Hierarchize(
Descendants(
{[Year].[Key].&[2007]},
[Year].[Key].[Key],
SELF_AND_BEFORE
)
)
)
DIMENSION PROPERTIES PARENT_UNIQUE_NAME,MEMBER_TYPE ON 1
FROM [PRO110530]
WHERE(
[KPI].[Parent].&[1]
);
This query is nearly the same as query 1, but the accounts are not filtered out
by their type. Therefore the formula of "KPI 1" applies to all accounts and
only account "3000" is filtered out.

The correct result is "3000.00" (Sum of accounts "1000" and "2000")

Analysis Server returns this result if You run Query 2 as first query.

The error occurs in the following case:
- Process the cube (or restart) the Analysis Server.
- Connect to the database.
- Run Query1:
The server returns result: "1000.00". That's correct.
- Run Query2 (on the same connection):
The server returns result: "1000.00". That's wrong.

The error does not occur in the following cases:
- If you restart the server between Query1 and Query2.
(That is no pratical workaround).
- If You do not put the Year-dimension on Axis 1
(In real life that is no practical workaround, because we have a more complex
Time-dimension and want for instance to see two years on Axis 1)
- If You use different connections for the two Queries
(That is no workaround for us, because we use a third-party tool, which
calls the Analysis Server)
- If You add the VisualTotals-function to the MDX for Axis 1
(That is a bad workaround, because the runtime of complex KPIs rises up significantly)

It's hard to tell, but it almost feels like an issue with the formula cache.

Your options would be

1. Ring Product Support - If you need to get a fix in a timely manner, then this is your best bet. You would have to check when you call, but I think you would get your fee refunded if the call is confirmed as a bug in the product.

2. You could log the bug in the SQL Server section on the connect website connect.microsoft.com, but you are not guarenteed of a timely response (the product team does go through these issues, but there is just no telling when this will happen)

It could be something to do with the CustomRollup formulas, have you tried turning off the custom rollups and moving the calc into a scope statement in the calc script? If this work around does fix your issue I would still encourage you to log a bug on connect.

|||

Other than filing a bug, if you need an immediate workaround, try issuing the following ClearCache command through XML/A between the two queries.

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">

<Body>

<Execute xmlns="urnTongue Tiedchemas-microsoft-com:xml-analysis">

<Command>

<Batch xmlns="http://schemas.microsoft.com/analysisservices/2003/engine">

<ClearCache>

<Object>

<DatabaseID>Your Database ID</DatabaseID>

</Object>

</ClearCache>

</Batch>

</Command>

<Properties/>

</Execute>

</Body>

</Envelope>

|||

Good idea Jeffrey, I did think of this, but forgot to mention it. If it is a cache issue this would probably work too. The only issue being that you cannot "chain" this command onto the start or the end of a query, so the problem then becomes "how do we know when to run this command".

I also have a variation on this command wrapped in a stored proc on the AS Stored Procedure project on codeplex www.codeplex.com/asstoredprocedures - it is not part of the lastest release, you would have to download the source and compile it (we are planning to compile another release soon), there is docmentation on this command on the codeplex site.

|||

Darren and Jeffrey,

thank Your for the replies.

Unfortunately I can't clear the cache, because I only fill the OLAP-Database and the Database is called by a third party tool.

Therefore I will report this problem to Microsoft Product Support at next.

Hopefully they know a workaround or have a hotfix.

|||

We reported the error to Microsoft report. I'm citing from the answer:

"...the problem is really because of the CustomRollupFormula, where we are seeing performance issues as well as problems like yours. Our developer team recommended that these people should start using “Cache Policy = 9” with SP2 in order to obtain better performance (connection string setting). Now, Cache Policy is not doable in SSMS or BIDS, so what you can do is to change this setting server wide by changing inside the msmdsrv.ini: <CalculationCoverPolicy>9</CalculationCoverPolicy> Rebooting the server will use this new setting. Something to remember is that this will change the behavior of the query engine. So, some of your queries will go faster and some slower. So, remember that and monitor the server."

We changed this setting and the error does not occur anymore. Moreover the performance of some testcases which use custom rollup formulas was significantly better. I hope the overall performance of the system remains OK with this setting.

My question at this point is: Custom Rollup Formulas are a very powerful part of Analysis Services -- You can create very interesting solutions with them. But it seems to me that the use of Custom Rollup Formulas is not in the main focus of the Analysis Services development team. Otherwise I could not explain the error and performance problems in SP2 (the performance in SP1 was better!). Perhaps it would help, if Microsoft has real-life examples of the usage of this feature. Is it possible to establish a deeper contact between the development team and users of custom rollup formulas to exchange testcases and experiences for this topic?

|||have you written any custom aggregations - either through xlma or the aggregation design wizard?

Analyser no using right index

Hi,
This Query :
SELECT 0
FROM
WOTransit -- with (index=x1,readuncommitted)
INNER JOIN WO On WoTransit.Wo_ref=Wo.Wo_ref
WHERE WO.Cmd_No=814352
AND ISNULL(WOTransit.Charge_ref,0) <> 0
Since this morning this query is much more slow than usual
If i add : "with (index=x1,readuncommitted) ", the speed
is back to normal. because analyser usually use that
index.
If not, analyser is using a clustered index that is not
related to the query.
why doesn't he use the right index ?
What can i do to fix that ? i allready ran UPDATEUSAGE
and no change.
Thank you !
DonaldHave you rebuilt or defragged the x1 index?
--
Kevin Hill
President
3NF Consulting
www.3nf-inc.com/NewsGroups.htm
www.DallasDBAs.com/forum - new DB forum for Dallas/Ft. Worth area DBAs.
"Donald" <anonymous@.discussions.microsoft.com> wrote in message
news:1c5c901c4522c$62730400$a001280a@.phx.gbl...
> Hi,
> This Query :
> SELECT 0
> FROM
> WOTransit -- with (index=x1,readuncommitted)
> INNER JOIN WO On WoTransit.Wo_ref=Wo.Wo_ref
> WHERE WO.Cmd_No=814352
> AND ISNULL(WOTransit.Charge_ref,0) <> 0
>
> Since this morning this query is much more slow than usual
> If i add : "with (index=x1,readuncommitted) ", the speed
> is back to normal. because analyser usually use that
> index.
> If not, analyser is using a clustered index that is not
> related to the query.
> why doesn't he use the right index ?
> What can i do to fix that ? i allready ran UPDATEUSAGE
> and no change.
> Thank you !
> Donald|||Yes,
i dropped X1 index and recreated it
>--Original Message--
>Have you rebuilt or defragged the x1 index?
>--
>Kevin Hill
>President
>3NF Consulting
>www.3nf-inc.com/NewsGroups.htm
>www.DallasDBAs.com/forum - new DB forum for Dallas/Ft.
Worth area DBAs.
>"Donald" <anonymous@.discussions.microsoft.com> wrote in
message
>news:1c5c901c4522c$62730400$a001280a@.phx.gbl...
>> Hi,
>> This Query :
>> SELECT 0
>> FROM
>> WOTransit -- with (index=x1,readuncommitted)
>> INNER JOIN WO On WoTransit.Wo_ref=Wo.Wo_ref
>> WHERE WO.Cmd_No=814352
>> AND ISNULL(WOTransit.Charge_ref,0) <> 0
>>
>> Since this morning this query is much more slow than
usual
>> If i add : "with (index=x1,readuncommitted) ", the speed
>> is back to normal. because analyser usually use that
>> index.
>> If not, analyser is using a clustered index that is not
>> related to the query.
>> why doesn't he use the right index ?
>> What can i do to fix that ? i allready ran UPDATEUSAGE
>> and no change.
>> Thank you !
>> Donald
>
>.
>|||This is what I usually do. Compare the actual plan and estimated plan
(without the hint). Look for areas where the number of rows differ greatly.
Try to understand why the estimate is way-off here. You might need to
update the statistics with the FULLSCAN option in order for SQL Server to
make better estimates.
Peter Yeoh
http://www.yohz.com
Need smaller SQL2K backups? Try MiniSQLBackup
"Donald" <anonymous@.discussions.microsoft.com> wrote in message
news:1c5c901c4522c$62730400$a001280a@.phx.gbl...
> Hi,
> This Query :
> SELECT 0
> FROM
> WOTransit -- with (index=x1,readuncommitted)
> INNER JOIN WO On WoTransit.Wo_ref=Wo.Wo_ref
> WHERE WO.Cmd_No=814352
> AND ISNULL(WOTransit.Charge_ref,0) <> 0
>
> Since this morning this query is much more slow than usual
> If i add : "with (index=x1,readuncommitted) ", the speed
> is back to normal. because analyser usually use that
> index.
> If not, analyser is using a clustered index that is not
> related to the query.
> why doesn't he use the right index ?
> What can i do to fix that ? i allready ran UPDATEUSAGE
> and no change.
> Thank you !
> Donald

Analyser no using right index

Hi,
This Query :
SELECT 0
FROM
WOTransit -- with (index=x1,readuncommitted)
INNER JOIN WO On WoTransit.Wo_ref=Wo.Wo_ref
WHERE WO.Cmd_No=814352
AND ISNULL(WOTransit.Charge_ref,0) <> 0
Since this morning this query is much more slow than usual
If i add : "with (index=x1,readuncommitted) ", the speed
is back to normal. because analyser usually use that
index.
If not, analyser is using a clustered index that is not
related to the query.
why doesn't he use the right index ?
What can i do to fix that ? i allready ran UPDATEUSAGE
and no change.
Thank you !
DonaldHave you rebuilt or defragged the x1 index?
Kevin Hill
President
3NF Consulting
www.3nf-inc.com/NewsGroups.htm
www.DallasDBAs.com/forum - new DB forum for Dallas/Ft. Worth area DBAs.
"Donald" <anonymous@.discussions.microsoft.com> wrote in message
news:1c5c901c4522c$62730400$a001280a@.phx
.gbl...
> Hi,
> This Query :
> SELECT 0
> FROM
> WOTransit -- with (index=x1,readuncommitted)
> INNER JOIN WO On WoTransit.Wo_ref=Wo.Wo_ref
> WHERE WO.Cmd_No=814352
> AND ISNULL(WOTransit.Charge_ref,0) <> 0
>
> Since this morning this query is much more slow than usual
> If i add : "with (index=x1,readuncommitted) ", the speed
> is back to normal. because analyser usually use that
> index.
> If not, analyser is using a clustered index that is not
> related to the query.
> why doesn't he use the right index ?
> What can i do to fix that ? i allready ran UPDATEUSAGE
> and no change.
> Thank you !
> Donald|||Yes,
i dropped X1 index and recreated it

>--Original Message--
>Have you rebuilt or defragged the x1 index?
>--
>Kevin Hill
>President
>3NF Consulting
>www.3nf-inc.com/NewsGroups.htm
>www.DallasDBAs.com/forum - new DB forum for Dallas/Ft.
Worth area DBAs.
>"Donald" <anonymous@.discussions.microsoft.com> wrote in
message
> news:1c5c901c4522c$62730400$a001280a@.phx
.gbl...
usual[vbcol=seagreen]
>
>.
>|||This is what I usually do. Compare the actual plan and estimated plan
(without the hint). Look for areas where the number of rows differ greatly.
Try to understand why the estimate is way-off here. You might need to
update the statistics with the FULLSCAN option in order for SQL Server to
make better estimates.
Peter Yeoh
http://www.yohz.com
Need smaller SQL2K backups? Try MiniSQLBackup
"Donald" <anonymous@.discussions.microsoft.com> wrote in message
news:1c5c901c4522c$62730400$a001280a@.phx
.gbl...
> Hi,
> This Query :
> SELECT 0
> FROM
> WOTransit -- with (index=x1,readuncommitted)
> INNER JOIN WO On WoTransit.Wo_ref=Wo.Wo_ref
> WHERE WO.Cmd_No=814352
> AND ISNULL(WOTransit.Charge_ref,0) <> 0
>
> Since this morning this query is much more slow than usual
> If i add : "with (index=x1,readuncommitted) ", the speed
> is back to normal. because analyser usually use that
> index.
> If not, analyser is using a clustered index that is not
> related to the query.
> why doesn't he use the right index ?
> What can i do to fix that ? i allready ran UPDATEUSAGE
> and no change.
> Thank you !
> Donald

Analyser no using right index

Hi,
This Query :
SELECT 0
FROM
WOTransit -- with (index=x1,readuncommitted)
INNER JOIN WO On WoTransit.Wo_ref=Wo.Wo_ref
WHERE WO.Cmd_No=814352
AND ISNULL(WOTransit.Charge_ref,0) <> 0
Since this morning this query is much more slow than usual
If i add : "with (index=x1,readuncommitted) ", the speed
is back to normal. because analyser usually use that
index.
If not, analyser is using a clustered index that is not
related to the query.
why doesn't he use the right index ?
What can i do to fix that ? i allready ran UPDATEUSAGE
and no change.
Thank you !
Donald
Have you rebuilt or defragged the x1 index?
Kevin Hill
President
3NF Consulting
www.3nf-inc.com/NewsGroups.htm
www.DallasDBAs.com/forum - new DB forum for Dallas/Ft. Worth area DBAs.
"Donald" <anonymous@.discussions.microsoft.com> wrote in message
news:1c5c901c4522c$62730400$a001280a@.phx.gbl...
> Hi,
> This Query :
> SELECT 0
> FROM
> WOTransit -- with (index=x1,readuncommitted)
> INNER JOIN WO On WoTransit.Wo_ref=Wo.Wo_ref
> WHERE WO.Cmd_No=814352
> AND ISNULL(WOTransit.Charge_ref,0) <> 0
>
> Since this morning this query is much more slow than usual
> If i add : "with (index=x1,readuncommitted) ", the speed
> is back to normal. because analyser usually use that
> index.
> If not, analyser is using a clustered index that is not
> related to the query.
> why doesn't he use the right index ?
> What can i do to fix that ? i allready ran UPDATEUSAGE
> and no change.
> Thank you !
> Donald
|||Yes,
i dropped X1 index and recreated it

>--Original Message--
>Have you rebuilt or defragged the x1 index?
>--
>Kevin Hill
>President
>3NF Consulting
>www.3nf-inc.com/NewsGroups.htm
>www.DallasDBAs.com/forum - new DB forum for Dallas/Ft.
Worth area DBAs.
>"Donald" <anonymous@.discussions.microsoft.com> wrote in
message[vbcol=seagreen]
>news:1c5c901c4522c$62730400$a001280a@.phx.gbl...
usual
>
>.
>
|||This is what I usually do. Compare the actual plan and estimated plan
(without the hint). Look for areas where the number of rows differ greatly.
Try to understand why the estimate is way-off here. You might need to
update the statistics with the FULLSCAN option in order for SQL Server to
make better estimates.
Peter Yeoh
http://www.yohz.com
Need smaller SQL2K backups? Try MiniSQLBackup
"Donald" <anonymous@.discussions.microsoft.com> wrote in message
news:1c5c901c4522c$62730400$a001280a@.phx.gbl...
> Hi,
> This Query :
> SELECT 0
> FROM
> WOTransit -- with (index=x1,readuncommitted)
> INNER JOIN WO On WoTransit.Wo_ref=Wo.Wo_ref
> WHERE WO.Cmd_No=814352
> AND ISNULL(WOTransit.Charge_ref,0) <> 0
>
> Since this morning this query is much more slow than usual
> If i add : "with (index=x1,readuncommitted) ", the speed
> is back to normal. because analyser usually use that
> index.
> If not, analyser is using a clustered index that is not
> related to the query.
> why doesn't he use the right index ?
> What can i do to fix that ? i allready ran UPDATEUSAGE
> and no change.
> Thank you !
> Donald
sql

Tuesday, March 20, 2012

An update query

Hi,
I run a same update query in our two servers, which have the same
configuration and same database and indexes, one of them is returning the
result in 4 seconds, and the other one in 7 minutes. the only difference
between them is that the fast server has 512 MB and the other one has 256 MB
RAM. Why is it that much slow.
Thanks in advance,
Mathew
hi Mathew,
Mathew wrote:
> Hi,
> I run a same update query in our two servers, which have the same
> configuration and same database and indexes, one of them is returning
> the result in 4 seconds, and the other one in 7 minutes. the only
> difference between them is that the fast server has 512 MB and the
> other one has 256 MB RAM. Why is it that much slow.
> Thanks in advance,
actually the 2 servers are not the same... probably they do not have the
same data too, and/or the same disk subsystem... perhaps the second is more
fragmented too, both at physical OS file status and at internal logical page
status..
and having the half of RAM does not help for sure.., this mean MSDE has
fewer available resources, that the runnig applications have more
contentions for resources with the SQL Services...
more paging at OS level will be needed by all applications... the whole
system can be involved...
BTW, the 2 results are very different indeed... but try cleaning up your
server... defrag it, both at OS level and database level..
try comparing the statistics output as well as the used plans...
lot of variables are involved...
Andrea Montanari (Microsoft MVP - SQL Server)
http://www.asql.biz/DbaMgr.shtmhttp://italy.mvps.org
DbaMgr2k ver 0.14.0 - DbaMgr ver 0.59.0
(my vb6+sql-dmo little try to provide MS MSDE 1.0 and MSDE 2000 a visual
interface)
-- remove DMO to reply

An unexplained error message for an Xquery

Hello,
When I issue this query:

select doc.query ('
for $b in /a/b,
$c in /a/c
return $b,$c
')
from T1
where id=6

I recieve this error message:
.Net SqlClient Data Provider: Msg 2227, Level 16, State 1, Line 5
XQuery [T1.doc.query()]: The variable '$c' was not found in the scope in which it was referenced.


Interestingly, when I reverse the order of the variables in the return clause (i.e. make it c$,$b ), the unidentified variable in the error message becomes $b instead of $c. i.e. the system always does not identify the second variable. The query always works fine if the return clause has only one variable, be it $b or $c.

Am I missing something here, or is it a bug?

thanks
-Arsany

The behavior is correct in this case. The problem here is with the precedence of the ',' operator with respect to the FLWOR statement. Basically, the ',' operator in the return statement is not binding to the return clause of the FLWOR, but rather creating a new XQuery expression. If you put parenthesis around the return statement (as shown below) this will enforce the precedence that you want in your query:

select doc.query ('
for $b in /a/b,
$c in /a/c
return ($b,$c)
')
from T1
where id=6
|||Thank you Mike
-Arsany Sawiressql

Monday, March 19, 2012

An internal error occurred. [ ID = 3639 ] on delete query

Hi,

When I am trying to execute a delete query i'm getting the following error An internal error occurred. [ ID = 3639 ]. This is happening for some specific rows only. Other rows are getting deleted without any issues. Some 7 rows are there which i'm not able to delete. I am able to run update query on that rows. but not delete query

Pls help

Thanks

Nebu

This error does not look like a SQL CE error. Are you using SQL CE or SQL Server ?

Also, could you show us the statement and describe your environment, then others may be able to help you.

|||I'm using SQL CE.

delete from tabl1 where ID=1

We are using SLQ ce as a databse for a windows application. We use C# . Some times there will be insert and delete statements of more than 10000. I executed this statement for more than 10000 records, in that apart from 7 records every thing else got deleted. I'm not able to delete it even from SQL server management studio expresss.

tahnks

Nebu

|||Sounds like your sdf file has become corrupted. Try to run a Compact/Repair on the db. You can also try to send the sdf file to me, and I will have a look at it with SSMS.

|||

Hi Erik,

Thanks for the reply. I will not able to send you the sdf bcos of confidentiality. Can you please tell me how to run a reapir?

Thanks

Nebu

|||

Repair can be done from SSMS(E), right click the database, select Properties and the Shrink/Repair tab.

Also, the SqlCeEngine object has a Repair method.

|||Thanks Eirk.. It worked.. Do you have any idea why did it happen? Is it

because of the no of transactions?

Thanks

Nebu

An if...else task

Hi,

Im running a database query and I want to compare the value of a datetime field to see what I wanna do with my data.

Is there any easy way of doing this with something from the Toolbox or would you recommend using a Script Task?

Thank you.

What do you want to compare it to? Can you give more detail about what it is you are trying to do?

-Jamie

|||

I have 100 rows of query data.

The rows contain a datetime field that I wanna check.

If the row happens before 10 o'clock:

- Do something

After 10 o'clock:

- Do something else

Thank you.

|||All depends on what Something and Something Else is.

You could use a conditional split to send the rows to different places or add an additional column with the flag stating the change or use the script task if you want to change the value of a variable if the condition is found.|||

I would say that conditional split is almost certainly going to be what you are looking for.

in your example you would just set a single case wherein your example datetime column is compared to less than or equal to 10 o'clock and all other rows are sent to default (greater than 10 o'clock) ...

Sunday, March 11, 2012

An error occurred while executing the query

Ferquently I am getting this error

An error occurred while executing the query.
ExecuteReader requires an open and available Connection. The connection's current state is closed.


ADDITIONAL INFORMATION:

ExecuteReader requires an open and available Connection. The connection's current state is closed. (System.Data)

If I refreshed the page it is working

Please help me why it is comming

Hi,

this the error becasue there is some problem with ur dataset.

click save all and close the soluton and then re-open the solution.

click refresh on the data set tab.

hope this helps...

Saturday, February 25, 2012

AMO: Use a query for datasourceview schema

Hi!

I want to use a query that returns all the necessary information to make a cube

Is there a way to provide this query to the datasourceview.schema property without adding any other tables?

So you basically have one big view that contains all your measures and all the attributes for every dimension?

I think this should be possible, the data source view is basically a .Net DataSet object, so you could just create a single table in your dataset with this view as the source.

But this is not really a recommended architecture. I would expect processing performance to suffer, SSAS would end up doing a lot of select distincts over the attribute columns. You would normally want to have all the tables and joins referenced in this view in your DSV.

|||

I know that there will be performance issues but all I have in my hands is a query and not even a view (actually many queries each for one cube)

In Analysis Services Designer you can provide just a named query but I do not know how to do this programmatically.

I suspect that after filling the datasourceview schema with an adapter, some extended properties will have to be added so as data to be fetched from the tables of the database to cube. Something like this:

Datasourceview.schema.Tables(0).ExtendedProperties.Add("TableType", "NamedQuery")

Datasourceview.schema.Tables(0).ExtendedProperties.Add("QueryDefinition", Query)

but it does not work!!! (cube is created but has no data)

Any idea?

|||I believe you want:

Datasourceview.schema.Tables(0).ExtendedProperties.Add("TableType", "View")

I don't know if that'll solve your problem, but that's the proper syntax for that statement AFAIK.

C
|||I think Chris is correct, the table type looks like it might have to be set to "View". The AMOAdventureWorks sample shows how to build a cut down version of the Adventure Works database using purely AMO (Although it does not contain an example of creating a named query) I'm not sure, but it's possible that you may also need to set:

Datasourceview.schema.tables(0).ExtendedProperties.Add("IsLogical", "True")

|||And, if i remember correctly, i had to remove the Schema name from the DT as well..

Datasourceview.schema.tables(0).ExtendedProperties.Remove("DBSchemaName")

C


AMO: Use a query for datasourceview schema

Hi!

I want to use a query that returns all the necessary information to make a cube

Is there a way to provide this query to the datasourceview.schema property without adding any other tables?

So you basically have one big view that contains all your measures and all the attributes for every dimension?

I think this should be possible, the data source view is basically a .Net DataSet object, so you could just create a single table in your dataset with this view as the source.

But this is not really a recommended architecture. I would expect processing performance to suffer, SSAS would end up doing a lot of select distincts over the attribute columns. You would normally want to have all the tables and joins referenced in this view in your DSV.

|||

I know that there will be performance issues but all I have in my hands is a query and not even a view (actually many queries each for one cube)

In Analysis Services Designer you can provide just a named query but I do not know how to do this programmatically.

I suspect that after filling the datasourceview schema with an adapter, some extended properties will have to be added so as data to be fetched from the tables of the database to cube. Something like this:

Datasourceview.schema.Tables(0).ExtendedProperties.Add("TableType", "NamedQuery")

Datasourceview.schema.Tables(0).ExtendedProperties.Add("QueryDefinition", Query)

but it does not work!!! (cube is created but has no data)

Any idea?

|||I believe you want:

Datasourceview.schema.Tables(0).ExtendedProperties.Add("TableType", "View")

I don't know if that'll solve your problem, but that's the proper syntax for that statement AFAIK.

C
|||I think Chris is correct, the table type looks like it might have to be set to "View". The AMOAdventureWorks sample shows how to build a cut down version of the Adventure Works database using purely AMO (Although it does not contain an example of creating a named query) I'm not sure, but it's possible that you may also need to set:

Datasourceview.schema.tables(0).ExtendedProperties.Add("IsLogical", "True")

|||And, if i remember correctly, i had to remove the Schema name from the DT as well..

Datasourceview.schema.tables(0).ExtendedProperties.Remove("DBSchemaName")

C


Sunday, February 19, 2012

ambiguous?

ok, im trying to create this query

Code Snippet

select distinct j.eventid
from oppositeleptons j
where dbo.invmass(j.l1Ee,j.l2Ee,j.l1px,j.l2px,j.l1py,
j.l2py,j.l1pz,j.l2pz,91.1882)<10;

GO


and it throw me this error message

Msg 4121, Level 16, State 1, Procedure EvInvMass, Line 3
Cannot find either column "dbo" or the user-defined function or aggregate "dbo.invmass", or the name is ambiguous.

the fact is.... theres no DBO column in oppositeleptons, so why this ambiguity?
the problem is that the function "dbo.invmass" does not exist

Check the owner of the function.. it needs to be called as
<owner>.invmass
where <owner> usually is dbo but it depends who created it and how.

Ambiguous Column Name Problem

I have a table which needs to have a column called rank. When I run the
following query I get an error about the table names being ambiguous. Is
there a way round this. Regards, Chris.
SELECT [Key], productdescriptionid, productdesc_name FROM FREETEXTTABLE
(tblProductDescriptions, *,'biopsy') F JOIN tblProductDescriptions P ON
P.productdescriptionid = F.[KEY]ORDER BY RANK DESC
Sorry I really wasn't thinking. just put F.RANK !!!!!
SELECT [Key], productdescriptionid, productdesc_name FROM FREETEXTTABLE
(tblProductDescriptions, *,'biopsy') F JOIN tblProductDescriptions P ON
P.productdescriptionid = F.[KEY]ORDER BY RANK DESC
"Chris Kennedy" <chrisknospam@.cybase.co.uk> wrote in message
news:OnxD4UKeEHA.3132@.TK2MSFTNGP11.phx.gbl...
> I have a table which needs to have a column called rank. When I run the
> following query I get an error about the table names being ambiguous. Is
> there a way round this. Regards, Chris.
> SELECT [Key], productdescriptionid, productdesc_name FROM FREETEXTTABLE
> (tblProductDescriptions, *,'biopsy') F JOIN tblProductDescriptions P ON
> P.productdescriptionid = F.[KEY]ORDER BY RANK DESC
>
|||does this work?
SELECT [Key], productdescriptionid, productdesc_name FROM FREETEXTTABLE
(tblProductDescriptions, *,'biopsy') F JOIN tblProductDescriptions P ON
P.productdescriptionid = F.[KEY] ORDER BY F.[RANK] DESC
Hilary Cotter
Looking for a book on SQL Server replication?
http://www.nwsu.com/0974973602.html
"Chris Kennedy" <chrisknospam@.cybase.co.uk> wrote in message
news:OnxD4UKeEHA.3132@.TK2MSFTNGP11.phx.gbl...
> I have a table which needs to have a column called rank. When I run the
> following query I get an error about the table names being ambiguous. Is
> there a way round this. Regards, Chris.
> SELECT [Key], productdescriptionid, productdesc_name FROM FREETEXTTABLE
> (tblProductDescriptions, *,'biopsy') F JOIN tblProductDescriptions P ON
> P.productdescriptionid = F.[KEY]ORDER BY RANK DESC
>

Thursday, February 16, 2012

Ambiguos of the ORDER BY

Previously I am using mssql2000
My sql is like this
SELECT mycol, mycol FROM mytable WHERE active=1 ORDER BY mycol
This query is running fine
Then recently I upgrade my mssql server to mssql2005
The query above return an error said "ambiguos"
Then I change my query to
SELECT mycol, mycol FROM mytable WHERE active=1 ORDER BY mytable.mycol
It works.
I am confuse of why the query can work fine on mssql2000 but cant work
on mssql2005
And why it can work after I change the
ORDER BY mycol
To
ORDER BY mytable.mycol
'
Can someone explain? Thank you!brian...@.gmail.com wrote:
> Previously I am using mssql2000
> My sql is like this
> SELECT mycol, mycol FROM mytable WHERE active=1 ORDER BY mycol
> This query is running fine
> Then recently I upgrade my mssql server to mssql2005
> The query above return an error said "ambiguos"
> Then I change my query to
> SELECT mycol, mycol FROM mytable WHERE active=1 ORDER BY mytable.mycol
> It works.
> I am confuse of why the query can work fine on mssql2000 but cant work
> on mssql2005
> And why it can work after I change the
> ORDER BY mycol
> To
> ORDER BY mytable.mycol
> '
> Can someone explain? Thank you!
SQL allows duplicate column names in query results. Usually the
duplicate names come from two different tables that are joined so if
you reference such a column without specifying a qualifying alias the
result is ambiguous because you may in fact be referring to either of
two different columns.
In your case the columns with duplicate names are in fact the same
column so it doesn't really matter which you refer to but SQL Server
2005 (rightly in my view) still insists that you qualify the name with
an alias. In SQL 2000 the ORDER BY didn't generate this error message,
which caused a lot of problems and confusion when duplicate names were
used.
Arguably the designers of SQL are to blame for allowing duplicate
column names at all. You would be well advised to modify your query to
return unique column names. Otherwise how will you refer to this data
in your client app? Relying on column positional indexes isn't good
practice.
SELECT mycol AS mycol1,
mycol AS mycol2
FROM mytable
WHERE active=1
ORDER BY mycol1;
Hope this helps.
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--

ambiguity performance problem

The first query execution time less than 1 second
But the second query takes around one minute

SELECT ACC_KEY1,ACC_STATUS_LAST FROM PSSIG.CLNT_ACCOUNTS INNER JOIN PSSIG.CLNT_CUSTOMERS ON
PSSIG.CLNT_ACCOUNTS.CSTMR_OID = PSSIG.CLNT_CUSTOMERS.CSTMR_OID
WHERE (PSSIG.CLNT_CUSTOMERS.CSTMR_START_DT >= '1900-1-1 12:00:00') AND
(PSSIG.CLNT_CUSTOMERS.CSTMR_END_DT <= '2106-12-31 12:00:00') AND
(PSSIG.CLNT_ACCOUNTS.ACC_KEY1 >= '0000000000000') AND
(PSSIG.CLNT_ACCOUNTS.ACC_KEY1 <= '9999999999999') AND
(PSSIG.CLNT_ACCOUNTS.ACC_STATUS_LAST in (5,-999)) AND
ACC_KEY1 > '0' ORDER BY ACC_KEY1

SELECT ACC_KEY1,ACC_STATUS_LAST FROM PSSIG.CLNT_ACCOUNTS INNER JOIN PSSIG.CLNT_CUSTOMERS ON
PSSIG.CLNT_ACCOUNTS.CSTMR_OID = PSSIG.CLNT_CUSTOMERS.CSTMR_OID
WHERE (PSSIG.CLNT_CUSTOMERS.CSTMR_START_DT >= '1900-1-1 12:00:00') AND
(PSSIG.CLNT_CUSTOMERS.CSTMR_END_DT <= '2106-12-31 12:00:00') AND
(PSSIG.CLNT_ACCOUNTS.ACC_KEY1 >= '0000000000000') AND
(PSSIG.CLNT_ACCOUNTS.ACC_KEY1 <= '9999999999999') AND
(PSSIG.CLNT_ACCOUNTS.ACC_STATUS_LAST = 5 ) AND
ACC_KEY1 > '0' ORDER BY ACC_KEY1

Note 1 : value -999 deos not exist in the table field ACC_STATUS_LAST
Note 2 : value 5 exist in most of rows about ( 999999/1000000 ) from the table rows count
Note 3 : the number of rows in each table around 15000000

Hi,

didi you have a look at the execution plan ? The execution plan can be seen in QA (using SQL 2k) or Query Pane (using SQL2k5) graphically or by using the statement SET SHOWPLAN ON before isseing the statement.

HTH, Jens Suessmeyer.


http://www.sqlserver2005.de

|||Yeah, and then post it. I would love to see how an equality query is beat out by an OR query. This looks very much like it is probably an optimizer issue, unless the plan shows something obvious...|||

thank you for this notice ,

because there is a big difference between the access plan for both queries

and I don't now why this happen ,

Thursday, February 9, 2012

Alternative to Creating View with Union in two databases?

I attempted to create a view in SQL Server 2000 that Unions two
queries. The first part of the query gets data from the local server,
the second part gets info from a linked server. (The query works fine
in Query Analyzer.)

I received this error when I tried to save the query:

ODBC error: [Microsoft][ODBC SQL Server Driver] The operation could
not be performed because the OLE DB provider 'SQLOLEDB' was unable to
begin a distributed transaction.

[Microsft][ODBC SQL Server Driver][SQL Server][OLE/DB provider
returned message: New transaction cannot enlist in the specified
transaction coordinator.]

After a little reading I discovered the "Database limitation":
"A view can be created on a table only in the database the view
creator is accessing".

That's my problem... is there a simple solution or alternative to
creating a view?

Thanks,
Mattmattd@.semiconductor.com (Matt D) wrote in news:7bd0381c.0310070503.4d416d94@.posting.google.c om:

> That's my problem... is there a simple solution or alternative to
> creating a view?

A stored procedure will likely do the trick.

--
Ross Presser -- rpresser AT imtek DOT com
... seeking a new quote ...|||Matt D (mattd@.semiconductor.com) writes:
> I attempted to create a view in SQL Server 2000 that Unions two
> queries. The first part of the query gets data from the local server,
> the second part gets info from a linked server. (The query works fine
> in Query Analyzer.)
> I received this error when I tried to save the query:

I had no problems to create a view spanning two servers.

Since you talk about saving query, I get the idea that you might
be using Enterprise Manager for the task. Try running the CREATE VIEW
statement from Query Analyzer instead.

--
Erland Sommarskog, SQL Server MVP, sommar@.algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp