Showing posts with label company. Show all posts
Showing posts with label company. Show all posts

Friday, March 23, 2012

Outer Join - shifting result set.

I'm a quantitative securities analyst working with Compustat data
(company fiscal reports and pricing feeds).

My coworker came across a problem that we fixed, but I'd like to
understand 'why' it was happening and just don't get it yet.

Here's the starting query (reduced to simple prefixes):

--INITIAL--

declare @.mthDate datetime
set @.mthDate = (select max(datadate) from t)
declare @.wkDate datetime
set @.wkDate = (select max(datadate) from z)

Select
...
from
z
left join a on a.idA = z.idA and a.idB = z.idB
and a.datadate = z.datadate
left join b on b.idA = z.idA and b.idB = z.idB
and b.datadate = @.mthDate
left join c on c.idA = z.idA and c.idB = z.idB
and c.datadate = @.mthDate
left join d on d.idA = z.idA and d.idB = z.idB
and d.datadate = z.datadate
left join e on e.idA = z.idA
and e.datadate = @.mthDate
left join f on f.idA = e.idA and f.datadate=e.date2
left join g on g.idA = e.idA and g.datadate=e.date2
left join h on h.idA = z.idA
left join k on k.ticker = z.ticker
left join m on m.idA = z.idA and m.idB=z.idB
where
z.datadate = @.wkDate
<..some other expression filters...>
and k.ticker is null

--END INITIAL----

As you can see 'z' is the main table that things are linked to via
outer joins (our security master). Table 'k' has a list of securities
that we wish not to have results for.

There are 77 entries in table k and 4933 in table z for that given
time. We'd expect 4856 to be in this, but no. it's 4400, and then the
next time you run it (no changes whatsover) it's 2312, and so on.
Every time you execute you get a different record count.

My thought/and fix was to move the (k.ticker) predicate out of the
where clause and get a differenced set from z using NOT EXISTS:

--AMENDED-----
from
(z where not exists(select * from k where k.ticker=y.ticker)) y
left join a on a.idA = y.idA and a.idB = y.idB
and a.datadate = y.datadate
left join b on b.idA = y.idA and b.idB = y.idB
and b.datadate = @.mthDate
left join c on c.idA = y.idA and c.idB = y.idB
and c.datadate = @.mthDate
left join d on d.idA = y.idA and d.idB = y.idB
and d.datadate = y.datadate
left join e on e.idA = y.idA
and e.datadate = @.mthDate
left join f on f.idA = e.idA and f.datadate=e.date2
left join g on g.idA = e.idA and g.datadate=e.date2
left join h on h.idA = y.idA
left join k on k.ticker = y.ticker
left join m on m.idA = y.idA and m.idB=y.idB
where
y.datadate = @.wkDate
<..some other expression filters...
--------

And this works. It's stable now.

I'm hoping someone here can help me up the wisdom curve by explaining
to me 'why' the recordset kept changing before.

My guess is that the cost-based optimizer was resorting the outer joins
and handing back different sets as a result, but i want to understand,
and thought i'd come to this group for help.

I appreciate your time and look forward to replies.

Greg McIntireGreg,

it sounds like a bug to me. If the data doesn't change, then the query
result shouldn't change.

What version and service pack are you running? Can you create a
(simplified?) script that reproceduces the problem?

Gert-Jan

Greg wrote:
> I'm a quantitative securities analyst working with Compustat data
> (company fiscal reports and pricing feeds).
> My coworker came across a problem that we fixed, but I'd like to
> understand 'why' it was happening and just don't get it yet.
> Here's the starting query (reduced to simple prefixes):
> --INITIAL--
> declare @.mthDate datetime
> set @.mthDate = (select max(datadate) from t)
> declare @.wkDate datetime
> set @.wkDate = (select max(datadate) from z)
> Select
> ...
> from
> z
> left join a on a.idA = z.idA and a.idB = z.idB
> and a.datadate = z.datadate
> left join b on b.idA = z.idA and b.idB = z.idB
> and b.datadate = @.mthDate
> left join c on c.idA = z.idA and c.idB = z.idB
> and c.datadate = @.mthDate
> left join d on d.idA = z.idA and d.idB = z.idB
> and d.datadate = z.datadate
> left join e on e.idA = z.idA
> and e.datadate = @.mthDate
> left join f on f.idA = e.idA and f.datadate=e.date2
> left join g on g.idA = e.idA and g.datadate=e.date2
> left join h on h.idA = z.idA
> left join k on k.ticker = z.ticker
> left join m on m.idA = z.idA and m.idB=z.idB
> where
> z.datadate = @.wkDate
> <..some other expression filters...>
> and k.ticker is null
> --END INITIAL----
> As you can see 'z' is the main table that things are linked to via
> outer joins (our security master). Table 'k' has a list of securities
> that we wish not to have results for.
> There are 77 entries in table k and 4933 in table z for that given
> time. We'd expect 4856 to be in this, but no. it's 4400, and then the
> next time you run it (no changes whatsover) it's 2312, and so on.
> Every time you execute you get a different record count.
> My thought/and fix was to move the (k.ticker) predicate out of the
> where clause and get a differenced set from z using NOT EXISTS:
> --AMENDED-----
> from
> (z where not exists(select * from k where k.ticker=y.ticker)) y
> left join a on a.idA = y.idA and a.idB = y.idB
> and a.datadate = y.datadate
> left join b on b.idA = y.idA and b.idB = y.idB
> and b.datadate = @.mthDate
> left join c on c.idA = y.idA and c.idB = y.idB
> and c.datadate = @.mthDate
> left join d on d.idA = y.idA and d.idB = y.idB
> and d.datadate = y.datadate
> left join e on e.idA = y.idA
> and e.datadate = @.mthDate
> left join f on f.idA = e.idA and f.datadate=e.date2
> left join g on g.idA = e.idA and g.datadate=e.date2
> left join h on h.idA = y.idA
> left join k on k.ticker = y.ticker
> left join m on m.idA = y.idA and m.idB=y.idB
> where
> y.datadate = @.wkDate
> <..some other expression filters...>
> --------
> And this works. It's stable now.
> I'm hoping someone here can help me up the wisdom curve by explaining
> to me 'why' the recordset kept changing before.
> My guess is that the cost-based optimizer was resorting the outer joins
> and handing back different sets as a result, but i want to understand,
> and thought i'd come to this group for help.
> I appreciate your time and look forward to replies.
> Greg McIntire|||It's Version 8.00.194

While my ego would like to say it's not me, it's Microsoft, I'm pretty
doubtful. I think it's much more likely that it's a mental mistake...

Greg|||Well, could be, but I would install a service pack anyway. 8.00.194
means you have not installed any SQL-Server service pack, which
basically means you are missing all bug fixes of the last 5 years...

Gert-Jan

Greg wrote:
> It's Version 8.00.194
> While my ego would like to say it's not me, it's Microsoft, I'm pretty
> doubtful. I think it's much more likely that it's a mental mistake...
> Greg|||alright will talk to our tech guy. thanks a bunch.

Greg|||Greg (jacore70@.hotmail.com) writes:
> Select
> ...
> from
> z
> left join a on a.idA = z.idA and a.idB = z.idB
> and a.datadate = z.datadate
> left join b on b.idA = z.idA and b.idB = z.idB
> and b.datadate = @.mthDate
> left join c on c.idA = z.idA and c.idB = z.idB
> and c.datadate = @.mthDate
> left join d on d.idA = z.idA and d.idB = z.idB
> and d.datadate = z.datadate
> left join e on e.idA = z.idA
> and e.datadate = @.mthDate
> left join f on f.idA = e.idA and f.datadate=e.date2
> left join g on g.idA = e.idA and g.datadate=e.date2
> left join h on h.idA = z.idA
> left join k on k.ticker = z.ticker
> left join m on m.idA = z.idA and m.idB=z.idB
> where
> z.datadate = @.wkDate
> <..some other expression filters...>
> and k.ticker is null

The part with e, f and g looks suspicious to me. Not if I can tell
whether they are the cause of your SELECT:s returning a different
number. But you might want to have said:

left join (e
join f on f.idA = e.idA and f.datadate=e.date2
join g on g.idA = e.idA and g.datadate=e.date2)
on e.idA = z.idA
and e.datadate = @.mthDate

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||"Greg" <jacore70@.hotmail.com> wrote in message
news:1110566766.025803.171120@.l41g2000cwc.googlegr oups.com...
> I'm a quantitative securities analyst working with Compustat data
> (company fiscal reports and pricing feeds).
> My coworker came across a problem that we fixed, but I'd like to
> understand 'why' it was happening and just don't get it yet.
> Here's the starting query (reduced to simple prefixes):
>
> --INITIAL--
> declare @.mthDate datetime
> set @.mthDate = (select max(datadate) from t)
> declare @.wkDate datetime
> set @.wkDate = (select max(datadate) from z)
> Select
> ...
> from
> z
> left join a on a.idA = z.idA and a.idB = z.idB
> and a.datadate = z.datadate
> left join b on b.idA = z.idA and b.idB = z.idB
> and b.datadate = @.mthDate
> left join c on c.idA = z.idA and c.idB = z.idB
> and c.datadate = @.mthDate
> left join d on d.idA = z.idA and d.idB = z.idB
> and d.datadate = z.datadate
> left join e on e.idA = z.idA
> and e.datadate = @.mthDate
> left join f on f.idA = e.idA and f.datadate=e.date2
> left join g on g.idA = e.idA and g.datadate=e.date2
> left join h on h.idA = z.idA
> left join k on k.ticker = z.ticker
> left join m on m.idA = z.idA and m.idB=z.idB
> where
> z.datadate = @.wkDate
> <..some other expression filters...>
> and k.ticker is null
> --END INITIAL----
> As you can see 'z' is the main table that things are linked to via
> outer joins (our security master). Table 'k' has a list of securities
> that we wish not to have results for.
> There are 77 entries in table k and 4933 in table z for that given
> time. We'd expect 4856 to be in this, but no. it's 4400, and then the
> next time you run it (no changes whatsover) it's 2312, and so on.
> Every time you execute you get a different record count.
> My thought/and fix was to move the (k.ticker) predicate out of the
> where clause and get a differenced set from z using NOT EXISTS:
>
> --AMENDED-----
> from
> (z where not exists(select * from k where k.ticker=y.ticker)) y
> left join a on a.idA = y.idA and a.idB = y.idB
> and a.datadate = y.datadate
> left join b on b.idA = y.idA and b.idB = y.idB
> and b.datadate = @.mthDate
> left join c on c.idA = y.idA and c.idB = y.idB
> and c.datadate = @.mthDate
> left join d on d.idA = y.idA and d.idB = y.idB
> and d.datadate = y.datadate
> left join e on e.idA = y.idA
> and e.datadate = @.mthDate
> left join f on f.idA = e.idA and f.datadate=e.date2
> left join g on g.idA = e.idA and g.datadate=e.date2
> left join h on h.idA = y.idA
> left join k on k.ticker = y.ticker
> left join m on m.idA = y.idA and m.idB=y.idB
> where
> y.datadate = @.wkDate
> <..some other expression filters...>
> --------
> And this works. It's stable now.
> I'm hoping someone here can help me up the wisdom curve by explaining
> to me 'why' the recordset kept changing before.
> My guess is that the cost-based optimizer was resorting the outer joins
> and handing back different sets as a result, but i want to understand,
> and thought i'd come to this group for help.
> I appreciate your time and look forward to replies.
> Greg McIntire

Your guess sounds pretty reasonable to me.

If you use the show query plan setting in Query Analyzer, you can look and
see if the plan selected changes from execution to execution.

As a general rule ... I would take the variable comparison filtering out of
the joining and into the where clause.|||> As a general rule ... I would take the variable comparison filtering out of
> the joining and into the where clause.

You can't do that with outer joins, because that changes the meaning
(i.e. the resultset).

Gert-Jansql

Out of the box reports

Hi
My company is planning to deploy SQL Server 2005 Reporting Services to
monitor usage of a number of sites we've created using Sharepoint.
The marketing blurb says that a number of out-of-the-box reports are
available but doesn't say exactly what these reports are. Can someone
help by giving me the details?
Thanks
Tony
> My company is planning to deploy SQL Server 2005 Reporting Services to
> monitor usage of a number of sites we've created using Sharepoint.
> The marketing blurb says that a number of out-of-the-box reports are
> available but doesn't say exactly what these reports are. Can someone
> help by giving me the details?
>
The reports and the deployment guide are available for free from
Microsoft. Do a seach on microsoft.com about "Report Pack for
Sharepoint" and "Report Pack for Sharepoint Deployment Guide".
Regards,
lucm
sql

Out of the box reports

Hi
My company is planning to deploy SQL Server 2005 Reporting Services to
monitor usage of a number of sites we've created using Sharepoint.
The marketing blurb says that a number of out-of-the-box reports are
available but doesn't say exactly what these reports are. Can someone
help by giving me the details?
Thanks
Tony> My company is planning to deploy SQL Server 2005 Reporting Services to
> monitor usage of a number of sites we've created using Sharepoint.
> The marketing blurb says that a number of out-of-the-box reports are
> available but doesn't say exactly what these reports are. Can someone
> help by giving me the details?
>
The reports and the deployment guide are available for free from
Microsoft. Do a seach on microsoft.com about "Report Pack for
Sharepoint" and "Report Pack for Sharepoint Deployment Guide".
Regards,
lucm

Out of the box reports

Hi
My company is planning to deploy SQL Server 2005 Reporting Services to
monitor usage of a number of sites we've created using Sharepoint.
The marketing blurb says that a number of out-of-the-box reports are
available but doesn't say exactly what these reports are. Can someone
help by giving me the details?
Thanks
Tony> My company is planning to deploy SQL Server 2005 Reporting Services to
> monitor usage of a number of sites we've created using Sharepoint.
> The marketing blurb says that a number of out-of-the-box reports are
> available but doesn't say exactly what these reports are. Can someone
> help by giving me the details?
>
The reports and the deployment guide are available for free from
Microsoft. Do a seach on microsoft.com about "Report Pack for
Sharepoint" and "Report Pack for Sharepoint Deployment Guide".
Regards,
lucm

Tuesday, March 20, 2012

Our Application dosn't work with Sql Service pack 3

Hi , My name is Tomas
I work for a Software Developing Company ,
Our applications has been written and developed by
Power Builder 5.0 , and they can work with Sql Server 2000
normally , but when I install service pack 3.0 on our sql
server after that our application can't work with sql
server correctly , for example some queries doesn't run
and there is no result for them after installing service
pack 3,,
Please Help MeHi
First thing you need to do is run profiler on the server to see what queries
are being submitted. then pick some of those queries and run them in Query
Analyzer. In that situation, you will be able to tell if your code is
running with errors.
If your application is using more than 1 database at the same time, look at
the "Cross-Database Ownership Chaining" in books online. This was a change
introduced by SP3.
--
--
Mike Epprecht, Microsoft SQL Server MVP
Epprecht Consulting (PTY) LTD
Johannesburg, South Africa
Mobile: +27-82-552-0268
IM: mike@.NOSPAMepprecht.net
Specialist SQL Server Solutions and Consulting
"Tomas" <anonymous@.discussions.microsoft.com> wrote in message
news:01a101c3d429$41ba6c70$a001280a@.phx.gbl...
> Hi , My name is Tomas
> I work for a Software Developing Company ,
> Our applications has been written and developed by
> Power Builder 5.0 , and they can work with Sql Server 2000
> normally , but when I install service pack 3.0 on our sql
> server after that our application can't work with sql
> server correctly , for example some queries doesn't run
> and there is no result for them after installing service
> pack 3,,
> Please Help Me
>|||you should really consider upgrading powerbuilder. when did 5.0 come
out, the mid 90's?
Tomas wrote:
> Hi , My name is Tomas
> I work for a Software Developing Company ,
> Our applications has been written and developed by
> Power Builder 5.0 , and they can work with Sql Server 2000
> normally , but when I install service pack 3.0 on our sql
> server after that our application can't work with sql
> server correctly , for example some queries doesn't run
> and there is no result for them after installing service
> pack 3,,
> Please Help Me|||Especially since PB5 is no longer supported much less supported for use with
SQL2000. We're using PB9 and it works great with SQL2K.
Mike Kruchten
"ch" <ch@.dontemailme.com> wrote in message
news:3FFB0C2E.A65CF347@.dontemailme.com...
> you should really consider upgrading powerbuilder. when did 5.0 come
> out, the mid 90's?
>
> Tomas wrote:
> > Hi , My name is Tomas
> > I work for a Software Developing Company ,
> > Our applications has been written and developed by
> > Power Builder 5.0 , and they can work with Sql Server 2000
> > normally , but when I install service pack 3.0 on our sql
> > server after that our application can't work with sql
> > server correctly , for example some queries doesn't run
> > and there is no result for them after installing service
> > pack 3,,
> > Please Help Me
>

Other Replication Providers

Can anyone tell me the names of some non-Microsoft Replication providers? I
have found a company called Peer Direct, but would like to see what other
alternatives exist for replication.
Thanks in advance
Ron L
What precisely are you trying to accomplish.
Sometimes people run to 3rd party products because of problems they have
with native SQL Server replication, when a support call to PSS could solve
the problem.
Last I heard the DataMirror licenses where $30k.
"Ron L" <ronl@.bogus.Address.com> wrote in message
news:#f2fIaptEHA.2596@.TK2MSFTNGP15.phx.gbl...
> Can anyone tell me the names of some non-Microsoft Replication providers?
I
> have found a company called Peer Direct, but would like to see what other
> alternatives exist for replication.
> Thanks in advance
> Ron L
>
|||Paul
Thanks for the suggestion, I will take a look at it.
Ron L
"Paul Ibison" <Paul.Ibison@.Pygmalion.Com> wrote in message
news:177d01c4b698$1d3eb6b0$a501280a@.phx.gbl...
> DataMirror is occasionally mentioned in this newsgroup
> (http://www.datamirror.com/products/tserver/) although I
> haven't implemented it myself.
> Rgds,
> Paul Ibison (SQL Server MVP)
>
|||Hilary
Thanks for the response. We have a database that is being replicated to
2 other sites currently and will probably add anywhere from 1 to 15 sites
over the next few years. As I mentioned before, some of the sites are
disconnected for extended periods of times. In setting up and maintaining
the merge replication we have in place, we have found a number of issues
with replication that concern us from the point of long-term data transfer.
One of these issues is the fact that MS seems to strongly suggest that a
snapshot be periodically created and pushed to existing subscribers.
Another is how the retention and re-initialization procedures work. We are
not always in a situation where we can have all of the subscribers connected
at the same time to re-initialize them.
Ron L
"Hilary Cotter" <hilary.cotter@.gmail.com> wrote in message
news:O%23UgeCstEHA.1452@.TK2MSFTNGP11.phx.gbl...
> What precisely are you trying to accomplish.
> Sometimes people run to 3rd party products because of problems they have
> with native SQL Server replication, when a support call to PSS could solve
> the problem.
> Last I heard the DataMirror licenses where $30k.
> "Ron L" <ronl@.bogus.Address.com> wrote in message
> news:#f2fIaptEHA.2596@.TK2MSFTNGP15.phx.gbl...
> I
>