Use of Indexes in select query
Hello,
This is on a 9i install.
There is an index called form_id_idx on the form_id column.
Why does this query use the index (autotrace indicates range scan on the index):
select count(*) from table_name where form_id=123456;
but this query does NOT use the index (autotrace indicates full table scan):
select accepted from table_name where form_id=123456;
This second query runs much faster when I use a hint on the index. Any help/suggestions?
Thanks.
The first query does NOT have to go to the Table it all. It can read the index to count the number of rows for "form_id=123456". An Index Range Scan would be fast.
The second query has to go to the table to get the values for the "accepted" column for all the rows that have "form_id=123456". Remember that every get can require a read of 2 or more blocks -- at least one, probably 2 or 3, from the index and 1 from the table. If the number of rows is likely to be large then the number of block get operations would be high. In such cases, Oracle computes that it is faster to do a small set of multiblock reads to read the whole table (Table FullScan).
Therefore, the optimzer weighs :
a. how many rows it thinks will satisfy "form_id=123456"
b. how many index + table block gets it would have to execute (all as single block read calls to the OS)
versus
x. how many multiblock read calls it thinks it has to execute to read the whole table
If the available statistics on number of rows, cardinality or density and the size of the table indicate that operation "x" would be cheaper then operations "a" + "b", Oracle would prefer the latter.
Hemant K Chitale
http://hemantoracledba.blogspot.com
Similar Messages
-
Check Index used in an oracle select query
Hi Friends,
I have partitioned an oracle table and created Local Index for the Partitioned table .
Now i want to make sure that the Local index is being used when i perform select query on the Table partition.
How do i confirm that ?
can i check the explain plan generted for the select query to confirm local index is being used ?
Please let me know.
Regards,
DBNow i want to make sure that the Local index is being used when i perform select query on the Table partition.Why? Have you proven that using this local index is the "best" plan?
How do i confirm that ?
can i check the explain plan generted for the select query to confirm local index is being used ?When I asked Google "how to read an oracle explain plan," I found lots of information - what did you find? -
Using varchar record in SELECT query
Hi, from a VARCHAR field I get the string ",1,2,3,4,5,6,".
I wish to use it in a SELECT query like:
SELECT * FROM TABLE WHERE ID IN (1,2,3,4,5,6)
Is there a way to obtain this in a tsql query ?
Thank you
StefanoCREATE TABLE t1
col1 INT NOT NULL PRIMARY KEY,
col2 VARCHAR(50) NOT NULL
INSERT INTO t1 VALUES (1,'10,11,12')
INSERT INTO t1 VALUES (2,'13')
INSERT INTO t1 VALUES (3,'14,15')
CREATE TABLE t2
col1 INT NOT NULL PRIMARY KEY,
col2 VARCHAR(50) NOT NULL
INSERT INTO t2 VALUES (10,'A')
INSERT INTO t2 VALUES (11,'B')
INSERT INTO t2 VALUES (12,'C')
INSERT INTO t2 VALUES (13,'D')
INSERT INTO t2 VALUES (14,'E')
INSERT INTO t2 VALUES (15,'F')
SELECT DISTINCT O.col1, O.col2
FROM t1 T
INNER JOIN t2 O
ON (PATINDEX('%,' + CAST(O.col1 AS varchar(10)) + ',%',
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence -
How can i use SUM aggregate in select query?
HI,
GURUS,
How can i use SUM function in Select Query and i want to store that value into itab.
for ex:
TABLES: vbap.
types: begin of ty_vbap,
incluse type vbap,
sum type string,
end of ty_vbap.
data: i_vbap type TABLE OF ty_vbap,
w_vbap type ty_vbap.
SELECT sum(posnr) FROM vbap into table i_vbap up to 5 rows.
(or)
SELECT sum(posnr) FROM vbap into table i_vbap group by vbeln.
loop at i_vbap into w_vbap
" which variable have to use to display summed value.
endloop.
if above code is not understandable pleas give ome sample code on above query.
Thank u,
shabeer ahmed.Hi,
Check this sample code.
TABLES SBOOK.
DATA: COUNT TYPE I, SUM TYPE P DECIMALS 2, AVG TYPE F.
DATA: CONNID LIKE SBOOK-CONNID.
SELECT CONNID COUNT( * ) SUM( LUGGWEIGHT ) AVG( LUGGWEIGHT )
INTO (CONNID, COUNT, SUM, AVG)
FROM SBOOK
WHERE
CARRID = 'LH ' AND
FLDATE = '19950228'
GROUP BY CONNID.
WRITE: / CONNID, COUNT, SUM, AVG.
ENDSELECT.
Regards,
Sravanthi -
How can i use index in select query.. facing problem with the select query.
Hi Friends,
I am facing a serious problem in one of the select query. It is taking a lot of time to fetch data in Production Scenario.
Here is the query:
SELECT * APPENDING CORRESPONDING FIELDS OF TABLE tbl_summary
FROM ztftelat LEFT JOIN ztfzberep
ON ztfzberep~gjahr = st_input-gjahr
AND ztfzberep~poper = st_input-poper
AND ztfzberepcntr = ztftelatrprctr
WHERE rldnr = c_telstra_accounting
AND rrcty = c_actual
AND rvers = c_ver_001
AND rbukrs = st_input-bukrs
AND racct = st_input-saknr
AND ryear = st_input-gjahr
And rzzlstar in r_lstar
AND rpmax = c_max_period.
There are 5 indices present for Table ZTFTELAT.
Indices of ZTFTELAT:
Name Description
0 Primary key( RCLNT,RLDNR,RRCTY,RVERS,RYEAR,ROBJNR,SOBJNR,RTCUR,RUNIT,DRCRK,RPMAX)
005 Profit (RCLNT,RPRCTR)
1 Ledger, company code, account (RLDNR,RBUKRS, RACCT)
2 Ledger, company code, cost center (RLDNR, RBUKRS,RCNTR)
3 Account, cost center (RACCT,RCNTR)
4 RCLNT/RLDNR/RRCTY/RVERS/RYEAR/RZZAUFNR
Z01 Activity Type, Account (RZZLSTAR,RACCT)
Z02 RYEAR-RBUKRS- RZZZBER-RLDNR
Can anyone help me out why it is taking so much time and how we can reduce it ? and also tell me if I want to use index number 1 then how can I use?
Thanks in advance.Hi Shiva,
I am using two more select queries with the same manner ....
here are the other two select query :
***************1************************
SELECT * APPENDING CORRESPONDING FIELDS OF TABLE tbl_summary
FROM ztftelpt LEFT JOIN ztfzberep
ON ztfzberep~gjahr = st_input-gjahr
AND ztfzberep~poper = st_input-poper
AND ztfzberepcntr = ztftelptrprctr
WHERE rldnr = c_telstra_projects
AND rrcty = c_actual
AND rvers = c_ver_001
AND rbukrs = st_input-bukrs
AND racct = st_input-saknr
AND ryear = st_input-gjahr
and rzzlstar in r_lstar
AND rpmax = c_max_period.
and the second one is
*************************2************************
SELECT * APPENDING CORRESPONDING FIELDS OF TABLE tbl_summary
FROM ztftelnt LEFT JOIN ztfzberep
ON ztfzberep~gjahr = st_input-gjahr
AND ztfzberep~poper = st_input-poper
AND ztfzberepcntr = ztftelntrprctr
WHERE rldnr = c_telstra_networks
AND rrcty = c_actual
AND rvers = c_ver_001
AND rbukrs = st_input-bukrs
AND racct = st_input-saknr
AND ryear = st_input-gjahr
and rzzlstar in r_lstar
AND rpmax = c_max_period.
for both the above table program is taking very less time .... although both the table used in above queries have similar amount of data. And i can not remove the APPENDING CORRESPONDING. because i have to append the data after fetching from the tables. if i will not use it will delete all the data fetched earlier.
Thanks on advanced......
Sourabh -
How to mention index in select query?
Hi All,
If I am using fields of two diffrent secondary index in a single select query on a table how I can mention that data should be picked according to first index used in the query?
Regards
DeepakPlease search before asking basic questions.
Thread locked.
Rob -
Using buffering option in select query
Hi All,
Can anybody give me a brief idea on , where we will use the buffering and how we will write it in coding part.Similarly please tell me what will happen if we use by passing buffering addition in select query. Please explain it with steps of sample code if possible.
Thanks in advance.
Regards,
Rakesh.Hi Sharma,
Buffer is used to hold large amount of data.
if internla table is unable to hold data.. Buffer is used..this is mainly used in copy data from PRD to Quality as a part testung.
see the sample code how the buffer is used..
FUNCTION zzrfc_get_zcpeg_fg_related.
*"*"Local Interface:
*" IMPORTING
*" VALUE(PL_VERSION) LIKE ZCPEG_FG_RELATED-PL_VERSION OPTIONAL
*" VALUE(BYPASS_BUFFER) LIKE SY-FTYPE DEFAULT SPACE
*" VALUE(FROM_KEY) LIKE SY-ENTRY DEFAULT SPACE
*" VALUE(GEN_KEY) LIKE SY-ENTRY DEFAULT SPACE
*" VALUE(MAX_ENTRIES) LIKE SY-TABIX DEFAULT 0
*" VALUE(TABLE_NAME) LIKE X030L-TABNAME
*" VALUE(TO_KEY) LIKE SY-ENTRY DEFAULT SPACE
*" EXPORTING
*" VALUE(NUMBER_OF_ENTRIES) LIKE SY-INDEX
*" TABLES
*" ENTRIES STRUCTURE ZCPEG_FG_RELATED
*" EXCEPTIONS
*" INTERNAL_ERROR
*" TABLE_EMPTY
*" TABLE_NOT_FOUND
TABLES dd02l.
DATA: BEGIN OF buf OCCURS 100,
line(4100),
END OF buf.
DATA keyln TYPE i.
DATA: l_tabname LIKE dd25v-viewname.
DATA: l_len TYPE i.
DATA : w_plversion TYPE /sapapo/vrsioex. "PJONNALA
w_plversion = pl_version. "PJONNALA
l_tabname = table_name.
CALL FUNCTION 'VIEW_AUTHORITY_CHECK'
EXPORTING
view_action = 'S'
view_name = l_tabname
no_warning_for_clientindep = 'X'
EXCEPTIONS
OTHERS = 6.
IF sy-subrc <> 0.
RAISE internal_error.
ENDIF.
IF bypass_buffer NE ' ' AND bypass_buffer NE 'N'.
bypass_buffer = 'Y'.
ENDIF.
IF gen_key CA ' '. ENDIF.
keyln = sy-fdpos.
* read client dependant tables always with client
SELECT SINGLE * FROM dd02l WHERE tabname = table_name
AND as4local = 'A'.
IF dd02l-clidep = 'X'.
*l_len = strlen( sy-mandt ) * cl_abap_char_utilities=>charsize.
* " ecwg. unicode
* move gen_key to gen_key+l_len.
* move sy-mandt to gen_key(l_len).
* add l_len to keyln.
CONCATENATE sy-mandt gen_key INTO gen_key.
keyln = STRLEN( gen_key ) * cl_abap_char_utilities=>charsize.
ENDIF.
* endselect.
IF keyln NE 0 OR from_key = space.
CALL 'C_GET_TABLE' ID 'TABLNAME' FIELD table_name
ID 'INTTAB' FIELD buf-*sys*
ID 'GENKEY' FIELD gen_key
ID 'GENKEY_LN' FIELD keyln
ID 'DBCNT' FIELD number_of_entries
ID 'BYPASS' FIELD bypass_buffer.
ELSE.
CALL 'C_GET_TABLE' ID 'TABLNAME' FIELD table_name
ID 'INTTAB' FIELD buf-*sys*
ID 'FROM_KEY' FIELD from_key
ID 'TO_KEY' FIELD to_key
ID 'DBCNT' FIELD number_of_entries
ID 'BYPASS' FIELD bypass_buffer.
ENDIF.
CASE sy-subrc.
WHEN 4. RAISE table_empty.
WHEN 8. RAISE table_not_found.
WHEN 12. RAISE internal_error.
ENDCASE.
DESCRIBE TABLE buf LINES number_of_entries.
ENDFUNCTION.
Regards,
Prabhudas -
Sample XML format that can be used to write a SELECT query
Hello,
I want to use and XML file in the scenario FILE to JDBC where i use the operation as SELECT in which i want to embbed an sql statemnet which is equivalent to
SELECT EMPNO, NAME FROM EMPLOYEE WHERE EMPNO>1
as in the form of XML format like,
<?xml version="1.0" encoding="UTF-8"?>
<ns0:MT_JDBC_SELECT_JDBC_REQ xmlns:ns0="http://JDBC_SELECT">
<STATEMENT>
<TABLENAME ACTION="SELECT">
<TABLE>EMPTEST</TABLE>
<ACCESS>
<EMPNO></EMPNO>
<NAME></NAME>
</ACCESS>
<KEY>
<EMPNO compareOperation="GT">1</EMPNO>
</KEY>
</TABLENAME>
</STATEMENT>
</ns0:MT_JDBC_SELECT_JDBC_REQ>
Can i do like this?
PLease help me out in using various conditions in the XML file formats like the above.
Thanks,
Soorya.Hello raj,
I would like to write the query in that format where i mentioned as,
<?xml version="1.0" encoding="UTF-8"?>
<ns0:MT_JDBC_SELECT_JDBC_REQ xmlns:ns0="http://JDBC_SELECT">
<STATEMENT>
<TABLENAME ACTION="SELECT">
<TABLE>EMPTEST</TABLE>
<ACCESS>
<EMPNO></EMPNO>
<NAME></NAME>
</ACCESS>
<KEY>
<EMPNO compareOperation="GT">1</EMPNO>
</KEY>
</TABLENAME>
</STATEMENT>
</ns0:MT_JDBC_SELECT_JDBC_REQ>
without giving clear SQL statement as you mentioned here like,
<ns0:MT_JDBC_SELECT_JDBC_REQ xmlns:ns0="http://JDBC_SELECT">
<STATEMENT>
<TABLENAME ACTION="SQL_QUERY">
<ACCESS>SELECT EMPNO, NAME FROM EMPLOYEE WHERE EMPNO > '$EMPNO$</ACCESS>
<KEY>
<EMPNO>1</EMPNO>
</KEY>
</TABLENAME>
</STATEMENT>
</ns0:MT_JDBC_SELECT_JDBC_REQ>
Thanks,
Soorya -
How can i use param in my select query ( see code)
Hi ,
I need to use the param instead of hardcoding the value in the select query , when i did that it is working .
I think the limit of args is only till the end of main and my select query is in a method called Load() .
How can i use the param in my select query .
public static void main(String[] args){
name = args[0];
class= args[1];
new Load();
}//end of main
public Load()
try {
Class.forName(JDBC_DRIVER);
connection = DriverManager.getConnection(DATABASE_URL,"username","pw");
statement = connection.createStatement();
//First Query : pin and ticket number
ResultSet resultSet = statement.executeQuery("SELECT pin , ticketnumber from airport ,year where "+ "year.year_name= Here i need to use the param (instead of hardcoding) and year.class_year= Here too i need to use param");
}// end of method Load()Edited by: 1sai on Sep 24, 2008 7:34 AM
Edited by: 1sai on Sep 24, 2008 7:35 AMMight I suggest you change the structure of your program to the following:
public class Load {
private Connection conn;
private PreparedStatement statement;
public Load(String sql) {
init(sql);
protected void init(String sql) throws Exception {
Class.forName(JDBC_DRIVER);
conn = DriverManager.getConnection(DATABASE_URL, "username", "pw");
statement = conn.prepareStatement(sql);
public ResultSet execute(String p1, String p2) throws Exception {
statement.setString(1, p1);
statement.setString(2, p2);
return statement.executeQuery();
public void close() throws Exception {
if (statement != null)
statement.close();
statement = null;
if (conn != null)
conn.close();
conn = null;
public static void main(String[] args) throws Exception {
String sql = args[0];
String param1 = args[1];
String param2 = args[2];
Load load = new Load(sql);
ResultSet rs = load.execute(param1, param2);
while (rs.next())
System.out.println(rs.get(0));
rs.close();
load.close();
}This allows you to use the same "Load" object for multiple queries with different parameters.
I do not recommend you actually use the code above in any sort of production application. You should really take a look at Spring Framework along with an ORM tool like Hibernate or Ibatis to simplify your DAO layer.
Hope this helps,
David -
Trying to do something as data would be uploaded and edited in grid. At present I am using Ora_Hash.
SELECT
e.ROWID, e.Employee_Id,e.First_Name,e.Last_Name,e.Email,e.Phone_Number,e.Hire_Date,
e.Job_Id,e.Salary,e.Manager_Id,e.Department_Id,
owa_opt_lock.checksum('HR','EMPLOYEES', e.rowid) As HashForThisRow
FROM EMPLOYEES e;
ThxNo you can't.
owa_opt_lock.checksum is a function which is used for optimist locking. It locks the row(probably by using Select FOR Update mechanism) which you select and which you are trying to update. As a result, what you are eventually trying to do is that inside a Select query you are using a function that is locking the rows, which is not allowed. And thus your query will fail with the below mentioned error.
ORA-14551: cannot perform a DML operation inside a query
ORA-06512: at "SYS.DBMS_SQL", line 1575
ORA-06512: at "SYS.OWA_OPT_LOCK", line 172
14551. 00000 - "cannot perform a DML operation inside a query "
*Cause: DML operation like insert, update, delete or select-for-update
cannot be performed inside a query or under a PDML slave.
*Action: Ensure that the offending DML operation is not performed or
use an autonomous transaction to perform the DML operation within
the query or PDML slave.
Thanks,
Ishan -
Using DB Links - Improving SELECT query performance
Hi there,
I am using dblink in the following query:
I would like to improve performance of the query by using hints as per described in the link: http://www.experts-exchange.com/Database/Oracle/9.x/Q_23640348.html. However, i am not sure how can i include this in my select query.
Details are:
Oracle - 9i Database Terminal Release .8
DB Link: TCPROD
Could someone please explain with an example how to use hints to get the query to select data on the remote database and then return the results to the target database?
Many Thanks.
SELECT ec.obid AS prObid,
ec.b2ProgramName AS program,
ec.projectName AS project,
ec.wbsID AS prNo,
ec.wbsName AS title,
ec.revision AS revision,
ec.superseded AS revisionSuperseded,
ec.lifeCycleState AS lifeCycleState,
ec.b2ChangeType AS type,
ec.b2Complexity AS subType,
ec.r1SsiCode AS ssi,
ec.b2disposition as disposition,
ec.wbsOriginator AS requestor,
ec.wbsAdministrator AS administrator,
ec.changepriority as priority,
ec.r1tsc as tsc,
ec.t1comments as tenixComments,
ec.b2securityclass as securityClassification,
ec.t1changesafety as safety,
ec.t1actionofficer as actionOfficer,
ec.t1changereason as changeReason,
ec.t1wbsextchangenumber as extChangeNo,
ec.creator as creator,
to_date(substr(ec.creationdate,
0,
instr(ec.creationdate, ':', 1, 3) - 1),
'YYYY/MM/DD-HH24:MI:SS') as creationdate,
to_date(ec.originatorassigndate, 'YYYY/MM/DD') as originatorassigndate,
zbd.description as description,
zbc.comments as comments
FROM (SELECT obid,
b2ProgramName,
projectName,
wbsID,
wbsName,
revision,
superseded,
lifeCycleState,
b2ChangeType,
b2Complexity,
r1SsiCode,
b2disposition,
wbsOriginator,
wbsAdministrator,
changepriority,
r1tsc,
t1comments,
b2securityclass,
t1changesafety,
t1actionofficer,
t1changereason,
t1wbsextchangenumber,
creator,
creationdate,
originatorassigndate
FROM awdbt1m4.cmPrRpIt@TCPROD
UNION
SELECT obid,
b2ProgramName,
projectName,
wbsID,
wbsName,
revision,
superseded,
lifeCycleState,
b2ChangeType,
b2Complexity,
r1SsiCode,
b2disposition,
wbsOriginator,
wbsAdministrator,
changepriority,
r1tsc,
t1comments,
b2securityclass,
t1changesafety,
t1actionofficer,
t1changereason,
t1wbsextchangenumber,
creator,
creationdate,
originatorassigndate
FROM mart1m4.cmPrRpIt@TCPROD
UNION
SELECT obid,
b2ProgramName,
projectName,
wbsID,
wbsName,
revision,
superseded,
lifeCycleState,
b2ChangeType,
b2Complexity,
r1SsiCode,
b2disposition,
wbsOriginator,
wbsAdministrator,
changepriority,
r1tsc,
t1comments,
b2securityclass,
t1changesafety,
t1actionofficer,
t1changereason,
t1wbsextchangenumber,
creator,
creationdate,
originatorassigndate
FROM mpsdt1m4.cmPrRpIt@TCPROD
UNION
SELECT obid,
b2ProgramName,
projectName,
wbsID,
wbsName,
revision,
superseded,
lifeCycleState,
b2ChangeType,
b2Complexity,
r1SsiCode,
b2disposition,
wbsOriginator,
wbsAdministrator,
changepriority,
r1tsc,
t1comments,
b2securityclass,
t1changesafety,
t1actionofficer,
t1changereason,
t1wbsextchangenumber,
creator,
creationdate,
originatorassigndate
FROM nondt1m4.cmPrRpIt@TCPROD
UNION
SELECT obid,
b2ProgramName,
projectName,
wbsID,
wbsName,
revision,
superseded,
lifeCycleState,
b2ChangeType,
b2Complexity,
r1SsiCode,
b2disposition,
wbsOriginator,
wbsAdministrator,
changepriority,
r1tsc,
t1comments,
b2securityclass,
t1changesafety,
t1actionofficer,
t1changereason,
t1wbsextchangenumber,
creator,
creationdate,
originatorassigndate
FROM rnast1m4.cmPrRpIt@TCPROD
UNION
SELECT obid,
b2ProgramName,
projectName,
wbsID,
wbsName,
revision,
superseded,
lifeCycleState,
b2ChangeType,
b2Complexity,
r1SsiCode,
b2disposition,
wbsOriginator,
wbsAdministrator,
changepriority,
r1tsc,
t1comments,
b2securityclass,
t1changesafety,
t1actionofficer,
t1changereason,
t1wbsextchangenumber,
creator,
creationdate,
originatorassigndate
FROM rnlht1m4.cmPrRpIt@TCPROD
UNION
SELECT obid,
b2ProgramName,
projectName,
wbsID,
wbsName,
revision,
superseded,
lifeCycleState,
b2ChangeType,
b2Complexity,
r1SsiCode,
b2disposition,
wbsOriginator,
wbsAdministrator,
changepriority,
r1tsc,
t1comments,
b2securityclass,
t1changesafety,
t1actionofficer,
t1changereason,
t1wbsextchangenumber,
creator,
creationdate,
originatorassigndate
FROM rnolt1m4.cmPrRpIt@TCPROD
UNION
SELECT obid,
b2ProgramName,
projectName,
wbsID,
wbsName,
revision,
superseded,
lifeCycleState,
b2ChangeType,
b2Complexity,
r1SsiCode,
b2disposition,
wbsOriginator,
wbsAdministrator,
changepriority,
r1tsc,
t1comments,
b2securityclass,
t1changesafety,
t1actionofficer,
t1changereason,
t1wbsextchangenumber,
creator,
creationdate,
originatorassigndate
FROM rzptt1m4.cmPrRpIt@TCPRODit's the tablename in the hint, not the column name
something like
SELECT ec.obid AS prObid,
ec.b2ProgramName AS program,
ec.projectName AS project,
ec.wbsID AS prNo,
ec.wbsName AS title,
ec.revision AS revision,
ec.superseded AS revisionSuperseded,
ec.lifeCycleState AS lifeCycleState,
ec.b2ChangeType AS type,
ec.b2Complexity AS subType,
ec.r1SsiCode AS ssi,
ec.b2disposition as disposition,
ec.wbsOriginator AS requestor,
ec.wbsAdministrator AS administrator,
ec.changepriority as priority,
ec.r1tsc as tsc,
ec.t1comments as tenixComments,
ec.b2securityclass as securityClassification,
ec.t1changesafety as safety,
ec.t1actionofficer as actionOfficer,
ec.t1changereason as changeReason,
ec.t1wbsextchangenumber as extChangeNo,
ec.creator as creator,
to_date(substr(ec.creationdate,
0,
instr(ec.creationdate, ':', 1, 3) - 1),
'YYYY/MM/DD-HH24:MI:SS') as creationdate,
to_date(ec.originatorassigndate, 'YYYY/MM/DD') as originatorassigndate
FROM (SELECT /*+ DRIVING_SITE(awdbt1m4.cmPrRpIt) */ obid,
b2ProgramName,
projectName,
wbsID,
wbsName,
revision,
superseded,
lifeCycleState,
b2ChangeType,
b2Complexity,
r1SsiCode,
b2disposition,
wbsOriginator,
wbsAdministrator,
changepriority,
r1tsc,
t1comments,
b2securityclass,
t1changesafety,
t1actionofficer,
t1changereason,
t1wbsextchangenumber,
creator,
creationdate,
originatorassigndate
FROM awdbt1m4.cmPrRpIt@TCPROD
UNION
SELECT /*+ DRIVING_SITE(mart1m4.cmPrRpIt) */ obid,
b2ProgramName,
projectName,
wbsID,
wbsName,
revision,
superseded,
lifeCycleState,
b2ChangeType,
b2Complexity,
r1SsiCode,
b2disposition,
wbsOriginator,
wbsAdministrator,
changepriority,
r1tsc,
t1comments,
b2securityclass,
t1changesafety,
t1actionofficer,
t1changereason,
t1wbsextchangenumber,
creator,
creationdate,
originatorassigndate
FROM mart1m4.cmPrRpIt@TCPROD
UNION
SELECT /*+ DRIVING_SITE(mpsdt1m4.cmPrRpIt) */ obid,
b2ProgramName,
projectName,
wbsID,
wbsName,
revision,
superseded,
lifeCycleState,
b2ChangeType,
b2Complexity,
r1SsiCode,
b2disposition,
wbsOriginator,
wbsAdministrator,
changepriority,
r1tsc,
t1comments,
b2securityclass,
t1changesafety,
t1actionofficer,
t1changereason,
t1wbsextchangenumber,
creator,
creationdate,
originatorassigndate
FROM mpsdt1m4.cmPrRpIt@TCPROD
UNION
SELECT /*+ DRIVING_SITE(nondt1m4.cmPrRpIt) */ obid,
b2ProgramName,
projectName,
wbsID,
wbsName,
revision,
superseded,
lifeCycleState,
b2ChangeType,
b2Complexity,
r1SsiCode,
b2disposition,
wbsOriginator,
wbsAdministrator,
changepriority,
r1tsc,
t1comments,
b2securityclass,
t1changesafety,
t1actionofficer,
t1changereason,
t1wbsextchangenumber,
creator,
creationdate,
originatorassigndate
FROM nondt1m4.cmPrRpIt@TCPROD
UNION
SELECT /*+ DRIVING_SITE(rnast1m4.cmPrRpIt) */ obid,
b2ProgramName,
projectName,
wbsID,
wbsName,
revision,
superseded,
lifeCycleState,
b2ChangeType,
b2Complexity,
r1SsiCode,
b2disposition,
wbsOriginator,
wbsAdministrator,
changepriority,
r1tsc,
t1comments,
b2securityclass,
t1changesafety,
t1actionofficer,
t1changereason,
t1wbsextchangenumber,
creator,
creationdate,
originatorassigndate
FROM rnast1m4.cmPrRpIt@TCPROD
UNION
SELECT /*+ DRIVING_SITE(rnlht1m4.cmPrRpIt) */ obid,
b2ProgramName,
projectName,
wbsID,
wbsName,
revision,
superseded,
lifeCycleState,
b2ChangeType,
b2Complexity,
r1SsiCode,
b2disposition,
wbsOriginator,
wbsAdministrator,
changepriority,
r1tsc,
t1comments,
b2securityclass,
t1changesafety,
t1actionofficer,
t1changereason,
t1wbsextchangenumber,
creator,
creationdate,
originatorassigndate
FROM rnlht1m4.cmPrRpIt@TCPROD
UNION
SELECT /*+ DRIVING_SITE(rnolt1m4.cmPrRpIt) */ obid,
b2ProgramName,
projectName,
wbsID,
wbsName,
revision,
superseded,
lifeCycleState,
b2ChangeType,
b2Complexity,
r1SsiCode,
b2disposition,
wbsOriginator,
wbsAdministrator,
changepriority,
r1tsc,
t1comments,
b2securityclass,
t1changesafety,
t1actionofficer,
t1changereason,
t1wbsextchangenumber,
creator,
creationdate,
originatorassigndate
FROM rnolt1m4.cmPrRpIt@TCPROD
UNION
SELECT /*+ DRIVING_SITE(rzptt1m4.cmPrRpIt) */ obid,
b2ProgramName,
projectName,
wbsID,
wbsName,
revision,
superseded,
lifeCycleState,
b2ChangeType,
b2Complexity,
r1SsiCode,
b2disposition,
wbsOriginator,
wbsAdministrator,
changepriority,
r1tsc,
t1comments,
b2securityclass,
t1changesafety,
t1actionofficer,
t1changereason,
t1wbsextchangenumber,
creator,
creationdate,
originatorassigndate
FROM rzptt1m4.cmPrRpIt@TCPROD) ec(not tested, of course) -
Oracle insists on using particular index in SELECT -- HELP!!!
Here's the situation: Back in November, I wrote a report program that contained the following SELECT statement on SAP table FMIFIIT:
* Get data from the FMIFIIT table.
SELECT trbtr
fmbelnr
fmbuzei
fonds
fistl
farea
measure
fipex
zhldt
sgtxt
grant_nbr
FROM fmifiit
INTO TABLE it_fmifiit_data
WHERE zhldt >= p_bpdte AND
zhldt <= p_epdte AND
fistl IN r_fndctr AND
fistl BETWEEN '4011000000' AND '4013999999' AND
fonds IN r_fund AND
fipex BETWEEN '500000' AND '599999' AND
measure <> 'GRANT RELEVANT' AND
measure IN s_rio AND
wrttp NOT IN ('51','60','81') AND
stats = ' '.
I ran into time-out issues with this statement, so a new index ("Z5") was created on the following fields: ZHLDT, FISTL, FONDS, and FIPEX. This was the 11th custom index added to the table. The program was re-run, the statement picked up the new index, and it ran much faster. Problem solved.
Fast-forward to this week. I wrote a new report program that used a SELECT statement virtually identical to the one above. It looks like this:
* Get FMIFIIT data.
SELECT gjahr
knbelnr
knbuzei
measure
trbtr
fmbelnr
fmbuzei
fonds
fistl
farea
fipex
zhldt
sgtxt
FROM fmifiit
INTO TABLE it_fmifiit
WHERE zhldt >= p_bpdte AND
zhldt <= p_epdte AND
fistl IN r_fndctr AND
fonds IN r_fund AND
fipex BETWEEN '500000' AND '599999' AND
measure <> 'GRANT RELEVANT' AND
measure IN s_rio AND
wrttp NOT IN ('51','60','81') AND
stats = ' '.
Again, the program began running into time-out issues on this statement. I did a trace using ST05, and I found that the system was choose index "3" (FONDS, FIPEX, FIPOS) instead of the obviously-better "Z5" index created a few months ago.
I tried all kinds of things to figure out why it was choosing "3" to no avail. Basis even re-ran statistics on the FMIFIIT table, but that didn't work. Right now, my only option is to add an Oracle hint to the SELECT statement to force it to use index "Z5". In our DEV system, I've used SE30 to verify that this definitely improves the timing bottleneck that occurs when "3" is used.
I've only been an ABAP programmer for a few years now, and this one is technically beyond my knowledge. I don't know what else to try, and I don't know how to determine why the system keeps choosing the index it does. It's especially frustrating when the SELECT statement is so similar to the one from above, and in that case, it DOES pick up the "Z5" index.
Does anyone have any information/strategies/suggestions? At this point, I'm all ears.
Thanks so much!
DaveHi Dave,
based on the query I cannot share your view that there is an obvious choice.
In fact the best index choice depends on what your data looks like and how are the In-lists filled.
Maybe the range conditions are very useful, maybe the in-lists are the most selective criteria.
As a detailed analysis of this is a bit heavy to be done via this forum, why don't you just implement the hint and live happily with it?
Since you find your index sensible and have proven that it leads to better performance, you obviously know more about your data than Oracle does by the statistics.
Now you can either try and learn how the Oracle CBO works (there are notes and books available on this topic) or you just use your workaround although you may not exactly understand the reasons for the problem.
In general - if this would be a support message - I would ask you to ensure that all parameter recommendations are implemented and all CBO patches are installed.
Then I'd use the sql-statement data collection script (there's a sap note containing this script - just search for 'sql_id') to gather much of the relevant data.
And then I'd have to look into the data and figure out what's behind the CBOs decision.
As you wrote that you're rather on the ABAP side of live this effort may not necessarily be worthwhile when you have a proven workaround at hand.
regards,
Lars -
Using parameters in a select query sometimes not working
I use parameters throughout my code - usually without problem, but for some reason in one case it does not return a result. When I modify the querystring to contain the value instead of using parameters it works. Is it because I'm secting a clob? or is it because I'm using a 9i ODP.net dll against a 10g database? this is c# 2.0
here's the source code that does not work for me - REQUEST_DATA is a clob:
public String loadRequest(String PSRNumber)
String returnVal = null;
ConnectionStringSettings connectionInfo = System.Configuration.ConfigurationManager.ConnectionStrings["Scribe"];
OracleConnection myConnection = new OracleConnection();
String strSQL = "select PSR, REQUEST_DATA from stats.request where PSR = :PSR";
try
myConnection.ConnectionString = connectionInfo.ConnectionString;
OracleCommand cmd = new OracleCommand(strSQL, myConnection);
cmd.CommandType = CommandType.Text;
cmd.Parameters.Add("PSR", OracleDbType.Varchar2).Value = PSRNumber;
myConnection.Open();
OracleDataReader dr = cmd.ExecuteReader();
if (dr.Read())
returnVal = dr.GetOracleString(dr.GetOrdinal("REQUEST_DATA")).ToString();
else
returnVal = null;
dr.Dispose();
cmd.Dispose();
catch (OracleException ex)
printError(ex.Message);
finally
myConnection.Close();
myConnection.Dispose();
return returnVal;
}when I replace the line generating the sql, and remove the lines pertaining to parameters it works:
String strSQL = String.Format("select PSR, REQUEST_DATA from stats.request where PSR = {0}", PSRNumber);
I'm fine just using this as a workaround, but I need an explanation why the other does not work - I prefer to use parameters.
Message was edited by:
user633546I figured it out. thank you for your help in pointing me in the right direction.
the problem was there was a trailing space in the data.
when the data for that table is numeric for every record, the query allows me to leave out the single quotes. Trailing spaces do not seem to cause the database to see it as non-numeric - leaving out the quote still finds the record even if there is a trailing space.
but when I put in the quote, it is not an exact string match, so it could not find the record. sometimes this flexibility gets me into trouble :\ -
2 set of conditions to use in a Single Select query in procedure
Good day
I have one procedure, want to use one 2 set of conditions in Where clause
like
where condition1 < value
AND condition 2 > value
AND condition 3 = value
where condition 1 > value
AND condition 2 < value
AND condition 4 = value
How we should combine in a single select statement where cluase.
Please accept my sincere thanks first and looking your advice asap.
Regards
M.K.ThamaraiselvanHi,
While we use this procdure to run at that time it is not picking up any values also it is not running in it, taking very long time.What is not picking the value? Where clause is not picking the value, or
where clause is picking the value but you are not getting the output.
If it is you are not getting the output.
I suggest to run the sql query individually without pl/sql and check if the records actually exist.
Since it is taking very long time, I feel the sql query is actually being executed in the database but could be you are not getting the records (check if records actualy exist or if you are correctly passing the where clause)
Regards
Anurag
PS:
v_sql_string := 'SELECT table/viewname.colomn_name,'||v_order_by||','||v_report_line ||','||
v_output_line||',table/viewname.check_amount'||v_from_clause||v_where_clause||' ORDER BY '||v_order_by;So you are using dynamic sql, can you add an extra line
dbms_output.put_line(v_sql_string);
and check what the actual query is formed by pl/sql, if you are satisified the query is correct run it through sql plus and check why oracle does not give the result. MAy be there is no records satisfiying this condition. And I am sure you meant either table or viewname in (table/viewname.colomn_name) and not something like what you posted.
Edited by: Anurag Tibrewal on Oct 8, 2009 9:15 AM -
Using command button to select query - WAD 7.0
Hello all
Can anyone please tell me how to configure a command button (button group) to display a particular query in WAD 7.0?
Here's what I mean -
I have a web template with three queries. I have inserted 3 command buttons on the template. I want to assign one button to one query, so that the users can select which of the three they want to view. Which Command do I select in the command wizard to do this? Also, is it possible to hide the other two queries, when one is selected?
Thanks
KarenHi,
Here is one approach - Keep three analysis items in the WT. Assign three different data providers to all three analysis items. If you do not want to show any query when the WT first loads, don't assign any query to the data providers. When a button is pushed, you can use the command SET_DATA_PROVIDER_PARAMATERS to assign a query to a DP so that that query will show up.
Other commands that will help you would be SET_ITEM_PARAMETERS using which you can hide analysis items and also, you can use the command BACK_TO_INITIAL_DP_STATE on data providers so that they do not show up if they were blank at the start.
Another way to hide a query is to assign the analysis item to a data provider which is blank.
For your requirements, you will have to put multiple commands behind each button - you can decide which of the above commands suit you best.
Maybe you are looking for
-
When I open iTunes, it will not allow me to preview or download TV shows. The preview and download options are gray and will not let me view them. I have tried installing the latest Quicktime but it tells me that I have to do software update and when
-
Firefox sync not working with android 4.0 (ice cream sandwich)
Okay i'll try to explain this as best as i can. Over the weekend i installed the new android OS 4.0 Ice Cream Sandwich...before hand firefox sync (from my desktop to my cell phone) was working fine. I could see all of my bookmarks and all of my histo
-
Re: creating zoom for my canvas
HI I am trying to add zoom feature to the canvas which is the super class of the class zoom. As you can see when you run the code below. I have partially succeded in zooming in and zooming out with mouse drag. Although, the shapes dont zoom about the
-
Can we throw an error in java ,if yes plz give an example?
Hi, How can we throw an error in java like an exception(using try catch).If an error can be thrown then what is the diffrence between error and exception because both can be thrown using throwble. Thanks Sumit
-
How to get Meta tag information of a mp4 video file
I want to read Meta tag information of a video file like Artist,Album,Year,etc.... i have read the mp3 meta tag in myid3 for java but i cant for mp4 I tryed "onMetaData" for a video file.But i didnt get information like Artist,Album,Year,etc... would