Showing posts with label apparently. Show all posts
Showing posts with label apparently. Show all posts

Thursday, March 29, 2012

Count Query Performance

I have a query that seems simple but apparently is not.Any thoughts on performance optimization would be helpful.The following query works, but it takes 20 minutes to run.

WITH

MEMBER [Measures].[90-100] AS

'COUNT( FILTER( EXISTING [Student].[Student].[Student].Members, [Measures].[Avg Attendance] >.90)

)'

MEMBER [Measures].[80-90] AS

'COUNT(FILTER( EXISTING [Student].[Student].[Student].Members, [Measures].[Avg Attendance] >.80

AND [Measures].[Avg Attendance] <.90)

)'

SELECT

{[Measures].[90-100], [Measures].[80-90]} ON COLUMNS,

NON EMPTY EXISTING [School].[By District Area].[School].MEMBERS ON ROWS

FROM [Student Engagement]

There has got to be a better way. My guess is that somehow I need to limit the resulting set of schools * students that get counted to only the nonempties, but I’m not sure how to formulate the MDX.

Any ideas?

Chris

Instead of EXISTING in the calculated measures, which isn't needed unless other attributes of the [Student] dimension are placed on query axes, you could try NonEmpty(), like:

WITH

MEMBER [Measures].[90-100] AS

COUNT( FILTER( NonEmpty([Student].[Student].[Student].Members,

{[Measures].[AttendFactCount]}),

[Measures].[Avg Attendance] >.90)

)

MEMBER [Measures].[80-90] AS

COUNT(FILTER( NonEmpty([Student].[Student].[Student].Members,

{[Measures].[AttendFactCount]}),

[Measures].[Avg Attendance] >.80

AND [Measures].[Avg Attendance] <.90)

)

where [AttendFactCount] is some cube measure from the relevant measure group (assuming that [Avg Attendance] is a calculated measure like: [PresentSum] / [AttendFactCount]).|||

Deepak-

Thank you! Inserting the “NonEmpty” worked. The query returned in 5 seconds.

The question is why.Given, that I had “Non Empty” in the select statement and the NonEmptyBehavior(NEB) set to [Measures].[Absence] for the calculated member [Measures].[Avg Attendance] (Avg Attendance = Absence/ Enrollment) in the initial query,I would have assumed that the query engine would suppress the non empties automatically based on the NEB.Can you help me understand?

Chris

|||

Chris,

The “Non Empty” in the select statement wouldn't help because, if the 2 calculated measures are simply defined as counts, they could be 0, but never empty. Regarding the NEB, I'm not sure; but it could be that the query optimizer doesn't infer from the condition: [Avg Attendance] > 0.9 that [Avg Attendance] isn't empty. You could check whether changing the condition to: Not IsEmpty([Avg Attendance]) And [Avg Attendance] > 0.9 speeds up the query.

Wednesday, March 7, 2012

could not find stored procdure xp_availablemedia

hi.
I am getting this error when I try to restore database from device
and try to choose 'filename'.
It's apparently I am missing xp_availablemedia stored procedure, but
where can I get a copy of this and put it in?
Please don't say I need to install full sqlserver again.
Try this first:
SELECT * from master..sysobjects where LOWER(name) = 'xp_availablemedia'
How many rows did it return?
If zero, try
sp_addextendedproc N'xp_availablemedia',N'xpstar.dll'
Make sure you are logged on as sysadmin and are in the master database
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
<jkim65@.socal.rr.com> wrote in message news:1111731156.502015.190160@.l41g2000cwc.googlegr oups.com...
> hi.
> I am getting this error when I try to restore database from device
> and try to choose 'filename'.
> It's apparently I am missing xp_availablemedia stored procedure, but
> where can I get a copy of this and put it in?
> Please don't say I need to install full sqlserver again.
>
|||it says
could not find stored procedure 'master.dbo.xp_fixeddrives'.
I guess maybe a bunch of stored procedure in master was deleted for
some reason.
I think I am going to somehow copy these stored procedures from some
other machine.
thanks for the reply.
|||> could not find stored procedure 'master.dbo.xp_fixeddrives'.
Are you saying that below query, executed from Query Analyzer returned that error?
SELECT * from master..sysobjects where LOWER(name) = 'xp_availablemedia'
If so, you have some serious issues with your installation.

> I think I am going to somehow copy these stored procedures from some
> other machine.
These are not regular stored procedures. The code for extended stored are in DLL files, and the code
I posted earlier adds the code in the DLL file to SQL Server so it is accessible through TSQL. Did
you try it? Here it is again:
sp_addextendedproc N'xp_availablemedia',N'xpstar.dll'
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
<jkim65@.socal.rr.com> wrote in message news:1111945063.141236.209750@.f14g2000cwb.googlegr oups.com...
> it says
> could not find stored procedure 'master.dbo.xp_fixeddrives'.
> I guess maybe a bunch of stored procedure in master was deleted for
> some reason.
> I think I am going to somehow copy these stored procedures from some
> other machine.
> thanks for the reply.
>

could not find stored procdure xp_availablemedia

hi.
I am getting this error when I try to restore database from device
and try to choose 'filename'.
It's apparently I am missing xp_availablemedia stored procedure, but
where can I get a copy of this and put it in?
Please don't say I need to install full sqlserver again.Try this first:
SELECT * from master..sysobjects where LOWER(name) = 'xp_availablemedia'
How many rows did it return?
If zero, try
sp_addextendedproc N'xp_availablemedia',N'xpstar.dll'
Make sure you are logged on as sysadmin and are in the master database
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
<jkim65@.socal.rr.com> wrote in message news:1111731156.502015.190160@.l41g2000cwc.googlegroup
s.com...
> hi.
> I am getting this error when I try to restore database from device
> and try to choose 'filename'.
> It's apparently I am missing xp_availablemedia stored procedure, but
> where can I get a copy of this and put it in?
> Please don't say I need to install full sqlserver again.
>|||it says
could not find stored procedure 'master.dbo.xp_fixeddrives'.
I guess maybe a bunch of stored procedure in master was deleted for
some reason.
I think I am going to somehow copy these stored procedures from some
other machine.
thanks for the reply.|||> could not find stored procedure 'master.dbo.xp_fixeddrives'.
Are you saying that below query, executed from Query Analyzer returned that
error?
SELECT * from master..sysobjects where LOWER(name) = 'xp_availablemedia'
If so, you have some serious issues with your installation.

> I think I am going to somehow copy these stored procedures from some
> other machine.
These are not regular stored procedures. The code for extended stored are in
DLL files, and the code
I posted earlier adds the code in the DLL file to SQL Server so it is access
ible through TSQL. Did
you try it? Here it is again:
sp_addextendedproc N'xp_availablemedia',N'xpstar.dll'
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
<jkim65@.socal.rr.com> wrote in message news:1111945063.141236.209750@.f14g2000cwb.googlegroup
s.com...
> it says
> could not find stored procedure 'master.dbo.xp_fixeddrives'.
> I guess maybe a bunch of stored procedure in master was deleted for
> some reason.
> I think I am going to somehow copy these stored procedures from some
> other machine.
> thanks for the reply.
>

could not find stored procdure xp_availablemedia

hi.
I am getting this error when I try to restore database from device
and try to choose 'filename'.
It's apparently I am missing xp_availablemedia stored procedure, but
where can I get a copy of this and put it in?
Please don't say I need to install full sqlserver again.Try this first:
SELECT * from master..sysobjects where LOWER(name) = 'xp_availablemedia'
How many rows did it return?
If zero, try
sp_addextendedproc N'xp_availablemedia',N'xpstar.dll'
Make sure you are logged on as sysadmin and are in the master database
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
<jkim65@.socal.rr.com> wrote in message news:1111731156.502015.190160@.l41g2000cwc.googlegroups.com...
> hi.
> I am getting this error when I try to restore database from device
> and try to choose 'filename'.
> It's apparently I am missing xp_availablemedia stored procedure, but
> where can I get a copy of this and put it in?
> Please don't say I need to install full sqlserver again.
>|||it says
could not find stored procedure 'master.dbo.xp_fixeddrives'.
I guess maybe a bunch of stored procedure in master was deleted for
some reason.
I think I am going to somehow copy these stored procedures from some
other machine.
thanks for the reply.|||> could not find stored procedure 'master.dbo.xp_fixeddrives'.
Are you saying that below query, executed from Query Analyzer returned that error?
SELECT * from master..sysobjects where LOWER(name) = 'xp_availablemedia'
If so, you have some serious issues with your installation.
> I think I am going to somehow copy these stored procedures from some
> other machine.
These are not regular stored procedures. The code for extended stored are in DLL files, and the code
I posted earlier adds the code in the DLL file to SQL Server so it is accessible through TSQL. Did
you try it? Here it is again:
sp_addextendedproc N'xp_availablemedia',N'xpstar.dll'
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
<jkim65@.socal.rr.com> wrote in message news:1111945063.141236.209750@.f14g2000cwb.googlegroups.com...
> it says
> could not find stored procedure 'master.dbo.xp_fixeddrives'.
> I guess maybe a bunch of stored procedure in master was deleted for
> some reason.
> I think I am going to somehow copy these stored procedures from some
> other machine.
> thanks for the reply.
>