Home » SQL & PL/SQL » SQL & PL/SQL » Query using dblink returns more rows than direct query (Oracle 10g)
Query using dblink returns more rows than direct query [message #450370] Tue, 06 April 2010 14:25 Go to next message
steinejl
Messages: 5
Registered: April 2010
Location: Colorado
Junior Member
I have an odd occurance that I haven't seen before--and haven't been able to find any information on:

I have a query that is pulling back more rows when I use the dblink than when I hit the linked database directly.



For example:

select
x,y,z
from
mytable@dblink

returns 788,324 rows

while

select
x,y,z
from
mytable

returns 712,102 rows

It's the exact same query, with the only difference being the dblink. It's not pulling the data into a cursor or array, it's a simple, straightforward query on a remote database.

Has anyone else ever come across this or do they have information on why this would happen?


Thx,
J
Re: Query using dblink returns more rows than direct query [message #450371 is a reply to message #450370] Tue, 06 April 2010 14:32 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>Has anyone else ever come across this or do they have information on why this would happen?
Oracle is too dumb to lie or mis-report reality.

Is the difference due to DML against table between the 2 queries?


It would be helpful if you followed Posting Guidelines - http://www.orafaq.com/forum/t/88153/0/
Re: Query using dblink returns more rows than direct query [message #450375 is a reply to message #450371] Tue, 06 April 2010 15:36 Go to previous messageGo to next message
steinejl
Messages: 5
Registered: April 2010
Location: Colorado
Junior Member
BlackSwan wrote on Tue, 06 April 2010 13:32
>Has anyone else ever come across this or do they have information on why this would happen?
Oracle is too dumb to lie or mis-report reality.

Is the difference due to DML against table between the 2 queries?


Perhaps I didn't explain this well enough.

This is a simple straighforward query:

select
x,y,z
from
table

When I run the query remotely, using a dblink, I'm pulling back 788,000 rows. When I run the EXACT same query on the host without the dblink, I'm only pulling back 712,000 rows.

There is no procedure involved, no cursors, no arrays, no difference except for one is being run on the host (no link) and one is remote (with link). It's a simple select statement, pulling from a single table. I found this quirk while doing data validation.

I've tried running this at different times in the day--made sure to flush my buffers, etc., and I'm getting the same results each time. I've also had someone else test this too--from a different remote location. Same result.

If I were getting more when I run it on the host, I would be inclined to say it was the link. If I were bringing it into a cursor or an array, I'd be inclined to say it was an issue with how it was being brought in.

The dblink is used for other queries, as well--without issue and the rowcount when tested between remote and host is identical on those more complex queries.

As I noted previously, this is an oddity--and it isn't something I've encountered over the past 10 years of doing this. I was hoping someone else may have run into it and had an idea of what may be occuring.

Thanks anyway tho...Smile

[EDITED by LF: fixed [quote] tags]

[Updated on: Wed, 07 April 2010 00:59] by Moderator

Report message to a moderator

Re: Query using dblink returns more rows than direct query [message #450379 is a reply to message #450370] Tue, 06 April 2010 16:49 Go to previous messageGo to next message
Kevin Meade
Messages: 2103
Registered: December 1999
Location: Connecticut USA
Senior Member
All IT eggheads are by nature pig headed and stubborn and lazy and full of themselves. Soon as we see something unusualy we start thinking "looks like and oracle bug to me".

OK so I have found my share of true oracle bugs in my day. But I have also worked on problems that seemed to have no obvious error on my part for hours to the point of thinking maybe it was a bug, only to spend another hour on it to see it was simple operator error.

So... I suggest to you that the most obvious answer to the reason why to identical queries return different results is because one of them is looking at a different table whether you recognize this fact or not. This means that the dblink is likely not logging into the user as you think it is.

Good luck, Kevin
Re: Query using dblink returns more rows than direct query [message #450381 is a reply to message #450379] Tue, 06 April 2010 17:05 Go to previous messageGo to next message
steinejl
Messages: 5
Registered: April 2010
Location: Colorado
Junior Member
Kevin,
Thanks for the input--
I thought about that possibility, too (not connecting to correct table). Along with possible collision issues, and a plethora of other issues that could have arisen. I even looked at the possibility that there could be changes within the db between run time of one and the other.

I'm connecting to a state databases, which has only 1 login per county, along with 1 user per county. I had another county test the code, along with another internal DBA to make sure it wasn't an *obvious* (or not so obvious) operator error. The state is pretty anal about what we're allowed to connect to and what we aren't Smile.

I'm checking with one of my state counterparts to see if it's something they've experienced and to have them test it too.

Again, thank you.

Re: Query using dblink returns more rows than direct query [message #450382 is a reply to message #450381] Tue, 06 April 2010 17:17 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
From where I sit, one of two realities exist.
1) You are mistaken about what you are reporting; though you do not know or understand why this is the case.
2) It is an Oracle bug.

If it is an Oracle bug, you will need to put together a test case so Oracle can reproduce the failure.

If it is a bug, we should be able to reproduce it, too.
So how can we reproduce what you report?

If I were a betting person, I'd place my money on #1 above.

Can/will you post a test case that proves me wrong?
Re: Query using dblink returns more rows than direct query [message #450430 is a reply to message #450382] Wed, 07 April 2010 03:21 Go to previous messageGo to next message
JRowbottom
Messages: 5933
Registered: June 2006
Location: Sunny North Yorkshire, ho...
Senior Member
Quote:
If it is a bug, we should be able to reproduce it, too.


Well yes, if we've got exactly the same version of Oracle, on exactly the same hardware, using the same data with the same physical layout of data.

I've had problems similar to this which went away when we rebuilt the table - it's optimistic to assume that this is going to bea simple one to reproduce.

@Op: Which query is returning the correct row set?
Are the extra rows that are returned valid data, or are they duplicates of existing data - ie is the query that is erroring missing out valid data, or creating additional data?
Re: Query using dblink returns more rows than direct query [message #450434 is a reply to message #450370] Wed, 07 April 2010 03:57 Go to previous messageGo to next message
cookiemonster
Messages: 13967
Registered: September 2008
Location: Rainy Manchester
Senior Member
One possibility that springs to mind is that you might have a corrupted index. If one of the queries is using the index and the other isn't then the one using it will give the wrong data.
Re: Query using dblink returns more rows than direct query [message #450503 is a reply to message #450430] Wed, 07 April 2010 10:11 Go to previous messageGo to next message
steinejl
Messages: 5
Registered: April 2010
Location: Colorado
Junior Member
JRowbottom wrote on Wed, 07 April 2010 02:21
Quote:
If it is a bug, we should be able to reproduce it, too.


Well yes, if we've got exactly the same version of Oracle, on exactly the same hardware, using the same data with the same physical layout of data.

I've had problems similar to this which went away when we rebuilt the table - it's optimistic to assume that this is going to bea simple one to reproduce.

@Op: Which query is returning the correct row set?
Are the extra rows that are returned valid data, or are they duplicates of existing data - ie is the query that is erroring missing out valid data, or creating additional data?


It's also optimistic to hope there was/is an easy way to fix something that may be out of my hands. Smile I reckon if the state feels it is worth their time and energy, they'll hand it over to Oracle.

Since this came to light, I've reached out to several people who are able to access the server and data sets that are being used. While they aren't using the exact same hardware, etc., they did reproduce the issue.

I can't be sure which of the two data sets is the *most valid*, I'm working on an effective way to compare the two--honestly, I'm hoping it is just pulling a partially duplicated set since that will be easier to accomodate for than missing data.

Thank you for your input--it does help.
Re: Query using dblink returns more rows than direct query [message #450504 is a reply to message #450434] Wed, 07 April 2010 10:12 Go to previous messageGo to next message
steinejl
Messages: 5
Registered: April 2010
Location: Colorado
Junior Member
cookiemonster wrote on Wed, 07 April 2010 02:57
One possibility that springs to mind is that you might have a corrupted index. If one of the queries is using the index and the other isn't then the one using it will give the wrong data.



As I try to figure this out, I'll keep that one in mind.
Thank you.
Re: Query using dblink returns more rows than direct query [message #450515 is a reply to message #450504] Wed, 07 April 2010 11:58 Go to previous message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
It might be an interesting exercise to SQL_TRACE=TRUE for both SQL & then compare and contrast both results.
Previous Topic: PLS-00103
Next Topic: help on Query
Goto Forum:
  


Current Time: Fri Jun 20 05:48:39 CDT 2025