Does using "fetch first N rows only" make /*+ FIRST_ROWS([N]) */ hint redundant?
I know the FIRST_ROWS hint tells the optimizer to minimize time to first row. I know the new 12c functionality for "FETCH [FIRST|NEXT] [N] ROWS [ONLY|WITH TIES]"fetch first/next N rows only/with ties" will implement the query using ROW_NUMBER(). Should I leave hint in case it improves performance, or does the FETCH FIRST clause make this hint redundant?
maybe the answer to this question is more complicated then I assumed at first: as Randolf Geist wrote in his presentation Everything You Wanted To Know About FIRST_ROWS_n But Were Afraid To Ask a rownum predicate implicitly defines a first rows n optimization. So I guessed that the fetch first clause would trigger a similar optimization. But a rownum predicate and a fetch first clause are not transformed into the same operation:
create table t
as
select rownum id
from dual
connect by level <= 1000000;
select id
from t
where rownum <= 5;
ID
1
2
3
4
5
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 5 | 25 | 2 (0)| 00:00:01 |
|* 1 | COUNT STOPKEY | | | | | |
| 2 | TABLE ACCESS FULL| T | 5 | 25 | 2 (0)| 00:00:01 |
Predicate Information (identified by operation id):
1 - filter(ROWNUM<=5)
select id
from t
fetch first 5 rows only;
ID
1
2
3
4
5
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1000K| 24M| 427 (1)| 00:00:01 |
|* 1 | VIEW | | 1000K| 24M| 427 (1)| 00:00:01 |
|* 2 | WINDOW NOSORT STOPKEY| | 1000K| 4882K| 427 (1)| 00:00:01 |
| 3 | TABLE ACCESS FULL | T | 1000K| 4882K| 427 (1)| 00:00:01 |
Predicate Information (identified by operation id):
1 - filter("from$_subquery$_002"."rowlimit_$$_rownumber"<=5)
2 - filter(ROW_NUMBER() OVER ( ORDER BY NULL )<=5)
Looking at a CBO trace for the two operations I see signs of a first rows optimization only for the query with the rownum predicate:
Final query after transformations:******* UNPARSED QUERY IS *******
SELECT "T"."ID" "ID" FROM "C##TEST"."T" "T" WHERE ROWNUM<=5
First K Rows: Setup begin
And so I think there is no first rows optimization for the fetch first clause. Of course the analytics would make an optimization for fast response almost impossible if there is an order in the query since in this case the analytics have to read the complete set before the filtering takes place.
Regards
Martin Preiss
Similar Messages
-
Want to fetch first two row from database
i'm having a database with multiple rows. I want to fetch first two rows form it dynamically, what should i have to do???.plz help....
the data comes from external source and updating the database, at the same time i've to read only first two rows, plz explain.
-
Does use of pipelined/pipe row have a limitation on amount of data returned
We are using Oracle 9i.
We have an existing function that pipes data. Select * from table(cast(schema.my_pkg.get_data() as schema.t_my_data_tab))
Function runs, but only returns around 10,000 records. There are actually about 50,000 records to be returned. I do not believe it is just erroring out one a single and stopping because I sorted my cursor multiple ways to show that in one sort certain records do not show, but when sorted another way they do. It is still possible something is stopping it - I will continue looking. But I would like to know if anyone is aware of any size limitations in the amount of data to be piped? I've looked at the types created & the function and do not see anything that was set for a size. Any ideas?
I apologize I do not know all the correct terms to use. I am taking this over from someone else - hopefully an example of their code will help. Thank you very much.
FUNCTION get_data(p_id NUMBER DEFAULT NULL)
RETURN t_my_data_tab PIPELINED
AS
v_temp VARCHAR2(10);
BEGIN
PIPE ROW
(t_links_contracts_rec
(...data values....)
RETURN;
END;I'm not sure really, if there was a limitation I believe it would be documented and even would raise an exception. I've only used pipelined table function for smallish sets of data. I can't simulate much as I only have access to 10g and 11g here, so I ran a query with 50,000, but I'm only posting its count for obvious reasons.
Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.4.0
Connected as fsitja
SQL> create or replace type t_tab is table of number;
2 /
Type created
SQL>
SQL> create or replace function test_pipe return t_tab pipelined as
2 begin
3 for i in 1 .. 50000
4 loop
5 pipe row (i);
6 end loop;
7 end;
8 /
Function created
SQL> select count(*) from table(test_pipe);
COUNT(*)
50000
SQL> Some docs referencing the subject from 9i:
http://download.oracle.com/docs/cd/B10501_01/appdev.920/a96624/08_subs.htm
http://download.oracle.com/docs/cd/B10501_01/appdev.920/a96595/dci12tbl.htm -
How to update the restricted rows that were selcted using fetch
Hi
I have to fetch one row at a time from my staging table using JDBC Sender Adapter, which is configured against AS400 DB2 and push it to R/3.
The select SQL looks like this in JDBC Sender Adapter
<b>select jedata, oxruns from fxjrnep2 where oxsts=' ' fetch first 1 rows only</b>
and
update sql is
<b>update suplib.FXJRNEP2 set OXSTS='SUC' where OXSTS=' ' </b>
The problem here is my select gets one row, which is what i want, but my update actually updates all the rows that satisfied the where condition oxsts=' ' instead of one.
I couldn't use <b>fetch first 1 rows only</b> at the end of the update sql to update the selected row. DB2 does not allow fetch in update sql.
Can anyone suggest solution here or recommend alternative?
Best Regards
Venkatcheck for update query where u can club the select stmt u had used with udpate like:
update suplib.FXJRNEP2 set OXSTS='SUC' where OXSTS = (select jedata, oxruns from fxjrnep2 where oxsts=' ' fetch first 1 rows only
just need to try combinations of this type.
if still this is not working use a bpm and get all the records where OXSTS is null and process record one by one within a block -
Hi all,
I am using Oracle 9.
I am converting my database from DB2 to Oracle.
I had one Query with Fetch First like this:
SELECT EMPNO, LASTNAME, FIRSTNME, SALARY
FROM DSN8710.EMP
ORDER BY SALARY DESC
FETCH FIRST 4 ROWS ONLY;
That FETCH FIRST giving error in Oracle, Can any one tell me the remedy for this.
Thanksi dont think fetch first is there in oracle
if u want determine topd 4 highest salary here is one such example
which gives top 3 highest salary as per deptno
SQL> select ename
2 , deptno
3 , sal
4 , rn
5 from (select ename
6 , deptno
7 , sal
8 , Row_Number() over (partition by deptno
9 order by sal desc
10 ) rn
11 from emp
12 )
13 where rn <= 3
14 /
ENAME DEPTNO SAL RN
KING 10 5000 1
CLARK 10 2450 2
MILLER 10 1300 3
SCOTT 20 3000 1
FORD 20 3000 2
JONES 20 2975 3
BLAKE 30 2850 1
ALLEN 30 1600 2
TURNER 30 1500 3 -
Delete first empty row in a table
Hi,
Can you please provide the script for the below requirement.
Need to delete First empty row in all the tables. (Tables having more number of empty rows. i need to delete first empty row only)
Regards,
Velu@Velu – the following blog post by Jongware might get you started:
Tackling Tables through Scripting
by: Jongware | April 8, 2013
http://indesignsecrets.com/tackling-tables-through-scripting.php
Document Object (DOM) documentation:
Indesign JavaScript Help
InDesign ExtendScript API (10.0)
Table Row specifics:
Adobe InDesign CS6 (8.0) Object Model JS: Row
InDesign ExtendScript API (10.0)
Uwe -
When using private browsing to view image results in Safari 5.1.3, only the first two rows of results are visible, the following four or so rows display greyed out place holders, the remainder of the results page is blank, and the safe search button is inoperable. When I turn off private browsing and refresh the page, everything works again.
Anyone else having this problem?I have got the same behaviour after the last Safari Update to 5.1.3. It seems that Safari now handles some scripts in a new way. If you debug the Google Website, you will see, that there is some Javascript Error, that seems to prevent to write into local cache. After some searching I wasn't able to finde a solution for this problem, other then disabling Javascript while private browsing to prevent the script loading. You then are able to use Google with the old layout. The option to disable JavaScript can be found in the Menu "Developer", wich has to be enabled in Safari in the options first.
In my opinion this is a bug that is now occuring, because Apple changed something in private browsing and that has to be fixed by Google now, to run again. Or we will have to wait for 5.1.4, as you can read online Apple will change and bugfix the javascript engine in that version, perhaps this fixes the problem as well. I hope so!
If anyone is in the developer program perhaps you could test this with the beta of 5.1.4 and tell us if it works. -
Number of total rows returned by a ref cursor without using FETCH
Hi. How can we get the total number of rows returned by a ref cursor without doing the FETCH? I mean, if you use %ROWCOUNT, it only returns the current row number being returned in every fetch. This is not what I want. My purpose is to determine if my query using ref cursor returns greater than zero total rows without using fetch. Thanks.
As John pointed out in the thread you linked to, the only way to know how many rows a query will return is to actually fetch all the rows. Oracle doesn't know how many rows a query is going to return until it actually fetches the last row.
Plus, assuming the default transaction isolation level, if you run the same query multiple times in succession, there is no guarantee that the results will be the same.
If you just want to know whether a query will return a nonzero number of rows, why not just write the code to assume that it returns at least 1 row and handle the zero row result as an exception.
Justin -
Why does last fetch take so much longer than first three?
I have this trace file:
EXEC #3:c=0,e=4803,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=1,plh=2726503091,tim=2779072194357
WAIT #3: nam='SQL*Net message to client' ela= 1 driver id=1650815232 #bytes=1 p3=0 obj#=-1 tim=2845769927079
FETCH #3:c=0,e=2969,p=0,cr=56,cu=0,mis=0,r=1,dep=0,og=1,plh=2726503091,tim=2779072197438
WAIT #3: nam='SQL*Net message from client' ela= 1006 driver id=1650815232 #bytes=1 p3=0 obj#=-1 tim=2845769931224
WAIT #3: nam='SQL*Net message to client' ela= 1 driver id=1650815232 #bytes=1 p3=0 obj#=-1 tim=2845769931269
FETCH #3:c=0,e=322,p=0,cr=2,cu=0,mis=0,r=15,dep=0,og=1,plh=2726503091,tim=2779072198806
WAIT #3: nam='SQL*Net message from client' ela= 3733 driver id=1650815232 #bytes=1 p3=0 obj#=-1 tim=2845769935348
WAIT #3: nam='SQL*Net message to client' ela= 0 driver id=1650815232 #bytes=1 p3=0 obj#=-1 tim=2845769935423
FETCH #3:c=0,e=178,p=0,cr=2,cu=0,mis=0,r=15,dep=0,og=1,plh=2726503091,tim=2779072202692
WAIT #3: nam='SQL*Net message from client' ela= 3136 driver id=1650815232 #bytes=1 p3=0 obj#=-1 tim=2845769938725
WAIT #3: nam='SQL*Net message to client' ela= 1 driver id=1650815232 #bytes=1 p3=0 obj#=-1 tim=2845769938763
FETCH #3:c=410000,e=403256,p=0,cr=7354,cu=0,mis=0,r=13,dep=0,og=1,plh=2726503091,tim=2779072609065
STAT #3 id=1 cnt=44 pid=0 pos=1 obj=0 op='PARTITION RANGE SINGLE PARTITION: KEY KEY (cr=7414 pr=0 pw=0 time=0 us cost=7 size=9823 card=47)'
STAT #3 id=2 cnt=44 pid=1 pos=1 obj=0 op='PARTITION RANGE SINGLE PARTITION: (cr=7414 pr=0 pw=0 time=0 us cost=7 size=9823 card=47)'
STAT #3 id=3 cnt=44 pid=2 pos=1 obj=590979 op='TABLE ACCESS BY LOCAL INDEX ROWID BA_PGM_SLS_DTL PARTITION: KEY KEY (cr=7414 pr=0 pw=0 time=0 us cost=7 size=9823 card=47)'
STAT #3 id=4 cnt=44 pid=3 pos=1 obj=590982 op='INDEX RANGE SCAN BA_PGM_SLS_DTL_PK PARTITION: KEY KEY (cr=7408 pr=0 pw=0 time=10 us cost=6 size=0 card=1)'
WAIT #3: nam='SQL*Net message from client' ela= 3104 driver id=1650815232 #bytes=1 p3=0 obj#=-1 tim=2845770355048It looks to me like the first three fetches return 31 rows in very little time, but the last fetch takes about .4 seconds and does about 7354 buffer gets to get the remaining 13 rows. Does anyone have an idea what might cause this?
- BobbyI goofed. The types of two of the bind variables got reversed:
Wrong type
VARIABLE V_PRIM_CUST_CNTL_LOCN VARCHAR2(10)
VARIABLE V_PRIM_CUST_NBR NUMBER
Right type
VARIABLE V_PRIM_CUST_CNTL_LOCN NUMBER
VARIABLE V_PRIM_CUST_NBR VARCHAR2(10)
Once I fixed this the query reads hardly any blocks at all just as I would expect. I guess the first three fetches got lucky and hit some blocks with matching data. The last fetch must have read through a bunch of index blocks needlessly because it wasn't using all the values in the where clause.
Here are the predicates with the right plan and wrong:
good
4 - access("BPSD"."PGM_MSTR_NBR"=:V_PGM_MSTR_NBR AND "BPSD"."PGM_SEQ"=:V_PGM_SEQ AND
"BPSD"."PMT_STS"=:V_PMT_STS AND "BPSD"."PRIM_CUST_CNTL_LOCN"=:V_PRIM_CUST_CNTL_LOCN AND
"BPSD"."PRIM_CUST_NBR"=:V_PRIM_CUST_NBR AND "BPSD"."DIV_NBR"=:V_DIV_NBR AND
"BPSD"."CUST_CNTL_LOCN"=:V_CUST_CNTL_LOCN AND "BPSD"."CUST_NBR"=:V_CUST_NBR AND
"BPSD"."PRCS_DT"=TO_DATE(:V_PRCS_DT,'DD-MON-YYYY') AND "BPSD"."CR_MEMO_NBR"=:V_CR_MEMO_NBR AND
"BPSD"."INV_NBR"=:V_INV_NBR)
bad
4 - access("BPSD"."PGM_MSTR_NBR"=:V_PGM_MSTR_NBR AND "BPSD"."PGM_SEQ"=:V_PGM_SEQ AND
"BPSD"."PMT_STS"=:V_PMT_STS AND "BPSD"."PRIM_CUST_CNTL_LOCN"=TO_NUMBER(:V_PRIM_CUST_CNTL_LOCN) AND
"BPSD"."DIV_NBR"=:V_DIV_NBR AND "BPSD"."CUST_CNTL_LOCN"=:V_CUST_CNTL_LOCN AND "BPSD"."CUST_NBR"=:V_CUST_NBR AND
"BPSD"."PRCS_DT"=TO_DATE(:V_PRCS_DT,'DD-MON-YYYY') AND "BPSD"."CR_MEMO_NBR"=:V_CR_MEMO_NBR AND
"BPSD"."INV_NBR"=:V_INV_NBR)
filter(("BPSD"."INV_NBR"=:V_INV_NBR AND "BPSD"."CUST_NBR"=:V_CUST_NBR AND
TO_NUMBER("BPSD"."PRIM_CUST_NBR")=:V_PRIM_CUST_NBR AND "BPSD"."DIV_NBR"=:V_DIV_NBR AND
"BPSD"."CR_MEMO_NBR"=:V_CR_MEMO_NBR AND "BPSD"."PRCS_DT"=TO_DATE(:V_PRCS_DT,'DD-MON-YYYY') AND
"BPSD"."CUST_CNTL_LOCN"=:V_CUST_CNTL_LOCN))Having reviewed this I believe this is what Jonathan Lewis meant by a hidden coercion of the data type of one of the columns. The column PRIM_CUST_NBR had to be converted to a number to compare it with the mistyped bind variable and so none of the columns after that one in the index could be used in the range scan.
- Bobby
Edited by: Bobby Durrett on Jul 9, 2012 3:17 PM
Edited by: Bobby Durrett on Jul 10, 2012 8:23 PM -
Af:commandButton only works for the first 10 rows returned in the af:table
Using JDeveloper 10.1.3.2.0.
I am new to ADF programming. I have attempted to create an ADF page that contains a search and return table in the same page. The search appears to work fine but the return table displays odd behavior. If the search returns more than 10 rows such that it is possible to page forward through the rows returned the command button associated with the return table that allows the user to pick a particular row and navigate to another page does not work. If the user finds what he/she is looking for in the first ten rows then the command button works fine and the user is taken to the next page. The command button is actually defined to have an af:setActionListener to set a value in a backing bean and then command button has an action to invoke a backing bean. Both of these fire just fine if the selection is made from the first 10 rows. However once the user pages forward to another set of rows then neither seem to happen. Any advice on where to figure out what I did wrong?When I get a component that seems to do nothing under certain circumstances, the first thing I usually check for is Javascript errors. Sometimes errors on page load can keep a component's Javascript from firing properly.
Try reproducing your problem in Firefox (or another browser with a decent Javascript error console; IE doesn't have one, although I think you can get extensions that provide JS debugging). Check the error console:
# Before scrolling off the first 10 rows.
# Right after scrolling off the first 10 rows.
# After unsuccessfully clicking the command button.
Do any interesting errors show up in steps 2 or 3? -
Change background and font for first row only?
Hi,
Have a tablix in SSRS (2008R2) and would like to change the background colour and font for the first row only, is this possible and if so how would I achieve this?
I have followed and example on setting alternate row background colour in the properties but can't see how to do this for just the first row.
=IIF(RowNumber(Nothing) MOD 2,”LightGrey”, “LightBlue”)
ThanksHello,
The Expression uses a Modulo function to calculate every second row. In your case just compare with equal 1 for the first row:
=IIF(RowNumber(Nothing) = 1, ”LightGrey”, “LightBlue”)
Olaf Helper
[ Blog] [ Xing] [ MVP] -
Show Only First N Rows in SAP Design Studio Chart/Table
Hi,
Is it possible to show only first N rows of data in SAP Design Studio Charts/Cross Tab ?
Eg
Bex Query Output
Here If I mention First 2 rows, my chart looks like below
If I mention First 4 rows, my chart looks like below
Thanks
AnilHi Mustafa,
Thanks for your reply.
Actually our requirement is, we have one Bex Query where we are using Ranking Function.
We have 15 customers, and we need to know the ranking based on some calculations.
Whenever we execute the query with different time periods, the ranking of Customers will vary, for example if I execute query for year 2014, customer 1 can be Rank 1, If I execute for year 2013, Customer 7 can be Rank 1.
From this Query I need to show only Top 5 Customers in Cross Tab/Chart.
We tried to put condition on CY Ranking in Bex to show only Top 5, but the result was giving some diff customers and also for all Time periods we are getting same Customers In Top 5.
To overcome this, we thought instead of putting condition on Bex side, we are trying to pick only first 5 rows from Bex Query and show them in Chart/Cross Tab, something like we will map only first 5 rows in Xcelcius.
We would like to know is there any functionality in Design Studio to show only first 5 rows of data.
Regards,
Anil -
Does anyone know the best software to make a scalene triangle using 3 predefined values?
Does anyone know the best software to make a scalene triangle using 3 predefined values?
kitweb,
It is not too difficult in Illustrator.
Presuming the values are the side lengths, you may turn on the Smart Guides and:
1) Create a circle with its centre at X=Y=0 and with its radius equalling the first side length;
2) Create another circle with its centre at X equalling the second side length and Y = 0, and with its radius equalling the third side length;
3) With the Pen Tool click at the centres of the circles (Smart Guides say centre), then at one of the intersections of the circles (Smart Guides say intersect), then back at the first centre;
4) Delete the circles, and if needed Object>Transform>Rotate/Reflect/Move/whatever for the right orientation/position.
Obviously, you may use any order of the predefined sidelengths from the beginning. -
I have to change my apple ID because I'm changing my email address. (I have a Comcast address and am switching to U-verse) I'm worried that when I do, I'll no longer be able to use my first generation apple tv unless I change the apple ID there as well. I'm also trying to find out if changing my apple ID is going to interfere with getting my itunes content on my computer and my iphone. Does anyone know how this works??
My iTunes appleID is an old defunct e-mail address - it does not have to be functional.
Do what Winston says to ensure you keep getting correspondence related to that ID.
AC -
I have one iPhone 8GB. After making un upgrade of iTunes and software of iPhone, it's impossible to use it. There's no service! doesn't acept PIN code! it only makes emergency calls and the image in the iPhone is the sign to connect to iTunes. What can i do to solve it?
Where are you and where did you get the phone. This sounds like a classic symptom of someone who bought an iPhone that originated in the U.S. which was then hacked so it would run on a carrier network other than AT&T... Then, when updating the phone, it becare re-locked to AT&T.
If that's what happened, you now own a paperweight. AT&T will NOT unlock them for any reason.
If this isn't the case, please clarify where you are, what carrier you have and where you got the phone so we can begin troubleshooting.
Maybe you are looking for
-
Old MacBook showed up on iMessage
I recently have changed my Apple ID password so I was logging in on my current devices (Mac Pro, iPhone, and iPad). I recently sold an old mid 2010 white MacBook to a store. Before doing so, I was sure to boot from the Snow Leopard CD, use the Disk U
-
Ok heres the issue. I have a Power Mac G5 with graphics card that has one DVI port and one ADC port. I am trying to hook up dual monitors. Now after the apple store told me to buy a 30 dollar adaptor that converts a ADC to DVI-D, i then realized i ne
-
MBAM 2.5 ADMX files with MBAM 2.0
I am standing up a new MBAM 2.5 environment to integrate with ConfigMgr 2012 R2. We currently have MBAM 2.0 integrated with ConfigMgr 2007. I want to know if I will run into any problems if I copy the new ADMX files to the sysvol share? Will our
-
When will GigaPower be available in Tomball, TX?
Any idea when the GigaPower fiber optic service will be available in Tomball, TX (suburb NW of Houston)?
-
Were do i go on pc to find username and pass for network server?
i'm trying to network my pc and mac. i'm able to login on pc to access mac files but i dont know were to find username and pass of my pc so as to login from mac into my pc. i know the pass and user on the mac is under system preferences (user&group)