query-optimization

PL/SQL Performance Tuning for LIKE '%…%' Wildcard Queries

寵の児 提交于 2019-11-28 09:08:21
We're using Oracle 11g database. As you may or may not know, if you use wildcard query with "%" in front of the string, the column index is not being used and a full table scan is happening. It looks like there isn't a definitive suggestion on how to improve this kind of query, but perhaps you could share some valuable information from your experience on how to optimize the following query: SELECT * FROM myTable WHERE UPPER(CustomerName) like '%ABC%' OR UPPER(IndemnifierOneName) like '%ABC%' OR UPPER(IndemnifierTwoName) like '%ABC%'; ...where all 3 columns are of type varchar2(100) and ABC is

Postgres query optimization (forcing an index scan)

谁说胖子不能爱 提交于 2019-11-28 08:56:53
Below is my query. I am trying to get it to use an index scan, but it will only seq scan. By the way the metric_data table has 130 million rows. The metrics table has about 2000 rows. metric_data table columns: metric_id integer , t timestamp , d double precision , PRIMARY KEY (metric_id, t) How can I get this query to use my PRIMARY KEY index? SELECT S.metric, D.t, D.d FROM metric_data D INNER JOIN metrics S ON S.id = D.metric_id WHERE S.NAME = ANY (ARRAY ['cpu', 'mem']) AND D.t BETWEEN '2012-02-05 00:00:00'::TIMESTAMP AND '2012-05-05 00:00:00'::TIMESTAMP; EXPLAIN: Hash Join (cost=271.30.

Performance difference: condition placed at INNER JOIN vs WHERE clause

。_饼干妹妹 提交于 2019-11-28 08:56:41
Say I have a table order as id | clientid | type | amount | itemid | date ---|----------|------|--------|--------|----------- 23 | 258 | B | 150 | 14 | 2012-04-03 24 | 258 | S | 69 | 14 | 2012-04-03 25 | 301 | S | 10 | 20 | 2012-04-03 26 | 327 | B | 54 | 156 | 2012-04-04 clientid is a foreign-key back to the client table itemid is a foreign key back to an item table type is only B or S amount is an integer and a table processed as id | orderid | processed | date ---|---------|-----------|--------- 41 | 23 | true | 2012-04-03 42 | 24 | true | 2012-04-03 43 | 25 | false | <NULL> 44 | 26 | true |

Meaning of “Select tables optimized away” in MySQL Explain plan

谁说我不能喝 提交于 2019-11-28 08:52:40
What is the meaning of Select tables optimized away in MySQL Explain plan? explain select count(comment_count) from wp_posts; +----+-------------+---------------------------+-----------------------------+ | id | select_type | table,type,possible_keys, | Extra | | | | key,key_len,ref,rows | | +----+-------------+---------------------------+-----------------------------+ | 1 | SIMPLE | all NULLs | Select tables optimized away| +----+-------------+---------------------------+-----------------------------+ 1 row in set (0.00 sec) Note: explain plan output edited for legibility. It means you have

Get n grouped categories and sum others into one

时光总嘲笑我的痴心妄想 提交于 2019-11-28 08:18:46
问题 I have a table with the following structure: Contents ( id name desc tdate categoryid ... ) I need to do some statistics with the data in this table. For example I want to get number of rows with the same category by grouping and id of that category. Also I want to limit them for n rows in descending order and if there are more categories available I want to mark them as "Others". So far I have come out with 2 queries to database: Select n rows in descending order: SELECT COALESCE(ca.NAME,

MySql.Data.MySqlClient.MySqlException: Timeout expired

╄→尐↘猪︶ㄣ 提交于 2019-11-28 07:10:14
问题 In recent times, a particular page in my web app throws the Exception Details: MySql.Data.MySqlClient.MySqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. Though I use Ibtais as persistence layer, this error occurs. I have restarted the MySql service instance but stil i get the same error. It didn't happen earlier but happens frequently in recent times. All the web applications deployed on the server uses Ibatis and

How do I use DB2 Explain?

时光总嘲笑我的痴心妄想 提交于 2019-11-28 06:50:39
How do I use DB2's Explain function? -- both to run it, and to use it to optimize queries. Is there a better tool available for DB2? I've built queries before, but the only way I've had to tell how long they'd take is to run them and time them -- which is hardly ideal. Edit: The answer for me turned out to be "You can't. You don't have and cannot get the access." Don't you love bureaucracy? What you're looking for is covered by two DB2 utilities: The explain utility , which shows the optimizer's access plan and estimated cost for a specific query (based on current RUNSTATS statistics) The

What is the best way to implement a substring search in SQL?

主宰稳场 提交于 2019-11-28 06:37:55
We have a simple SQL problem here. In a varchar column, we wanted to search for a string anywhere in the field. What is the best way to implement this for performance? Obviously an index is not going to help here, any other tricks? We are using MySQL and have about 3 million records. We need to execute many of these queries per second so really trying to implement these with the best performance. The most simple way to do this is so far is: Select * from table where column like '%search%' I should further specify that the column is actually a long string like "sadfasdfwerwe" and I have to

How can I further optimize a derived table query which performs better than the JOINed equivalent?

核能气质少年 提交于 2019-11-28 05:55:23
UPDATE: I found a solution. See my Answer below. My Question How can I optimize this query to minimize my downtime? I need to update over 50 schemas with the number of tickets ranging from 100,000 to 2 million. Is it advisable to attempt to set all fields in tickets_extra at the same time? I feel that there is a solution here that I'm just not seeing. Ive been banging my head against this problem for over a day. Also, I initially tried without using a sub SELECT, but the performance was much worse than what I currently have. Background I'm trying to optimize my database for a report that needs

Mysql count performance on very big tables

自古美人都是妖i 提交于 2019-11-28 05:17:20
I have a table with more than 100 millions rows in Innodb. I have to know if there is more than 5000 rows where the foreign key = 1. I don't need the exact number. I made some testing : SELECT COUNT(*) FROM table WHERE fk = 1 => 16 seconds SELECT COUNT(*) FROM table WHERE fk = 1 LIMIT 5000 => 16 seconds SELECT primary FROM table WHERE fk = 1 => 0.6 seconds I will have a bigger network and treatment time but it can be an overload of 15.4 seconds ! Do you have a better idea ? Thanks Edit: [Added OP's relevant comments] I tried SELECT SQL_NO_CACHE COUNT(fk) FROM table WHERE fk = 1 but it took 25