Terrifying result of sql-query, need explanation. [message #608274] |
Tue, 18 February 2014 05:33 |
|
Cott
Messages: 14 Registered: February 2014
|
Junior Member |
|
|
Hello!
I have some table csp_psv with the list of the fields.
When i'm trying to get the data with the query
select t.*
from csp_psv t
where psv_raion_id is null or psv_raion_id = 1;
i get 1165 rows. When i'm trying to get the count of the rows with query
select count(1)
from csp_psv t
where psv_raion_id is null or psv_raion_id = 1;
the result is 399.
The query
select *
from csp_psv t
where psv_raion_id is null;
returns 399 rows, the query
select *
from csp_psv t
where psv_raion_id = 1;
returns 0 rows.
What's going on? What is the possible reason of this?
Thank you.
----
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Release 10.2.0.4.0 - Production
CORE 10.2.0.4.0 Production
TNS for Linux: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production
|
|
|
|
|
|
|
|
|
|
|
Re: Terrifying result of sql-query, need explanation. [message #608286 is a reply to message #608285] |
Tue, 18 February 2014 06:43 |
ThomasG
Messages: 3211 Registered: April 2005 Location: Heilbronn, Germany
|
Senior Member |
|
|
If
select t.*
from csp_psv t
where psv_raion_id is null or psv_raion_id = 1;
gets 1165 rows, I would be curious what the result of this count is:
select count(*) from (
select t.*
from csp_psv t
where psv_raion_id is null or psv_raion_id = 1
);
|
|
|
|
|
|
Re: Terrifying result of sql-query, need explanation. [message #608292 is a reply to message #608291] |
Tue, 18 February 2014 07:36 |
John Watson
Messages: 8930 Registered: January 2010 Location: Global Village
|
Senior Member |
|
|
If I understand this correctly, the number of rows returned is dependent on which columns you project. This can be an effect of row level security (or VPD). I cannot remember the detail of the 10.2 VPD capabiities, but certainly in 11.x it is possible for filters to be applied depending on this. Are there any VPD policies on that table?
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: Terrifying result of sql-query, need explanation. [message #608451 is a reply to message #608450] |
Wed, 19 February 2014 19:45 |
rleishman
Messages: 3728 Registered: October 2005 Location: Melbourne, Australia
|
Senior Member |
|
|
Can you get a ROWID added to one of the spurious queries?
select ian_name1, ROWID
from csp_psv t
where nvl(trim(psv_raion_id),1) = 1;
Does it still return 540 rows?
Are all ROWIDs distinct?
This is probably all a bit academic and for our amusement. I reckon you have a corruption.
Ross Leishman
|
|
|
Re: Terrifying result of sql-query, need explanation. [message #608466 is a reply to message #608450] |
Thu, 20 February 2014 03:03 |
Roachcoach
Messages: 1576 Registered: May 2010 Location: UK
|
Senior Member |
|
|
rleishman wrote on Thu, 20 February 2014 01:40Roachcoach wrote on Wed, 19 February 2014 22:44Stale tolerated MV query rewrite?
Wouldn't a query rewrite show up in the Explain Plan?
Ross Leishman
I'd have thought so (though it's been a while since I looked) but the only explain plans for the actual problem queries were generated via a GUI and
a) I don't trust GUIs
b) I can't think of anything else remotely plausible because it's too simple a query on the surface to be a bug (imho)
|
|
|