Help: Selecting * from view takes minutes, query in view takes only seconds
Hello,
I have a view that i created that compiles ok and the query inside of the view only takes 2 seconds to return all the records. But if i try to select * from the view it takes 4-5 minutes to return the results. The explain plan is exactly the same, whether i select * from the view or run the query from within the view. Explain plan listed at bottom of post. Any ideas on where i might be going wrong? Thanks in advance.
The below query returns ~400 rows. If i limit the rows returned to ~200 with this additional line at the very end:
AND TEAM_CATEGORY LIKE '%FSM%'
the query runs in just a few seconds. So the rows returned is not the problem here.
Code:
SELECT /*+ PUSH_PRED( TEAM ) */ NP.ID_NUMBER,
NP.PROSPECT_ID,
NP.PREF_MAIL_NAME PROSPECT,
NP.OFFICER_RATING RATING,
NP.EVALUATION_RATING EVALUATION,
P.ASK_AMT NEXT_ASK,
P.ANTICIPATED_AMT EXPECT,
NP.STRATEGY_DESCRIPTION STRATEGY,
E1.LAST_NAME PROSPECT_MGR,
TEAM.TEAM_CATEGORY,
CASE
WHEN TOPA.SHORT_DESC <> ' ' THEN
'X'
END TOPA,
E.PREF_MAIL_NAME SPOUSE_NAME,
PR.PROSPECT_NAME_SORT SORT_NAME
FROM ADVANCE_NU.NWU_PROSPECT NP,
entity E,
entity E1,
assignment ASSI,
prospect PR,
(select p.proposal_id, p.prospect_id, p.ask_amt, p.anticipated_amt
from proposal p
where p.active_ind = 'Y'
AND (p.stop_date IS NULL OR p.stop_date > sysdate)) P,
(SELECT PC.PROSPECT_ID ID, TP.SHORT_DESC
FROM PROSPECT_CATEGORY PC, TMS_PROSPECT_CATEGORY TP
WHERE PC.PROSPECT_CATEGORY_CODE = TP.PROSPECT_CATEGORY_CODE
AND pc.prospect_category_code = 'TOP') TOPS,
(SELECT PC.PROSPECT_ID ID, TP.SHORT_DESC
FROM PROSPECT_CATEGORY PC, TMS_PROSPECT_CATEGORY TP
WHERE PC.PROSPECT_CATEGORY_CODE = TP.PROSPECT_CATEGORY_CODE
AND pc.prospect_category_code = 'TFP') TOPA,
(SELECT ID,
CASE WHEN count(TEAM_CAT) >= 1 THEN MAX(DECODE(CT, 1, TEAM_CAT)) ELSE ' ' END
|| CASE WHEN count(TEAM_CAT) >= 2 THEN ', ' || MAX(DECODE(CT, 2, TEAM_CAT)) ELSE ' ' END
|| CASE WHEN count(TEAM_CAT) >= 3 THEN ', ' || MAX(DECODE(CT, 3, TEAM_CAT)) ELSE ' ' END
|| CASE WHEN count(TEAM_CAT) >= 4 THEN ', ' || MAX(DECODE(CT, 4, TEAM_CAT)) ELSE ' ' END
|| CASE WHEN count(TEAM_CAT) >= 5 THEN ', ' || MAX(DECODE(CT, 5, TEAM_CAT)) ELSE ' ' END
|| CASE WHEN count(TEAM_CAT) >= 6 THEN ', ' || MAX(DECODE(CT, 6, TEAM_CAT)) ELSE ' ' END
TEAM_CATEGORY
FROM (SELECT PC.PROSPECT_ID ID,
ROW_NUMBER() OVER(PARTITION BY PC.PROSPECT_ID ORDER BY PC.PROSPECT_CATEGORY_CODE ASC) CT,
TP.SHORT_DESC TEAM_CAT
FROM PROSPECT_CATEGORY PC, TMS_PROSPECT_CATEGORY TP
WHERE PC.PROSPECT_CATEGORY_CODE = TP.PROSPECT_CATEGORY_CODE
AND PC.PROSPECT_CATEGORY_CODE NOT IN ('TOP', 'TFP'))
GROUP BY ID) TEAM
WHERE NP.PROSPECT_ID = P.PROSPECT_ID(+)
AND NP.spouse_id = E.id_number(+)
AND NP.prospect_id = PR.prospect_id
AND NP.PROSPECT_ID = TOPS.ID
AND NP.PROSPECT_ID = TEAM.ID(+)
AND NP.prospect_id = TOPA.ID(+)
AND NP.PROSPECT_ID = ASSI.PROSPECT_ID(+)
AND ASSI.ASSIGNMENT_ID_NUMBER = E1.ID_NUMBER(+)
AND ASSI.ASSIGNMENT_TYPE(+) = 'PM';Explain plan:
SELECT STATEMENT, GOAL = CHOOSE 346 1 369 346
HASH JOIN OUTER 346 1 369 346
HASH JOIN OUTER 332 1 330 332
NESTED LOOPS OUTER 326 1 190 326
NESTED LOOPS OUTER 325 1 171 325
NESTED LOOPS OUTER 323 1 152 323
NESTED LOOPS OUTER 322 1 119 322
NESTED LOOPS 320 1 90 320
NESTED LOOPS 319 1 67 319
NESTED LOOPS 319 484568 24712968 319
INDEX UNIQUE SCAN ADVANCE ZZ_ADV_TABLE_KEY0 1 1 8 1
TABLE ACCESS FULL ADVANCE_NU NWU_PROSPECT 318 484568 20836424 318
TABLE ACCESS BY INDEX ROWID ADVANCE PROSPECT_CATEGORY 1 16
INDEX RANGE SCAN ADVANCE PROSPECT_CATEGORY_KEY2 1
TABLE ACCESS BY INDEX ROWID ADVANCE PROSPECT 1 1 23 1
INDEX UNIQUE SCAN ADVANCE PROSPECT_KEY0 1
VIEW PUSHED PREDICATE RPT_ACEPONIS 2 1 29
NESTED LOOPS 2 1 40 2
TABLE ACCESS BY INDEX ROWID ADVANCE ZZ_ADV_TABLE 2 1 24 2
INDEX UNIQUE SCAN ADVANCE ZZ_ADV_TABLE_KEY0 1 1 1
TABLE ACCESS BY INDEX ROWID ADVANCE PROSPECT_CATEGORY 1 16
INDEX RANGE SCAN ADVANCE PROSPECT_CATEGORY_KEY2 1
TABLE ACCESS BY INDEX ROWID ADVANCE ENTITY 1 1 33 1
INDEX UNIQUE SCAN ADVANCE ENTITY_KEY0 1
TABLE ACCESS BY INDEX ROWID ADVANCE ASSIGNMENT 2 1 19 2
INDEX RANGE SCAN ADVANCE ASSIGN_PROSPECT_KEY0 1 3 1
TABLE ACCESS BY INDEX ROWID ADVANCE ENTITY 1 1 19 1
INDEX UNIQUE SCAN ADVANCE ENTITY_KEY0 1
VIEW RPT_ACEPONIS 5 1 140
SORT GROUP BY 5 1 48 5
VIEW RPT_ACEPONIS 5 1 48
WINDOW SORT 5 1 40 5
NESTED LOOPS 2 1 40 2
TABLE ACCESS FULL ADVANCE PROSPECT_CATEGORY 2 1 16 2
TABLE ACCESS BY INDEX ROWID ADVANCE ZZ_ADV_TABLE 1 24
INDEX UNIQUE SCAN ADVANCE ZZ_ADV_TABLE_KEY0 1
VIEW RPT_ACEPONIS 13 170 6630
SORT UNIQUE 13 170 32980 7
UNION-ALL
TABLE ACCESS FULL ADVANCE PROPOSAL 3 125 24250 3
TABLE ACCESS FULL ADVANCE PROPOSAL 3 45 8730 3Message was edited by:
user624909
Message was edited by:
user624909
Message was edited by:
AndyCep
I'm no expert. Hopefully, someone else will chime in.
A couple points though:
1) (select p.*
from proposal p
where p.active_ind = 'Y'
AND p.stop_date > sysdate
union
select p.*
from proposal p
where p.active_ind = 'Y'
AND p.stop_date is null) P,
is using UNION. It should probably be a UNION ALL, or even better:
(select p.*
from proposal p
where p.active_ind = 'Y'
AND (p.stop_date IS NULL OR p.stop_date > sysdate)
2) select p.*
Do not use * in a VIEW. In fact, never use it outside EXISTS, COUNT(*) and ad hoc queries.
Use a COLUMN-list instead. Always use a COLUMN-list.
3)
The CASE statement has no ELSE, and is redundant.
CASE
WHEN count(TEAM_CAT) = 1 THEN MAX(DECODE(CT, 1, TEAM_CAT))
WHEN count(TEAM_CAT) = 2 THEN MAX(DECODE(CT, 1, TEAM_CAT)) || ', ' || MAX(DECODE(CT, 2, TEAM_CAT))
WHEN count(TEAM_CAT) = 3 THEN MAX(DECODE(CT, 1, TEAM_CAT)) || ', ' || MAX(DECODE(CT, 2, TEAM_CAT)) || ', ' || MAX(DECODE(CT, 3, TEAM_CAT))
WHEN count(TEAM_CAT) = 4 THEN MAX(DECODE(CT, 1, TEAM_CAT)) || ', ' || MAX(DECODE(CT, 2, TEAM_CAT)) || ', ' || MAX(DECODE(CT, 3, TEAM_CAT)) || ', ' || MAX(DECODE(CT, 4, TEAM_CAT))
WHEN count(TEAM_CAT) = 5 THEN MAX(DECODE(CT, 1, TEAM_CAT)) || ', ' || MAX(DECODE(CT, 2, TEAM_CAT)) || ', ' || MAX(DECODE(CT, 3, TEAM_CAT)) || ', ' || MAX(DECODE(CT, 4, TEAM_CAT)) || ', ' || MAX(DECODE(CT, 5, TEAM_CAT))
WHEN count(TEAM_CAT) = 6 THEN MAX(DECODE(CT, 1, TEAM_CAT)) || ', ' || MAX(DECODE(CT, 2, TEAM_CAT)) || ', ' || MAX(DECODE(CT, 3, TEAM_CAT)) || ', ' || MAX(DECODE(CT, 4, TEAM_CAT)) || ', ' || MAX(DECODE(CT, 5, TEAM_CAT)) || ', ' || MAX(DECODE(CT, 6, TEAM_CAT))
END TEAM_CATEGORY
How about something like:
CASE WHEN count(TEAM_CAT) >= 1 THEN MAX(DECODE(CT, 1, TEAM_CAT)) ELSE ' ' END
|| CASE WHEN count(TEAM_CAT) >= 2 THEN ', ' || MAX(DECODE(CT, 2, TEAM_CAT)) ELSE ' ' END
|| CASE WHEN count(TEAM_CAT) >= 3 THEN ', ' || MAX(DECODE(CT, 3, TEAM_CAT)) ELSE ' ' END
|| CASE WHEN count(TEAM_CAT) >= 4 THEN ', ' || MAX(DECODE(CT, 4, TEAM_CAT)) ELSE ' ' END
|| CASE WHEN count(TEAM_CAT) >= 5 THEN ', ' || MAX(DECODE(CT, 5, TEAM_CAT)) ELSE ' ' END
|| CASE WHEN count(TEAM_CAT) >= 6 THEN ', ' || MAX(DECODE(CT, 6, TEAM_CAT)) ELSE ' ' END
TEAM_CATEGORY
4) I have to ask. Have you run statistics lately?
5) Did you really alias a TABLE as "***"? Please tell me that is a formatting error.
6) Are you sure you need all those outer joins?
Similar Messages
-
Help selecting from records with duplicate fields
Test_table2 is shown below with the sql to create it.
I need to:
Identify duplicate address_keys
Within that set of duplicate address_keys, select only if HH_Income is the same between the two records and the HH_Age difference is less than 10
Now the duplicate set matches the necessary criteria, and I want to select from these duplicate address_keys, only the one with the most recent verification date
The purpose of this is to infer cohabiting couples. In the large set of data we receive, for each HH_key if the people have the same last name they are all listed under the same HH_Key, but if they do not have same last name but live together, they will be listed as separate households (HH_key) but with the same address_key. A further validator is if each HH_key reports the same HH_Income and if they are close in age. We then only want to mail to one of the people, so we choose the one that has the most recent verification date.
The result I would expect here, using the table I provided, would be
HH_Key
Address_Key
HH_Type
HH_Income
Age
Verification_Date
1234
1111
10
6
50
10-Jun-13
Can you help?
HH_Key
Address_Key
HH_Type
HH_Income
Age
Verification_Date
1234
1111
10
6
50
10-Jun-13
5678
1111
11
6
49
15-Jun-12
5544
2222
10
6
65
10-Apr-13
7788
1111
3
3
25
10-Jun-13
9898
3333
10
6
45
18-Jun-13
CREATE TABLE test_table2
(HH_key varchar(20),
address_key varchar(20),
HH_type varchar(2),
HH_Income varchar(2),
HH_age varchar(2),
Verification_date Date
INSERT INTO test_table2
(HH_Key, Address_key, HH_Type, HH_Income, HH_Age, Verification_date)
VALUES
(1234, 1111, 10, 6, 50, '10-Jun-13');
INSERT INTO test_table2
(HH_Key, Address_key,HH_Type, HH_Income, HH_Age, Verification_date)
VALUES
(5678, 1111, 11, 6, 49, '15-Jun-12');
INSERT INTO test_table2
(HH_Key, Address_key,HH_Type, HH_Income, HH_Age, Verification_date)
VALUES
(5544, 2222, 10, 6, 65, '10-Apr-13');
INSERT INTO test_table2
(HH_Key, Address_key,HH_Type, HH_Income, HH_Age, Verification_date)
VALUES
(7788, 1111, 3, 3, 25, '10-Jun-13');
INSERT INTO test_table2
(HH_Key, Address_key,HH_Type, HH_Income, HH_Age, Verification_date)
VALUES
(9898, 3333, 10, 6, 45, '18-Jun-13');I really like the results this gave, because it allows me to create a view now that contains the pair in one record. Thanks for this response. I think I did post the result that I was looking for which would be the one record that we would mail to: Once I create the view with one record for each pair, then I would just need to select the verification date that was greatest with the related data. Would that be the best approach to take? The fact that I now have a single record for each pair is excellent!
The result I would expect here, using the table I provided, would be
HH_Key
Address_Key
HH_Type
HH_Income
Age
Verification_Date
1234
1111
10
6
50
10-Jun-13 -
Can u find (number of rows) + (SELECT * FROM emp) in 1 query?
We have a requirement like this: We need to pass a SQL statement as a SYS_REFCURSOR OUT variable from a SP. Problem is, if the SQL returned 0 rows we have to send 1 row with all NULLS to the SYS_REFCURSOR.
Is there any way to find out the number of rows returned from a SQL without having to put a SELECT COUNT(*) again using the "same" SQL?Peter:
That only works if the cursor actually returns rows. Consider:
SQL> create table t as
2 select rownum id, to_char(to_date(rownum, 'J'), 'Jsp') descr
3 from user_objects
4 where rownum <= 5;
Table created.
SQL> insert into t select * from t;
5 rows created.
SQL> commit;
Commit complete.
SQL> create function f (p_id in number) return sys_refcursor as
2 l_cur sys_refcursor;
3 begin
4 open l_cur for
5 select id, descr, count(*) over() cnt
6 from t
7 where id = p_id;
8 return l_cur;
9 end;
10 /
Function created.
SQL> var cur refcursor
SQL> exec :cur := f(1);
PL/SQL procedure successfully completed.
SQL> print cur
ID DESCR CNT
1 One 2
1 One 2
SQL> exec :cur := f(42);
PL/SQL procedure successfully completed.
SQL> print cur
no rows selectedSince the OP's requirement (or ""solution" coming from someone who misunderstood the concept of cursors") is that "if the SQL returned 0 rows we have to send 1 row with all NULLS to the SYS_REFCURSOR" the analytic count doesn't help.
@OP
The only reliable (for certain definitions of reliable) way would be to consume the first row of the cursor to see if it did in fact return any rows.
However, if the cursor was initally empty, we then need to generate a new cursor with all NULLS to satisfy the request. Not a big deal, as the new cursor would reflect the state of the database at the time of the initial query, even if a qualifying row was inserted and committed between the first query and the second, but it doesn't work the other way around.
If I consume the first row and find a record, then I need to re-do the query to get all of the rows. but what happens if another process changes/deletes the qualifying row in between and commits? The second query will have no rows and you will return an empty cursor to the caller.
Also, counting the rows (which the analytic count will need to do) could have a significant impact on performance since all the qualifying rows need to be read before the first row can be returned.
John -
Select from table and Update to a view
Hi,
Can anybody let me if this is possible.
I have a Master(single record)/detail(multi record) form. I would want to query/select the details from the base table but when I update/delete I would want to update/delete the details to a view.
Is this doable?
Thanks
KAvithaHi Kavitha,
Solution 1 :-
Why cann't you trap the ON-TRIGGERS (like ON-INSERT /On-update/ON-DELETE) of that block and put your piece of code to update/delete the view.
SOlution 2 (I didn't try this ,so please try)
I am not sure whether it will help you but can try !!Sorry if not working and let me know if you have a solution
Create a package with Insert /Update/Delete sub procedures which does DML on view (as per ur requirement).
Call this Procedure on DML Target Name of Advanced Database .
Regards -
Deny user from seeing/selecting from tables but allow access to certain view
Need some assistance. I have a database on SQL Server 2008 R2. Using windows authentication and a custom group, I control who can access the database and serve up the data via a web application.
I now have a requirement to allow users to connect to the data using Power Pivot, but do not want to allow users to see all tables/views, I want explicitly control what they see.
How do I lock everything down so that users can still view the data from a defined view but limit access to the other tables and views ?
In essence, my users should not be able to see/select from any of the tables or views except for a specific view that I want them to have access to.
ThanksIf the View and the Table are in the same database and have the same owner, then a user who has SELECT permission on the View does not require any permissions on the table.
See
Ownership Chains
David
David http://blogs.msdn.com/b/dbrowne/
http://blogs.msdn.com/b/dbrowne/ -
Select from Oracle to MySQL returns only one row
Environment:
The Oracle Developer Days Virtual Box image, so that's 11gR2 EE on OEL
MySQL 5.1.51-community
mysql-connector-odbc-5.1.7-0.i386.rpm
unixODBC 2.3.0
I got the connection working, I can insert, update and delete records in the MySQL DB from Oracle (SQL Plus).
But when I enter select * from "employees"@mysql I only get the first record returned.
If I enter select * from "employees"@mysql order by "id" desc, I only get the last one...
If I enter select count(*) from "employees"@mysql, I get the - correct - result of 3.
So, how do I get the complete set of (all) records from a MySQL table in Oracle? Is there some kind of setting or is this intended behavior and do I have to create a PL/SQL loop and put the results into a collection or something like that?I've create a table like yours:
create table gateway.employees(id int(10) auto_increment,
first_name varchar(30),
last_name varchar(100),
personal_code varchar(20),
birthday date,
salary decimal(10,2),
is_active int(1),
PRIMARY KEY (id));
insert into gateway.employees (first_name,last_name) values ('Name 1', 'Name 1');
insert into gateway.employees (first_name,last_name) values ('Name 2', 'Name 2');
insert into gateway.employees (first_name,last_name) values ('Name 3', 'Name 3');
insert into gateway.employees (first_name,last_name) values ('Name 4', 'Name 4');
insert into gateway.employees (first_name,last_name) values ('Name 5', 'Name 5');
select * from gateway.employees;
and tested it using DataDirect and MySQL ODBC.
The DataDirect shows all 5 lines whereas MySQL 5.1.0.7 ODBC shows only 1 row.
(isql isn't using extended fetching like DG4ODBC does).
Edited by: kgronau on Nov 4, 2010 4:03 PM
Here the result (fetching ID column):
MySQl ODBC;
SQL> select "id" from "employees"@MYSQL_EMGTW_1121_DB;
id
1
DD ODBC V6:
SQL> select "id" from "employees"@DD60_MYSQL_EMGTW_1121_DB;
id
1
2
3
4
5
Edited by: kgronau on Nov 4, 2010 4:33 PM
The 32bit version of MySQL ODBC (5.1.5 - no 5.1.7 release yet installed) works also:
SQL> select "id" from "employees"@MYSQL_32;
id
1
2
3
4
5
=> so it is an ODBC issue -
Select from Query ? / Dynamic view ? Anything else ?
Hello,
This could be a bit challenging. (or maybe not, i hope)
I have to create a report which is based on 3/4 tables with pretty complex SQL.
Step 1. I have to use views (in the database currently) to select data from these tables.
Step 2. Then create the next set of views (in the db) based on the previous views.
Step 3. Then finally join the last set of views in Reports and create the report based on the PARAMETERS entered.
This was fine, until the client changed the criteria. Now the views have to be created but the PARAMETERS affect the FIRST set of views.
That is, the views in the FIRST STEP will have a where condition based on the parameters at RUN TIME.
I was wondering about how to do this ?
1. Can I use dynamic views (in db) passing the where condition parameter to the where clause ? Alternatively use DDL in Reports.
OR
2. Create a query in Reports and create subsequent QUERIES BASED ON THE FIRST QUERY (like MS Access). Can this be done ?
3. Any other way ?
If you need any clarification, I can provide that.
THANKS for taking the time to read it. It would be great if you could give me any ideas.
Pat.hello,
you might look into REF-CURSOR-QUERIES for this particular case. it might help.
regards,
the oracle reports team -
Hi,
I am facing this weird issue. Any help would be appriciated.
I have view with the following definition:
CREATE VIEW [marketing].[OpenedMails]
AS
SELECT
ID_EmailAddress,
ID_Date_Opened,
ID_Contact,
ID_MailSendJobs,
COUNT(ID_OpenedMails) AS OpenCount,
CASE
WHEN ROW_NUMBER() OVER (PARTITION BY CAST(ID_EmailAddress AS VARCHAR(10)) + ' ' + CAST(ID_MailSendJobs AS VARCHAR(10)) ORDER BY ID_Date_Opened) = 1 THEN 1
ELSE 0
END
AS UniqueOpenCount
FROM
dbo.Fact_OpenedMails
where ID_Contact = 382340
GROUP BY ID_EmailAddress, ID_Date_Opened, ID_Contact, ID_MailSendJobs;
order by ID_MailSendJobs
When I run the the select statement in the view definition I get combination of both 1 and 0 for the 'UniqueOpenCount' column.
But when I run the select from the view itself using the following query:
SELECT [ID_EmailAddress]
,[ID_Date_Opened]
,[ID_Contact]
,[ID_MailSendJobs]
,[OpenCount]
,[UniqueOpenCount]
FROM [marketing].[OpenedMails]
I get equal amount of rows but only 0 values for the 'UniqueOpenCount' column which seems to be very weird to me. Why is this happening ? Can anyone help regarding how to solve this ??
Result from the select inside view definition:
Result from the select query directly from the view:
Thanks in advance.
Vivek KamathPlease post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. You failed. Temporal
data should use ISO-8601 formats – you failed again. Code should be in Standard SQL AS much AS possible and not local dialect.
This is minimal polite behavior on SQL forums.
Things like “ID_Date_Opened” are wrong. The affixes “id” and “date” are called attribute properties in ISO-11179 and data modeling. Since a date is a unit of measurement on a temporal scale, it cannot be an identifier by definition. My guess is this would be
“open_date” if it were done right. And the only display format in ANSI/ISO Standard SQL is ISO-8601 (yyyy-mm-dd)
An email address of -1?? Email addresses are VARCHAR(256), not numeric. There is no reason to cast them AS string!
Your vague “mail_send_jobs” is plural, but columns hold scalars and cannot be plural by definition. The partition cause can hold a list of columns:
WHEN ROW_NUMBER()
OVER (PARTITION BY email_address, mail_send_job
ORDER BY open_date)
= 1
THEN 1 ELSE 0 END
This still makes no sense, but the syntax is better. You do not understand how ROW_NUMBER() works.
Would you like to try again with proper Netiquette?
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL -
Hi Guys,
I was just hoping to get your opinion on something.
I have a procedure in Production that is taking longer and longer to finish and sticks on one certain section of code.
The code is an INSERT into the main dimension table.
This same procedure runs fine on TEST and the section of code completes an awful lot quicker.
The traffic on Production is a lot heavier and there have been applications developed by people other than myself which SELECT from this dimension table. I'm assuming, based on the fact the code in Test and Production are identical, that this increased traffic could be eating up the bandwith and slowing the jobs.
So, I was thinking - if I create Views and let the other applications hit the views as opposed to the main table, will this help speed it up. I did this before on a Teradata platform using a 'dirty read' which worked quite well but Oracle doesn't seem to offer this option.
What do you guys think? Could this work or do I need to take a different approach.
Thank You.GerardMcL wrote:
I meant ordinary views.
I was wondering if there was a way of putting some locking code in or asking for a dirty read that would speed up the SELECT from the table?There is no such thing as a dirty read with Oracle -- Teradata, SQL Server, Sybase, IBM, etc., have different locking architectures where reads can block write and writes can block reads, and that is not an issue with Oracle.
If there's a query performance problem, which is what that will be if the SELECTs are slow, then if you could follow the following links, that will help diagnosis immensely:
[How to Post A Tuning Request|http://forums.oracle.com/forums/thread.jspa?threadID=863295&tstart=0]
And:
[When your Query takes too long|http://forums.oracle.com/forums/thread.jspa?messageID=1812597#1812597]
There is such as thing as stale reads, against Materialized Views, which are views that actually materialize and store the results of a query, and which then can subsequently be queried. -
Error while selecting from a view ORA-01031: Insufficient privileges
As DBA I have granted select privileges on a view to a user, but whenever I login as that user and try to select from the view I get the message 'ORA-01031'. When I run the query in the view as the user I do not have problem and can see the results. This view joins tables from more than one schema and does a distinct on the resultset. I am new to Oracle and would appreciate any help I can get.
ThanksBack on this problem when I created another user with select permission on the same view and a default role that has reference on all the objects on the other schemas, I end up with the same error message. Although this time the schema owner of the view has select privileges on all the tables from other schemas referenced in the view.
Thanks -
SELECT * FROM table WHERE id NOT IN? Help with statement.
Hi,
Two tables. Orders (orderID = PK) and Paid Orders (orderID =
FK)
I want to display a recordset of orders from the Orders table
where the
order ID doesn't appear in the Paid Orders table.
I have tried something like this:
SELECT *
FROM dbo.tblOrders
WHERE orderID NOT IN ( SELECT TOP 100 PERCENT
tblPaidOrders.orderID FROM
dbo.tblPaidOrders )
...no joy with that though. Would appreciate some guidance.
Thank you.
Regards
Nath.Hi Nancy,
Before I begin that, can I ask if there is an issue with the
OR?
I need it to be:
(orderID IN (SELECT qryPaidOrders.orderID FROM qryPaidOrders)
ORDER BY
orderdate ASC) AND ((customerid = MMColParam1) OR (vanopID =
MMColParam2))
MMColParam1 is exactly the same as MMColParam but, for some
reason
unbeknowns to me, DW8.0.2 won't allow me to use it twice.
That's neither
here nor there though, as creating a 2nd variable
(MMColParam2) solves that
particular issue.
Do I need additional ( ) anywhere considering it is an OR
though?
Thanks.
nath.
"Nancy *Adobe Community Expert*" <[email protected]>
wrote in message
news:[email protected]...
>I would think so .. now that you have the core statement
working .. try
>adding the other portions. Put the main statement in ( )
and add the
>others. Like this:
>
> SELECT *
> FROM dbo.qryOrders
> WHERE (orderID IN (SELECT qryPaidOrders.orderID FROM
qryPaidOrders)
> ORDER BY orderdate ASC) AND (customerid = MMColParam1)
AND (vanopID =
> MMColParam2)
>
> See what that gives you and fiddle with those till you
get what you want.
>
>
> --
> Nancy Gill
> Adobe Community Expert
> BLOG:
http://www.dmxwishes.com/blog.asp
> Author: Dreamweaver 8 e-book for the DMX Zone
> Co-Author: Dreamweaver MX: Instant Troubleshooter
(August, 2003)
> Technical Editor: DMX 2004: The Complete Reference, DMX
2004: A
> Beginner's
> Guide, Mastering Macromedia Contribute
> Technical Reviewer: Dynamic Dreamweaver MX/DMX: Advanced
PHP Web
> Development
>
>
>
>
> "tradmusic.com" <[email protected]> wrote
in message
> news:[email protected]...
>> Hi,
>>
>> After a bit of twiddling, I changed the statement to
this:
>>
>> SELECT *
>> FROM dbo.qryOrders
>> WHERE orderID IN (SELECT qryPaidOrders.orderID FROM
qryPaidOrders)
>> ORDER BY orderdate ASC
>>
>> ...and it displays only those records who appear in
the Paid Orders
>> table. If I change this to NOT IN, it displays only
the orders in the
>> Orders table.
>>
>> Ideal, but I need to apply the customerID and
vanopID variables....is
>> that possible within this one statement?
>>
>> Really appreciate the help,
>> Regards
>> Nath.
>>
>> "Nancy *Adobe Community Expert*"
<[email protected]> wrote in message
>> news:[email protected]...
>>> You've added to it since the first post. Take
out the customerID and
>>> vanopID parts and try focusing on just the
orderID part. Get that
>>> working first.
>>>
>>> I would try seeing if you can select those
orderID's that are IN the
>>> subquery first .. that would see whether or not
the problem is the NOT
>>> .. which should work .. but let's see first
whether the culprit is the
>>> query structure or not. See if you can select
the orderID's that are in
>>> the paid orders table from the main query.
>>>
>>>
>>> --
>>> Nancy Gill
>>> Adobe Community Expert
>>> BLOG:
http://www.dmxwishes.com/blog.asp
>>> Author: Dreamweaver 8 e-book for the DMX Zone
>>> Co-Author: Dreamweaver MX: Instant
Troubleshooter (August, 2003)
>>> Technical Editor: DMX 2004: The Complete
Reference, DMX 2004: A
>>> Beginner's
>>> Guide, Mastering Macromedia Contribute
>>> Technical Reviewer: Dynamic Dreamweaver MX/DMX:
Advanced PHP Web
>>> Development
>>>
>>>
>>> "tradmusic.com"
<[email protected]> wrote in message
>>> news:[email protected]...
>>>> Hi Nancy,
>>>>
>>>> Have just tried that, but it is still
displaying records whose orderID
>>>> is also in a record in the Paid Orders
table?
>>>>
>>>> I've got:
>>>>
>>>> SELECT *
>>>> FROM dbo.qryOrders
>>>> WHERE customerID = MMColParam OR vanopID =
MMColParam1 AND orderID NOT
>>>> IN (SELECT qryPaidOrders.orderID FROM
qryPaidOrders)
>>>> ORDER BY orderdate ASC
>>>>
>>>> Hope you can help.
>>>> Thanks. :o)
>>>> Nath.
>>>>
>>>>
>>>> "Nancy *Adobe Community Expert*"
<[email protected]> wrote in message
>>>> news:[email protected]...
>>>>> Why couldn't your inner query just be
SELECT orderID from
>>>>> dbo.tblPaidOrders? Wouldn't the top 100%
be all of them?
>>>>>
>>>>>
>>>>> --
>>>>> Nancy Gill
>>>>> Adobe Community Expert
>>>>> BLOG:
http://www.dmxwishes.com/blog.asp
>>>>> Author: Dreamweaver 8 e-book for the DMX
Zone
>>>>> Co-Author: Dreamweaver MX: Instant
Troubleshooter (August, 2003)
>>>>> Technical Editor: DMX 2004: The Complete
Reference, DMX 2004: A
>>>>> Beginner's
>>>>> Guide, Mastering Macromedia Contribute
>>>>> Technical Reviewer: Dynamic Dreamweaver
MX/DMX: Advanced PHP Web
>>>>> Development
>>>>>
>>>>>
>>>>> "tradmusic.com"
<[email protected]> wrote in message
>>>>>
news:[email protected]...
>>>>>> Hi,
>>>>>>
>>>>>> Two tables. Orders (orderID = PK)
and Paid Orders (orderID = FK)
>>>>>> I want to display a recordset of
orders from the Orders table where
>>>>>> the order ID doesn't appear in the
Paid Orders table.
>>>>>>
>>>>>> I have tried something like this:
>>>>>>
>>>>>> SELECT *
>>>>>> FROM dbo.tblOrders
>>>>>> WHERE orderID NOT IN ( SELECT TOP
100 PERCENT tblPaidOrders.orderID
>>>>>> FROM dbo.tblPaidOrders )
>>>>>>
>>>>>> ...no joy with that though. Would
appreciate some guidance. Thank
>>>>>> you.
>>>>>>
>>>>>> Regards
>>>>>> Nath.
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
> -
Need SQL query using View - Please help
Hi,
I have similar requirement like below.
I have two tables DEPT and EMP and some departments may not have employees. I have created below view, which displays all DEPT records, even though there are no emplyees.
CREATE OR REPLACE VIEW dept_emp_vw AS
SELECT deptno, empid, 0 AS selected
FROM dept d, emp e
WHERE d.deptno = e.deptnno (+);
Ex.
DEPTNO EMPID SELECTED
10 101 0
10 102 0
20 103 0
30 103 0
40 104 0
50 <null> 0
Application will pass "empid" to the view (for ex. empid = 103) and I want result like below.
Ex.
DEPTNO EMPID SELECTED
10 101 0
10 102 0
20 103 1
30 103 1
40 104 0
50 <null> 0
Can you please let me know the query using "dept_emp_vw" view. We have Oracle 11g Release 2.
Thanks a lot for the help.Not possible using normal SQL - as SQL is not a procedure language and does not support variable declaration and use (e.g. passing empid as a variable and using it both as a predicate and as a condition in the SQL projection).
That said - SQL can be "+parameterised+". An approach that is ugly and contrary to the basic design and use of SQL. But it can support the (very weird) view definition of yours.
E.g.
SQL> create or replace procedure SetVariable( name varchar2, value varchar2 ) is
2 begin
3 DBMS_SESSION.set_context( 'MyVariables', name, value );
4 end;
5 /
Procedure created.
SQL>
SQL>
SQL> create or replace context MyVariables using SetVariable;
Context created.
SQL>
SQL> create or replace view my_funky_weird_view as
2 select
3 e.empno,
4 e.ename,
5 e.job,
6 case e.empno
7 when to_number(sys_context( 'MyVariables', 'empid' )) then
8 0
9 else
10 1
11 end as "SELECTED"
12 from emp e
13 /
View created.
SQL>
SQL> exec SetVariable( 'empid', 7499 )
PL/SQL procedure successfully completed.
SQL>
SQL> select * from session_context where namespace = 'MYVARIABLES';
NAMESPACE ATTRIBUTE VALUE
MYVARIABLES EMPID 7499
SQL>
SQL> select * from my_funky_weird_view order by selected;
EMPNO ENAME JOB SELECTED
7499 ALLEN SALESMAN 0
7521 WARD SALESMAN 1
7566 JONES MANAGER 1
7654 MARTIN SALESMAN 1
7698 BLAKE MANAGER 1
7934 MILLER CLERK 1
7788 SCOTT ANALYST 1
7839 KING PRESIDENT 1
7844 TURNER SALESMAN 1
7876 ADAMS CLERK 1
7900 JAMES CLERK 1
7902 FORD ANALYST 1
7369 SMITH CLERK 1
7782 CLARK MANAGER 1
14 rows selected.
SQL>But I will N\OT recommend doing it this way. It is not natural SQL as PL/SQL is needed to "+inject+" name-value pairs into the context for the SQL view to use. It is ugly. It is not standard. It cannot scale. It is complex to use. Etc.
Yes, there are instances when this approach is exactly what one needs - when for example dealing with a trusted context and using the contents for implementing a security layer. But in the above case - I would rather want to see the actual business requirement first, as I think you're barking up the wrong tree with the view solution you have imagined. -
Can select from table across db link but cannot create a materialized view
dblink1 is a private db link (it could also be public)
select count(*) from t1@dblink1;
-->
COUNT(*)
5276
create materialized view v1 as
select * from t1@dblink1;
-->
select * from t1@dblink1;
ERROR at line 2:
ORA-00942: table or view does not exist
This only applies to this particular db link. For another db link called "dblink2",
create materialized view v2 as
select * from t2@dblink2;
-->
Materialized view created.
What gives? dblink1 and dblink2 are 2 different databases on 2 different machines.This is the simplest cause:
dblink2 points to a database that has not a t1 table (as the message says, the table does not exist)
This is the following simple cause:
dblink2 uses a remote user user2, that can not select the t1 table because it exist in another schema, and user2 has not a synonym to the table (post the result of a query over dba_db_links that shows the remote users). Database objects has name and schema. If the objects are in your own schema you dont need to write the schema name, nor if you has a synonym to the object. But if the table t1 is in another schema, and you write t1, it means user2.t1 and fail.
I hope this helps
Regards,
Alfonso -
Is select from view faster then select from table..???
Hello Gurus,
I want to query some data from two tables, both of table have many columns (attributes) and many rows...
I use several where clauses to retrieve data from those tables..
witch one is faster, I create a view or I just "select" from those tables???
Regards.
Nia...riedelme wrote:
3360 wrote:
riedelme wrote:
Selecting through a view almost never helps performance and frequently hurts.Views do not affect performance.
Views are simply queries and like queries there are fast and slow ones.I disagree.
First of all, to use a view you are executing a query to get a result set, then accessing the data from that result set - a built-in extra step to perform to get data.First of all that entire explanation of how views work is not correct. The optimizer will rewrite the query to make the view go away if possible.
SQL> create or replace view v as select * from dual;
View created.
SQL> explain plan for select * from dual where dummy = 'X';
Explained.
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
Plan hash value: 272002086
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 2 | 2 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| DUAL | 1 | 2 | 2 (0)| 00:00:01 |
Predicate Information (identified by operation id):
1 - filter("DUMMY"='X')
13 rows selected.
SQL> explain plan for select * from v where dummy = 'X';
Explained.
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
Plan hash value: 272002086
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 2 | 2 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| DUAL | 1 | 2 | 2 (0)| 00:00:01 |
Predicate Information (identified by operation id):
1 - filter("DUMMY"='X')
13 rows selected.Exactly the same.
>
Second, when accessing the data from the view the result sets don't have indexes for fast lookups and efficient joins on later steps.This is also known as just making stuff up and is not how the database works. care to share any references at all for any of this?
>
Third, the systems I've seen that use views extensively - I am looking at one now - tend to perform joins on views using the same tables with the same data over and over. This is a design issue and not specifically a problem with views but they lend themselves to this misuse much too easilyCorrect as I said a view is just a query, and just like queries there are good fast views and bad slow views
>
I'll concede that the problem is not specifically with views themselves but as I just said they lend themselves to misuse. Tuning views of views and views joined to views is difficultYes, queries can be misused as can almost all SQL functions and functionality.
As I said - Views are simply queries and like queries there are fast and slow ones.
Nothing that you have posted that is accurate changes that. -
Performance problem with select from _DIFF view
Hi,
we have a versioned table with more then one million records. We use the DBMS_WM.SetDiffVersions procedure and select from DIFF view to get data differences between two workspaces. The problem is that the select from the DIFF view is very slow. I takes more than 15 minutes. Has anybody an idea why it consumes so much time? Is there any way how to improve it?
Thanks and regards
OndrejHi,
This can be due to any number of things, but is typically caused by an inefficient optimizer plan. Make sure that statistics on the _LT table have been recently analyzed.
Also the following information would be useful:
1. What is the relationship of the workspaces that you are trying to compare (parent/child, children of the same parent, etc) ?
2. How many and of what type dml are being performed in the workspaces ?
3. What version of Workspace Manager are you using and what is the version of the database ?
4. What is the time needed to select from the _DIFF view based on the primary key ?
Regards,
Ben
Maybe you are looking for
-
Help me to resovle this problem
Dear friend: Could you help me to this problem.I want to create a class.It can scan the specific directory to get the list of files in it.
-
Hello, I need some help, please! I have to do this kind of revaluation: E.g.: aquisition value = 50000; useful life = 10 years depreciation per year = 5000 After 2 years: the revaluated value = 64000; the accumulated depre
-
Aduit Log Report: Exempt from policy
Hi! I need to know if there is a standard report available of documents which are exempt from a policy (beforhand declared)? We have a Record Center solution available, content types with information mgt policies and in place record mgt active. Are t
-
How to save files on the server?
I want to save a log on the server, how can I do this using Oracle? In SQL Server I used the "bcp" command. Thanks.
-
How to identify the right extractor
hi all, i have a custom extractor(ABAP report) to pull the Std cost info into BW from R/3. I would like to remove this custom extractor and go for a generic one. Can anyone provide me the steps on how to identify the appropriate generic extractor. i