Performance hit using "where" clause in the query
Hi All,
I am facing a huge performance hit in the java code when using "where" clause in queries. Following are the details:
1. SELECT * FROM Employee
2. SELECT * FROM Employee where employeeid in (26,200,330,571,618,945)
There is no difference in Query Execution Time for both queries.
Business Logic Time is huge in second case as compared to first one (ratio - 1:20).
Rows returned are more in first case as compared to second case.(ratio - 1:4)
Business Logic is same for both the cases where I iterate through the ResultSet, get the objects and set them in a data structure.
Does anybody know the reason of unexpected time difference for the business logic in the second case?
Since you're mentioning clustering your index, I'll assume you are using Oracle. Knowing what database you are using makes it a lot easier to suggest things.
Since you are using Oracle, you can get the database to tell you what execution plan it is using for each of the 2 SQL statements, and figure out why they have similar times (if they do).
First, you need to be able to run SQL*Plus; that comes as part of a standard database installation and as part of the Oracle client installation - getting it set up and running is outside the scope of this forum.
Second, you may need your DBA to enable autotracing, if it's not already:
http://asktom.oracle.com/~tkyte/article1/autotrace.html
http://www.samoratech.com/tips/swenableautotrace.htm
Once it's all set up, you can log in to your database using sql*plus, issue "SET AUTOTRACE ON", issue queries and get execution plan information back.
For example:
SQL> set autotrace on
SQL> select count(*) from it.ticket where ticket_number between 10 and 20;
COUNT(*)
11
Execution Plan
Plan hash value: 2983758974
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 4 | 1 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 4 | | |
|* 2 | INDEX RANGE SCAN| TICKET_N10 | 12 | 48 | 1 (0)| 00:00:01 |
Predicate Information (identified by operation id):
2 - access("TICKET_NUMBER">=10 AND "TICKET_NUMBER"<=20)
Statistics
0 recursive calls
0 db block gets
1 consistent gets
0 physical reads
0 redo size
515 bytes sent via SQL*Net to client
469 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL> This tells me that this query used an INDEX RANGE SCAN on index TICKET_N1; the query can't do much better than that logically... In fact, the statistic "1 consistent gets" tells me that Oracle had to examine only one data block to get the answer, also can't do better than that. the statistic, "0 physical reads" tells me that the 1 data block used was already cached in Oracle's memory.
the above is from Oracle 10g; autotrace is available back to at least 8i, but they've been adding information to the output with each release.
If you have questions about sql_plus, check the forums at asktom.oracle.com or http://forums.oracle.com/forums/category.jspa?categoryID=18
since sql*plus is not a JDBC thing...
Oh, and sql*plus can also give you easier access to timing information, with "set timing on".
Similar Messages
-
I have a .Net mobile service.
Calling this:
https://qserv.azure-mobile.net/tables/items?$filter=(company%20eq%20%27987af3f9-8d44-4a9d-8be2-7e0567287106%27)
Returns:
{"message":"The query specified in the URI is not valid. Could not find a property named 'company' on type 'Default.<>f__AnonymousType2_3OfString_String_Double'."}
The field name in the "items" entity model is "company" and on the database is "company_Id", neither will work.Using http://ajax.aspnetcdn.com/ajax/mobileservices/MobileServices.Web-1.2.5.min.jsWhat is wrong?
RegardsI see. Now works. So it would be like doing "SELECT ITEM,CATEGORY,COUNTRY, FROM TABLE WHERE CATEGORY='toy' AND COUNTRY='US'"
All rows will contain the "CATEGORY" and "COUNTRY" fields (or more), which is kind of redundant and bandwidth consuming.
Hope MS can change this.
Regards -
Using "in" clause in the query in Database control
Hi,
I have a database control and need to fire an update query to update a set of rows based on a list of values as input
Like below
update tablename
set column1="value1"
where column2 in (.......)
I need to pass a list of values for this query where column2 is a NUMBER field in Oracle DB.
can anyone help me how to go about passing this list of values?
Help is appreciated.
ThanksYou may build the comma-separated list in Java and use " {sql: ...} " in your query: http://e-docs.bea.com/workshop/docs81/doc/en/workshop/java-class/com/bea/control/DatabaseControl.html (sorry, I can't find the documentation for WLI 9.2).
-
Creating a where clause in the LOV query box
Hi guys is any able to help me with this one
i have a page in my app where there is a LOV drop down now the values for this drop down comes from a table that looks like this
users_for _form_TBL
E_MAIL
Vendor
[email protected]
oracle
[email protected]
sap
[email protected]
IBM
[email protected]
Oracle
[email protected]
intergraph
So my syntax for the LOV i mentioned looks like this
select VENDOR as display_value, VENDOR as return_value
from form_user_tab where E_MAIL = :APP_USER
order by 1 ;
so if [email protected] logs onto the app and has to make a selection on the LOV it would only display the vendors relative to his E_MAIL like oracle ,sap, IBM then he hits the submit button on the page then the vendor that he selected is inserted into another table .What i did on the insert table was create a trigger that after a vendor is inserted the trigger inserts a 1 into a column called assessed .
What i did after this was add a select in the where clause of the LOV so that it would check in the insert table if that vendor had been chosen before and not display it again to be selected my syntax the second time around in the SQL query box was
select VENDOR as display_value, VENDOR as return_value
from users_for _form_TBL where E_MAIL = :APP_USER
and (select 'vendor' , 'ASSESSD' from inserted _tbl_imp is null);
order by 1 ;
But im getting an error any ideas guys .Thank youHay man thanks for that info on the Tom Kyte Blog
--(the code you gave me )
select
u.vendor display_value
, u.vendor return_value
from
users_for_form_tbl u
where
u.e_mail = :app_user
and not exists (select null from inserted_tbl_imp i where u.vendor = i.vendor)
order by
u.vendor
--(After the error i tried )Then when i got the error i try'd using 'or exists' like this
--(code)
where
u.e_mail = :app_user
and not exists (select null from inserted_tbl_imp i where u.vendor = i.vendor)
or exists (select null from inserted_tbl_imp i where u.vendor = i.vendor)
order by
u.vendor
But the all the vendors that where in the same in the insert table came up in the drop down list example is oracle was assessed before then only oracle would appear in the drop down list and if it was assessed 3 times it would come up 3 times
--Then i tried to select where 'Assessed' is null ('Assessed' is a column in the insert table which i created a trigger on to insert 1 in the 'ASSESSED' column when a vendor is begin assessed )
--(code)
where
u.e_mail = :app_user
and not exists (select 'ASSESSED' from inserted_tbl_imp i where 'ASSESSED' is null )
order by
u.vendor
This try didnt return any vendors at all
--Then i tried distinct
--(code)
where
u.e_mail = :app_user
and not exists (select distinct 'VENDOR', from inserted_tbl_imp i where u.vendor = i.vendor)
order by
u.vendor
This gave me a LOV ERROR
This is what i have tried so far there where others syntax's i tried last night as well but most of them came back as errors . Thanks again for you time and help fac586 -
How to Get the required List Item values by using Where Clause
I have two tables named "TAX_RULES","BILL"
1. " Tax_Rules" (Sub_Head_Code,Tax_ID,Tax_Percentage)
{ While "Sub_Head_Code" field is unique,
Tax_ID describes that there are two kinds of Tax_IDs based on Tax_percentage which is 6% for some Sub_Head_Codes and 3.5% for the remainng Sub_Head_Codes. I have given Tax_ID 1 for 6% and Tax_ID 2 for Sub_Head_codes having 3.5%. }
2. "BILL" (Bill_ID,Sub_Head_Code,Tax_ID,Bill_Amount)
{While "Bill_ID" describes unique Bill Identification Number,
Sub_Head_Code and Tax_ID are behaving like composite foreign key from Tax_Rules table}
I have design form for both tables.
In BILL form i am trying to get values of Tax_ID from Tax_Rules table at run-time by using WHEN-NEW-FORM-INSTANCE.
For this whenever i select a Sub_Head_Code in Bill Form, all the Tax_IDs that i have recorded against each Sub_Head_Code which is either 1 or 2 against 6% and 3.5% respectively.
But I want that whenever i select a "Sub_Head_Code", Only that Tax_ID which is associated with that Sub_Head_Code ahould come in the LIST ITEM.
I have used WHERE clause but that is useless.
Following is the Code that i have applied in the WHE-NEW-ITEM-INSTANCE Trigger at FORM LEVEL
<CODE>
DECLARE
rg_n1 VARCHAR2(40) :='TAX_ID';
rg_idn1 RecordGroup;
gc_idn1 GroupColumn;
errcode NUMBER;
BEGIN
CLEAR_LIST('BILL.TAX_ID');
rg_idn1 := Find_Group(rg_n1);
IF Id_Null(rg_idn1) then
rg_idn1 := Create_Group(rg_n1);
gc_idn1 := Add_Group_Column(rg_idn1,'EXPLAIN',CHAR_COLUMN,60);
gc_idn1 := Add_Group_Column(rg_idn1,'TAX_ID',CHAR_COLUMN,3);
END IF;
errcode := Populate_Group_With_Query(rg_idn1,'select TAX_ID,TAX_ID from TAX_RULES');
POPULATE_LIST('BILL.TAX_ID',RG_IDn1);
END;
</CODE>In the Tax Rules table, you state:
"Sub_Head_Code" field is unique
In the Bill table, you state:
Sub_Head_Code and Tax_ID are behaving like composite foreign key from Tax_Rules table
If the Sub_Head_Code is unique, then it's acting as a primary key, so Sub_Head_Code and Tax_ID in the Bill table are not behaving like a composite foreign key. The Sub_Head_Code is a foreign key, and the Tax_ID is irrelevant as far as keys are concerned.
It is not clear what it is you want to do.
If you want to display the Tax_IDs from the Bill table when you select a Sub_Head_Code from the Tax_Rules table, then change your query to:
select TAX_ID, TAX_ID from BILL where Sub_Head_Code = :Tax_Rules.Sub_Head_Code
If you want to display the Tax_IDs from the Tax_Rules table when you select a Sub_Head_Code from the Bill table, then change your query to:
select TAX_ID, TAX_ID from TAX_RULES where Sub_Head_Code = :Bill.Sub_Head_Code
If this is not what you want, then clarify what it is you want to do. Don't say:
"I want that whenever i select a "Sub_Head_Code", Only that Tax_ID which is associated with that Sub_Head_Code"
because it is not clear what tables you are referring to. -
How do you use 3 Where Clauses in a query
Hi, i am trying to figure out how to use 3 Where Clauses in a Query where 2 of the Where Clauses uses a Sub query.
Display the OrderID of all orders that where placed after all orders placed by “Bottom-Dollar Markets”.
Order the result by OrderID in ascending order.
First WHERE clause checks for OrderDate and uses a sub query with ALL keyword.
Second WHERE clause use equals and sub query.
Third WHERE clause uses equal and company name.
This is what i have so far but i am pretty confused on how to do this.
My Code for NorthWind:
Select OrderID
From Orders o
Where o.OrderID IN (Select OrderDate From Orders Where Orders.OrderID > ALL
(Select CompanyName From Customers Where CompanyName = 'Bottom-Dollar Markets'));
The book shows how to use the ALL Keyword but not in a Sub query with Multiple Where Clauses.
Select VenderName, InvoiceNumber, InvoiceTotal
FROM Invoices JOIN Vendors ON Invoices.VendorID = Vendors.VendorID
WHERE InvoiceTotal > ALL (Select InvoiceTotal From Invoices Where VendorID = 34)
ORDER BY VendorName;>Where Orders.OrderDate
> ALL (Select
CompanyName
The comparison operator (>) requires compatible data types.
DATETIME is not compatible with VARCHAR string for comparison.
Here is your homework:
SELECT orderid
FROM orders o
WHERE o.orderdate > ALL (SELECT orderdate
FROM orders
WHERE shipvia = (SELECT Max(shipvia)
FROM orders o
INNER JOIN customers c
ON c.customerid =
o.customerid
WHERE
c.companyname = 'Bottom-Dollar Markets'));
11064
11065
11066
11067
11068
11069
11070
11071
11072
11073
11074
11075
11076
11077
Kalman Toth Database & OLAP Architect
SQL Server 2014 Database Design
New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2014 -
I am not able to run a SQL query using where clause.
the query is as follows:
I extract the text input by the user in a text field say 'a' and
store it in string 'y'.
String y= a.getText();
//running the query
Select A from B where B.x=y;
how do we run a where clause when y is a string variable instead of value?Use the following :
String y = a.getText();
String query ="select A.CODE from Port A where A.NAME=" + "'" + y + "'" ;
ResultSet rs= stmt.executeQuery(query); -
Regarding dynamically assigning the where clause to select query
hi,
Please send the code regarding how to dynamically assign the where clause to select query.
thanks in advanceSELECT <fileds>
INTO TABLE itab
FROM dbase
WHERE condition. -
Hi all,
im trying to set a block default where clause in the pre-query trigger of my block "customer_settlement" , to query the records that exist in a customers table like this, where the customer_name is variable based on the value entered by the user in enter-query mode before hitting the F8 key , the statement is :
set_block_property( 'customer_settlement' , default_where ,
' fk_cust_code in ( select customer_code from customers where customer_name like %' || :customer_settlement.customer_name ||'% )' );
the query doesnt work and giving me an error " unable to perform query" , notice that :customer_settlement.customer_name is an item in the block , the user change it and would like to query upon it , and its not a base table item on customer_settlement block its on customers table only . I tried all combinations of '%' and || but it seems that oracle can't see the value In the customer_name field.
any help is highly thanked.
im using Oracle form 9.0.4 and Oracle 10g Db.
Regards,
IKQHi,
does this work ?
set_block_property( 'customer_settlement' , default_where ,
' fk_cust_code in ( select customer_code from customers where customer_name like '''%' || :customer_settlement.customer_name ||'%''' )' );
Frank -
Can we use where clause in Update on Merge statement?
Hi All,
I tried to execute the following Merge Query:
When this query is executed without ‘Where clause’ in Update statement its working fine. When executed with ‘Where clause’ it throwing the following error:
ORA-00905: missing keyword.
Following is the sample query which I tried to execute:
MERGE INTO TABLE_NAME
USING (SELECT COLUMN FORM TABLES)
ON (CONDITION)
WHEN MATCHED THEN
UPDATE SET
COLUMN UPATES
WHERE CONDITION -- Can we use where clause here?
WHEN NOT MATCHED THEN
INSERT
INSERT VALUES;
Can some one help on this?
Thanks in advance.
DariusYes:
SQL> drop table emp1;
Table dropped.
SQL> create table emp1 as select * from emp where deptno = 30;
Table created.
SQL> update emp1 set sal = sal*2;
6 rows updated.
SQL> commit;
Commit complete.
SQL> select ename,sal from emp1;
ENAME SAL
ALLEN 3200
WARD 2500
MARTIN 2500
BLAKE 5700
TURNER 3000
JAMES 1900
6 rows selected.
SQL> MERGE INTO emp1
2 USING(select * from emp) emp
3 ON (emp1.empno = emp.empno)
4 WHEN MATCHED THEN
5 UPDATE SET sal = emp.sal WHERE ename = 'TURNER'
6 WHEN NOT MATCHED THEN
7 INSERT(ename,sal) VALUES(emp.ename,emp.sal);
9 rows merged.
SQL> select ename,sal from emp1;
ENAME SAL
ALLEN 3200
WARD 2500
MARTIN 2500
BLAKE 5700
TURNER 1500
JAMES 1900
SMITH 800
JONES 2975
CLARK 2450
SCOTT 3000
KING 5000
ENAME SAL
ADAMS 1100
FORD 3000
MILLER 1300
14 rows selected.
SQL> SY. -
How can I pass multiple condition in where clause with the join table?
Hi:
I need to collect several inputs at run time, and query the record according to the input.
How can I pass multiple conditions in where clause with the join table?
Thanks in advance for any help.
Regards,
TDIf you are using SQL-Plus or Reports you can use lexical parameters like:
SELECT * FROM emp &condition;
When you run the query it will ask for value of condition and you can enter what every you want. Here is a really fun query:
SELECT &columns FROM &tables &condition;
But if you are using Forms. Then you have to change the condition by SET_BLOCK_PROPERTY.
Best of luck! -
How to use WHERE Clause in BPEL
Hi ,
i am trying to use where clause in DB adapter but its not working.
my query is "select empname from employee where empid = &a"
can any body tell me what is the reason its npt working?
and how can i retrive data form DB?Hi,
You are thinking perfectly fine. The solution what I suggested was
select ename from emp where empno=?
And the solution provided by you was
SELECT first_name, last_name FROM per_all_people_f WHERE person_id = #p_person_id
There is no problem with the above mentioned select statements.
I just want to say that if you see closely, internal logic changes #parameter name to ?. So both the logics are right.
Cheers,
Abhi... -
Where Clause in the Forms doesn't work
Hi,
I am trying to execute a query in base table block. The block property 'Query allowed' is TRUE and WHere clause is null;
I used 'SET_BLOCK_PROPERTY' and set the where clause. Did a GO_BLOCK and EXECUTE_QUERY;
The block brings all records as if there is no where clause. TO make sure I put up a message 'GET_BLOCK_PROPERTY' to see the where clause. It showed correct where clause.
nullSetting the where clause the way you did usually works, and it worked fine for me several times.
Yet, a couple of days ago I ran into something that defies my logic:
1) when using the "=" operator, it fetched me several records that satisfied the condition
2) when using the "<=" or ">=" operator it fetched only one of the records that satisfied the condition: the one that is strictly equal.
I tried using the pre-query trigger, but to no avail.
I'm looking forward for your succes.
null -
How to set Where clause in the View Object of the MessageChoice ?
Hi,
How to set Where clause in the View Object of the
MessageChoice ?
Example:
<bc4j:rootAppModuleDef name="EdEscolaCampusView1AppModule"
definition="ed00050.Ed00050Module"
releaseMode="stateful" >
<bc4j:viewObjectDef name="EdEscolaCampusView1" >
<bc4j:rowDef name="CreateEdEscolaCampusView1" autoCreate="true" >
<bc4j:propertyKey name="key" />
</bc4j:rowDef>
</bc4j:viewObjectDef>
<bc4j:viewObjectDef name="ListaTipLocalView1"
rangeSize="9999">
</bc4j:viewObjectDef>
</bc4j:rootAppModuleDef>
</bc4j:registryDef>
messageChoice declaration:
<bc4j:messageChoice name="SeqTipoLocalCampus"
attrName="SeqTipoLocalCampus"
prompt="Local do Campus">
<contents>
<bc4j:optionList attrName="SeqTipoBasico"
textAttrName="NomTipoBasico"
voName="ListaTipLocalView1"/>
</contents>
</bc4j:messageChoice>
I would like set where clause of ViewObject, with dinamic parameters (using attribute1 = :1), before populate messageChoice.
thanks...
DaniloHi Andy,
I try set a where clause using the message:
Set where Clause parameter using UIX , but my UIX Page have 2 messageChoice's of different ViewObject's, then I need implement this Java Class:
//Nome da Package da Tela Detail
package br.com.siadem.siaed.ed00050;
// Importa as Bibliotecas necessárias
import oracle.jbo.ViewObject;
import oracle.jbo.ApplicationModule;
import oracle.jbo.client.Configuration;
import oracle.cabo.servlet.BajaContext;
import oracle.cabo.servlet.Page;
import oracle.cabo.servlet.event.PageEvent;
import oracle.cabo.servlet.event.EventResult;
import oracle.cabo.data.jbo.servlet.bind.*;
import oracle.cabo.ui.data.BoundValue;
import oracle.cabo.ui.data.DataBoundValue;
import javax.servlet.http.HttpServletRequest;
import br.com.siadem.siaed.util.*;
import javax.servlet.http.Cookie;
import oracle.cabo.data.jbo.def.NestedAppModuleDef;
import oracle.cabo.data.jbo.def.ViewObjectDef;
import oracle.cabo.data.jbo.def.AppModuleDef;
// Classe que configura os parametros para a execução da Query,
// utilizando variáveis de Sessao
public class FunPreQueryLista
public static EventResult FunConfiguraQuery(BajaContext context, Page page, PageEvent event) throws Throwable
// TrataDadosSessao - Classe utilizada para retornar os valores das variáveis de sessão genéricas
// Ex: CodCliente, CodMunicipio etc...
TrataDadosSessao varDadosSessao = new TrataDadosSessao();
// 1o. Parametro Configurado - Através da classe TrataDadosSessao, utilizando um método Get
// <alterar>
String valor1 = varDadosSessao.getCodCliente();
String valor2 = varDadosSessao.getCodMunicipio();
//Cria o objeto que retorna o ApplicationModule
ApplicationModule am = ServletBindingUtils.getApplicationModule(context);
// Início das Configurações da Query da Lista
//Cria o objeto que retorna o view object da lista desejada
//alterar
ViewObject TipoLocal = am.findViewObject("ListaTipoLocalView1");
//Configuração dos parametros definidos na query do view Object
//alterar
TipoLocal.setWhereClauseParam(0,valor1);
TipoLocal.setWhereClauseParam(1,valor2);
// Executa a Query
TipoLocal.executeQuery();
// Fim das Configurações da Query da Lista
// Início das Configurações da Query da Lista
//Cria o objeto que retorna o view object da lista desejada
//alterar
ViewObject TipoDestLixo = am.findViewObject("ListaDestinoLixoView1");
//Configuração dos parametros definidos na query do view Object
//alterar
TipoDestLixo.setWhereClauseParam(0,valor1);
TipoDestLixo.setWhereClauseParam(1,valor2);
// Executa a Query
TipoDestLixo.executeQuery();
// Fim das Configurações da Query da Lista
// Retorna o Resultado para a Página
return new EventResult(page);
The code works very well...
And, I'm sorry for my two repost's in UIX Forum about this in a few time.
Thank very much...
Danilo -
How to use where clause with get statement in LDB programs
Hi All,
I am using logical databse in my report program.I am not getting how to use the where clause in the get statement is it possible to use?or if not possible only option is we should filter it after get statment is right?Can you please some body throw some idea on this?
Regards
MaheshHi,
Reffer these links
http://help.sap.com/saphelp_nw04/helpdata/en/9f/db9bfa35c111d1829f0000e829fbfe/content.htm
http://help.sap.com/saphelp_nw04/helpdata/en/9f/db9b5e35c111d1829f0000e829fbfe/frameset.htm
http://help.sap.com/saphelp_nw04/helpdata/en/c6/8a15381b80436ce10000009b38f8cf/frameset.htm
/people/srivijaya.gutala/blog/2007/03/05/why-not-logical-databases
reward if helpful
Thanks,
Suma.
Maybe you are looking for
-
I want to give my wife and daughters their own Apple ID's and have them purchase stuff using the new one, but I don't want them to lose all of the music and videos they bought using my ID for the last 8 years. The main reason I want to do this, is s
-
Photoshop CS4 Issue with NVIDIA 8800 Video Card?
I have an Mac Pro Intel 2 x 2.8 GHz Quad-Core Xeon with 6GB RAM running OS X 10.5.5 and an NVIDIA GeForce 8800 GT driving two monitors. I just installed Adobe Photoshop CS4 fresh from a factory CD. When I perform a Distort -> Lens Correction or do a
-
Now the song is not in my phones memory anymore and when I want to listen to it I have to download it again. It picks and chooses songs randomly and for some reason it is usually the most current ones I download. How do I stop my phone from automat
-
Subscriptions in google play?
Hi - Much to my dismay I have just found that the DPS viewer does not support subscriptions in google play. Does anyone know a workaround to this? Can I engineer something from the google end of things?
-
Hi friends! I'm making some changes in a copy of Sap form medruck. I have line with text and I used ',,' to space, but por minimal adjusts I'm trying with blanks spaces, but it don't take effects....why space is not moving the text? I'm using a defau