query-optimization

Expensive full table scan on select all without condition

大憨熊 提交于 2019-12-11 17:00:19
问题 I have a wide table with 210 columns (This might be a bad structure but all data is needed every time). There is a primary type index for the primary key. Now when I do select * from my single table without any condition. It results in a full table scan. It says the following: no useable indexes were found for the table This also means the search range is so broad that the index is useless. What could I do to avoid this full table scan? Note: I need all the information every time so breaking

Optimizing query that looks at a specific time window each day

*爱你&永不变心* 提交于 2019-12-11 15:55:46
问题 This is a followup to my previous question Optimizing query to get entire row where one field is the maximum for a group I'll change the names from what I used there to make them a little more memorable, but these don't represent my actual use-case (so don't estimate the number of records from them). I have a table with a schema like this: OrderTime DATETIME(6), Customer VARCHAR(50), DrinkPrice DECIMAL, Bartender VARCHAR(50), TimeToPrepareDrink TIME(6), ... I'd like to extract the rows from

optimizing a query using union left joins and inner joins

…衆ロ難τιáo~ 提交于 2019-12-11 15:16:13
问题 I have a query that I want to optimize. Both unions executed separatley run fine, however as soon as I include inner join it takes up to 57 seconds. How do I solve this. My query is as follows SELECT p.PROJID, p.StartDate, o.ORDERNO, p.PROJCODE, p.PROJECT, cat.type AS CATEGORY, p.AREA, p.STATE, p.COUNTRY, p.VALUE, p.PROCESSOR, p.PROJINFO, p.NES, p.SPECSALE, p.OFFICE, p.DEPTCODE, p.INTERNLCHG, p.INTERCOCHG, p.LORM, p.PERCENT, d.COMPANY, CONCAT( d.LASTNAME, ", ", d.FIRSTNAME ) AS Contact FROM (

Optimize a query that group results by a field from the joined table

孤人 提交于 2019-12-11 14:51:08
问题 I've got a very simple query that have to group the results by the field from the joined table: SELECT SQL_NO_CACHE p.name, COUNT(1) FROM ycs_sales s INNER JOIN ycs_products p ON s.id = p.sales_id WHERE s.dtm BETWEEN '2018-02-16 00:00:00' AND '2018-02-22 23:59:59' GROUP BY p.name Table ycs_products is actually sales_products, lists products in each sale. I want to see the share of each product sold over a period of time. The current query speed is 2 seconds which is too much for the user

SQL Statement Performance Issue on Informix

主宰稳场 提交于 2019-12-11 11:59:38
问题 I have this Informix SQL statement which takes ages to run. Does anybody see any way to optimize it so it wouldn't take so long? SELECT * FROM OriginalTable WHERE type = 'S' AND flag <> 'S' INTO TEMP TempTableA; SELECT * FROM OriginalTable WHERE type = 'Z' AND flag <> 'S' INTO TEMP TempTableB; UPDATE OriginalTable SET flag = 'D' WHERE Serialnumber in ( select Serialnumber from TempTableA WHERE NOT EXISTS(SELECT * FROM TempTableB WHERE TempTableB.Col1 = TempTableA.Col1 AND TempTableB.Col2 =

Is cursor.skip() on indexed keys always faster?

别等时光非礼了梦想. 提交于 2019-12-11 11:30:19
问题 I have 2 databases: slow and fast ; each of which was fed with 4096 entries. The age key is a unique random integer that was generated with this script: var arr = [] while(arr.length < 4096){ var randmnum=Math.ceil(Math.random()*1000000) var found=false; for(var i=0;i<arr.length;i++){ if(arr[i]==randmnum){found=true;break} } if(!found)arr[arr.length]=randmnum; } var i=0; for (i=0 ; i< arr.length; ++i) { db.fast.insert({name:"john doe", email:"once@upon.a.time.com", age:arr[i]}); db.slow

The last UNION in SQL ignores existing INDEX

旧城冷巷雨未停 提交于 2019-12-11 11:24:15
问题 This is a refined problem I have been struggling with for a couple of days now. I have a static table that I create and build indexes on which I then create a stored procedure to run against. My issue is bizarre and I will do my best to explain it. I run the same scripts to create and execute across 194 databases...the vast majority of which run very quickly...however on a handful of databases they run exceptionally slow. Just so we are clear here are the INDEX: CREATE UNIQUE CLUSTERED INDEX

How to refer 'decider' in the where clause from the following mysql query?

陌路散爱 提交于 2019-12-11 10:58:58
问题 How to refer 'decider' in the where clause from the following mysql query? SELECT *, CASE WHEN (cond1) THEN 1 WHEN (cond2) THEN 2 END as decider FROM t1, t2 WHERE cond12 AND decider <> NULL I tried it, and I got a 1054: Unknown column in where clause error. 回答1: Use: SELECT *, CASE WHEN (cond1) THEN 1 WHEN (cond2) THEN 2 ELSE NULL END as decider FROM t1, t2 WHERE cond12 HAVING decider IS NOT NULL The earliest MySQL allows you to use column aliases is the GROUP BY clause You need to use IS

Optimized querying in PostgreSQL

别来无恙 提交于 2019-12-11 10:29:21
问题 Assume you have a table named tracker with following records. issue_id | ingest_date | verb,status 10 2015-01-24 00:00:00 1,1 10 2015-01-25 00:00:00 2,2 10 2015-01-26 00:00:00 2,3 10 2015-01-27 00:00:00 3,4 11 2015-01-10 00:00:00 1,3 11 2015-01-11 00:00:00 2,4 I need the following results 10 2015-01-26 00:00:00 2,3 11 2015-01-11 00:00:00 2,4 I am trying out this query select * from etl_change_fact where ingest_date = (select max(ingest_date) from etl_change_fact); However, this gives me only

Range queries on 2 columns

核能气质少年 提交于 2019-12-11 10:23:14
问题 I have very huge table Shelve(approximately 100 millions) which has Shelve info for books. Shelve ShevleID RangeStart RangeEnd ---------------------------------------- 1 1 100 2 200 500 3 501 1000 Each book has unique number BookID given to it. Lets say you have a book with BookID 50. Then Book must be kept in Shelve 1 because 50 lies between 1 and 100. Books BookID BookName --------------------------- 1 Book1 2 Book2 . . 50 Book3 My queries are like this- SELECT BookID, BookName, ShelveID