How can i improve the performance of this query?
-
Hi am quite new to SQL/ADO. how can i improve the speed of retrieving data of this query? I tried very long already but still.. thats is the best i can get. it took 10s to complete the whole query. Its querying oracle database. SELECT DISTINCT ppar_engparameters.parmval, ppar_engparameters.parmname, prcd.prcdname||' '||prcd.prcdversion, prcd.activeflag, prcd.prodstatis FROM prcd, ppar_engparameters WHERE ppar_engparameters.parmval='" & name & "' AND prcd.activeflag='A' AND ppar_engparameters.prcdname = prcd.prcdname and also how can i combine this query to the first one without compromising on the speed of retrieving data? when i tried, it took me hundreds of seconds. SELECT catnumber, category FROM catg_pll where catg_pll.partprcdname||' '||catg_pll.partprcdversion = prcd.prcdname||' '||prcd.prcdversion
-
Hi am quite new to SQL/ADO. how can i improve the speed of retrieving data of this query? I tried very long already but still.. thats is the best i can get. it took 10s to complete the whole query. Its querying oracle database. SELECT DISTINCT ppar_engparameters.parmval, ppar_engparameters.parmname, prcd.prcdname||' '||prcd.prcdversion, prcd.activeflag, prcd.prodstatis FROM prcd, ppar_engparameters WHERE ppar_engparameters.parmval='" & name & "' AND prcd.activeflag='A' AND ppar_engparameters.prcdname = prcd.prcdname and also how can i combine this query to the first one without compromising on the speed of retrieving data? when i tried, it took me hundreds of seconds. SELECT catnumber, category FROM catg_pll where catg_pll.partprcdname||' '||catg_pll.partprcdversion = prcd.prcdname||' '||prcd.prcdversion
Some things to look at are:
- Make sure you have proper indexes on your tables.
- Look at using some inner (or outer) joins, depending on what data you are trying to return.
Scott. —In just two days, tomorrow will be yesterday. —Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
[Forum Guidelines] [Articles] [Blog]
-
Some things to look at are:
- Make sure you have proper indexes on your tables.
- Look at using some inner (or outer) joins, depending on what data you are trying to return.
Scott. —In just two days, tomorrow will be yesterday. —Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
[Forum Guidelines] [Articles] [Blog]
hi, I am not sure of the indexes on the tables as this is a company database and I am actually a student on attachment and the company ask me to try this. I had tried using inner joins but the speed got even slower result return. Thus I am now lost of what to do already. Haix. :((
-
hi, I am not sure of the indexes on the tables as this is a company database and I am actually a student on attachment and the company ask me to try this. I had tried using inner joins but the speed got even slower result return. Thus I am now lost of what to do already. Haix. :((
tonyong wrote:
I am not sure of the indexes on the tables as this is a company database and I am actually a student on attachment and the company ask me to try this
Honestly that shouldn't matter. You are working for them for a reason. It should be expected that you ask some level of questions in order to get your job done. However, given the situation you may need to ask those questions a bit more carefully than normal. If you ask something along the lines of "You want to verify the indexes on the tables" I don't see any reason this should cause problems. You may want to review the joins again. My guess is that you used the wrong type of join. It's been a long time since I've worked with Oracle, but if there is any type of tool that lets you look at the execution plan for the query (the steps that the database engine will perform to actually run the query) that is the best place to start. That should tell you if indexes are being used, how many rows are being returned for each part of the query, etc.
Scott. —In just two days, tomorrow will be yesterday. —Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
[Forum Guidelines] [Articles] [Blog]
-
tonyong wrote:
I am not sure of the indexes on the tables as this is a company database and I am actually a student on attachment and the company ask me to try this
Honestly that shouldn't matter. You are working for them for a reason. It should be expected that you ask some level of questions in order to get your job done. However, given the situation you may need to ask those questions a bit more carefully than normal. If you ask something along the lines of "You want to verify the indexes on the tables" I don't see any reason this should cause problems. You may want to review the joins again. My guess is that you used the wrong type of join. It's been a long time since I've worked with Oracle, but if there is any type of tool that lets you look at the execution plan for the query (the steps that the database engine will perform to actually run the query) that is the best place to start. That should tell you if indexes are being used, how many rows are being returned for each part of the query, etc.
Scott. —In just two days, tomorrow will be yesterday. —Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
[Forum Guidelines] [Articles] [Blog]
I see. I will go and check again with them. I am not sure which type of joins to use as my knowledge with regards to sql is very little. In school we are given the codes to see the results and this is actually the first time i am trying to come up with my own codes to query the database and for days i am still not able to come up with any better than then first one. There is 3 tables i need to get data from. All the 3 table has 2 common keys. As for the execution plan, I guess i had to ask them to see if i am able to get them.
-
Hi am quite new to SQL/ADO. how can i improve the speed of retrieving data of this query? I tried very long already but still.. thats is the best i can get. it took 10s to complete the whole query. Its querying oracle database. SELECT DISTINCT ppar_engparameters.parmval, ppar_engparameters.parmname, prcd.prcdname||' '||prcd.prcdversion, prcd.activeflag, prcd.prodstatis FROM prcd, ppar_engparameters WHERE ppar_engparameters.parmval='" & name & "' AND prcd.activeflag='A' AND ppar_engparameters.prcdname = prcd.prcdname and also how can i combine this query to the first one without compromising on the speed of retrieving data? when i tried, it took me hundreds of seconds. SELECT catnumber, category FROM catg_pll where catg_pll.partprcdname||' '||catg_pll.partprcdversion = prcd.prcdname||' '||prcd.prcdversion
I've never used Oracle, so this may or may not help. But in SQL Server concatenation of strings will disable the use of any indexes. So your 2nd query might perform better if you rewrote it like this:
SELECT catnumber, category FROM catg_pll where catg_pll.partprcdname = prcd.prcdname AND catg_pll.partprcdversion = prcd.prcdversion
Mark's blog: developMENTALmadness.blogspot.com
-
I see. I will go and check again with them. I am not sure which type of joins to use as my knowledge with regards to sql is very little. In school we are given the codes to see the results and this is actually the first time i am trying to come up with my own codes to query the database and for days i am still not able to come up with any better than then first one. There is 3 tables i need to get data from. All the 3 table has 2 common keys. As for the execution plan, I guess i had to ask them to see if i am able to get them.
-
Hi, after reading the two, i came out with a new query that combines the two query together. However the speed is still not good. Still thinking of ways to make it faster. In the query what i want is to get data out from 3 tables that is corresponded to B value in one of the table.
-
Hi, after reading the two, i came out with a new query that combines the two query together. However the speed is still not good. Still thinking of ways to make it faster. In the query what i want is to get data out from 3 tables that is corresponded to B value in one of the table.
The following SQL would return all of the data from all 3 tables:
SELECT ppar_engparameters.parmval, ppar_engparameters.parmname, prcd.prcdname||' '||prcd.prcdversion, prcd.activeflag, prcd.prodstatis, catg_pll.catnumber, catg_pll.category FROM ppar_engparameters INNER JOIN prcd ON prcd.prcdname = ppar_engparameters.prcdname AND prcd.activeflag = 'A' LEFT OUTER JOIN catg_pll ON catg_pll.partprcdname = prcd.prcdname AND catg_pll.partprcdversion = prcd.prcdversion WHERE ppar_engparameters.parmval= 'MyValue'
I have removed the "distinct" clause that you had in the original. This is often used to hide poorly-designed tables - you understand where-and-why you are getting duplicates before blindly using this. Proper indexes are required to make this run fast. I would expect the following indexes (or primary keys) from your original description:
--For the link from product-parameter to product. create unique index prcd_idx1 on prcd (prcdname, prcdversion) --For the link from product. create index catg_pll_idx1 on catg_pll (partprcdname, partprcdversion) --For the search on parameter values. create index ppar_engparameters_idx1 on ppar_engparameters (parmval, activeflag)
Other indexes may also be required for other activities. There should ideally be a primary key or unique-index on every table. Oracle's query optimiser uses statistical data from indexes to determine the best way of answering your queries. There is a command (that I cannot remember) for recalculating these statistics. Oracle is also able to display the query-plan that it uses - so you would be able to tell exactly what Oracle is doing under the covers. Search Google[^] for more information. Hope that helps. Regards Andy
-
The following SQL would return all of the data from all 3 tables:
SELECT ppar_engparameters.parmval, ppar_engparameters.parmname, prcd.prcdname||' '||prcd.prcdversion, prcd.activeflag, prcd.prodstatis, catg_pll.catnumber, catg_pll.category FROM ppar_engparameters INNER JOIN prcd ON prcd.prcdname = ppar_engparameters.prcdname AND prcd.activeflag = 'A' LEFT OUTER JOIN catg_pll ON catg_pll.partprcdname = prcd.prcdname AND catg_pll.partprcdversion = prcd.prcdversion WHERE ppar_engparameters.parmval= 'MyValue'
I have removed the "distinct" clause that you had in the original. This is often used to hide poorly-designed tables - you understand where-and-why you are getting duplicates before blindly using this. Proper indexes are required to make this run fast. I would expect the following indexes (or primary keys) from your original description:
--For the link from product-parameter to product. create unique index prcd_idx1 on prcd (prcdname, prcdversion) --For the link from product. create index catg_pll_idx1 on catg_pll (partprcdname, partprcdversion) --For the search on parameter values. create index ppar_engparameters_idx1 on ppar_engparameters (parmval, activeflag)
Other indexes may also be required for other activities. There should ideally be a primary key or unique-index on every table. Oracle's query optimiser uses statistical data from indexes to determine the best way of answering your queries. There is a command (that I cannot remember) for recalculating these statistics. Oracle is also able to display the query-plan that it uses - so you would be able to tell exactly what Oracle is doing under the covers. Search Google[^] for more information. Hope that helps. Regards Andy
The distinct clause does make a difference of ard 20s. But how come it give repeated values? My current code is
select distinct ppar_engparameters.parmval, ppar_engparameters.parmname, prcd.prcdname||' '||prcd.prcdversion, prcd.activeflag, prcd.prodstatus, catg_pll.catgnumber, catg_pll.category from ppar_engparameters inner join prcd on prcd.prcdname = ppar_engparameters.prcdname and prcd.activeflag='A' inner join catg_pll on catg_pll.partprcdname = ppar_engparameters.prcdname and catg_pll.partprcdversion = ppar_engparameters.prcdversion where ppar_engparameters.parmval='MyValue'
As for the query plan and stuffs i still cant access to it. Thanks. Tony -
The following SQL would return all of the data from all 3 tables:
SELECT ppar_engparameters.parmval, ppar_engparameters.parmname, prcd.prcdname||' '||prcd.prcdversion, prcd.activeflag, prcd.prodstatis, catg_pll.catnumber, catg_pll.category FROM ppar_engparameters INNER JOIN prcd ON prcd.prcdname = ppar_engparameters.prcdname AND prcd.activeflag = 'A' LEFT OUTER JOIN catg_pll ON catg_pll.partprcdname = prcd.prcdname AND catg_pll.partprcdversion = prcd.prcdversion WHERE ppar_engparameters.parmval= 'MyValue'
I have removed the "distinct" clause that you had in the original. This is often used to hide poorly-designed tables - you understand where-and-why you are getting duplicates before blindly using this. Proper indexes are required to make this run fast. I would expect the following indexes (or primary keys) from your original description:
--For the link from product-parameter to product. create unique index prcd_idx1 on prcd (prcdname, prcdversion) --For the link from product. create index catg_pll_idx1 on catg_pll (partprcdname, partprcdversion) --For the search on parameter values. create index ppar_engparameters_idx1 on ppar_engparameters (parmval, activeflag)
Other indexes may also be required for other activities. There should ideally be a primary key or unique-index on every table. Oracle's query optimiser uses statistical data from indexes to determine the best way of answering your queries. There is a command (that I cannot remember) for recalculating these statistics. Oracle is also able to display the query-plan that it uses - so you would be able to tell exactly what Oracle is doing under the covers. Search Google[^] for more information. Hope that helps. Regards Andy