query-optimization

How do Entity Framework pre-compiled views get loaded

二次信任 提交于 2019-12-23 12:31:06
问题 I've discovered I can increase performance of my application by pre-compiling my views using the EdmGen.exe tool. This is all well and good, but neither me or my colleges can work out how the generated .cs file is actually used by the project. There doesnt seem to be any references to the class that was generated anywhere, so how is it getting included? Can anyone shed any light on this as its really rather frustrating not knowing how it works! EDIT We've acertained that the

When ordering by date desc, “Using temporary” slows down query

依然范特西╮ 提交于 2019-12-23 10:26:33
问题 I have a table for log entries, and a description table for the about 100 possible log codes: CREATE TABLE `log_entries` ( `logentry_id` int(11) NOT NULL AUTO_INCREMENT, `date` datetime NOT NULL, `partner_id` smallint(4) NOT NULL, `log_code` smallint(4) NOT NULL, PRIMARY KEY (`logentry_id`), KEY `IX_code` (`log_code`), KEY `IX_partner_code` (`partner_id`,`log_code`) ) ENGINE=MyISAM ; CREATE TABLE IF NOT EXISTS `log_codes` ( `log_code` smallint(4) NOT NULL DEFAULT '0', `log_desc` varchar(255)

Need SQL optimization (maybe DISTINCT ON is the reason?)

主宰稳场 提交于 2019-12-23 09:57:32
问题 Related, preceding question: Select a random entry from a group after grouping by a value (not column)? My current query looks like this: WITH points AS ( SELECT unnest(array_of_points) AS p ), gtps AS ( SELECT DISTINCT ON(points.p) points.p, m.groundtruth FROM measurement m, points WHERE st_distance(m.groundtruth, points.p) < distance ORDER BY points.p, RANDOM() ) SELECT DISTINCT ON(gtps.p, gtps.groundtruth, m.anchor_id) m.id, m.anchor_id, gtps.groundtruth, gtps.p FROM measurement m, gtps

COUNT and GROUP BY on text fields seems slow

一曲冷凌霜 提交于 2019-12-23 09:32:52
问题 I'm building a MySQL database which contains entries about special substrings of DNA in species of yeast. My table looks like this: +--------------+---------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------------+---------+------+-----+---------+-------+ | species | text | YES | MUL | NULL | | | region | text | YES | MUL | NULL | | | gene | text | YES | MUL | NULL | | | startPos | int(11) | YES | | NULL | | | repeatLength | int(11) | YES | | NULL | | |

SQL Server: IF EXISTS massively slowing down a query

為{幸葍}努か 提交于 2019-12-23 09:27:59
问题 (SQL Server 2012 being used) I found some topics on query optimization, and comparing EXISTS to COUNT, but I couldn't find this exact problem. I have a query that looks something like this: select * from tblAccount as acc join tblUser as user on acc.AccountId = user.AccountId join tblAddress as addr on acc.AccountId = addr.AccountId ... **a few more joins** where acc.AccountId in ( select * accountid from (select accountid, count(*) from tblUser where flag = 1 group by accountId) as tbl where

Would LIMIT 0,1 speed up a SELECT on a Primary Key?

萝らか妹 提交于 2019-12-23 09:06:27
问题 Does anyone know if there is any speed difference (obviously for tables that are sizable enough) between these two queries: SELECT field FROM table WHERE primary_key = "a particular value" or: SELECT field FROM table WHERE primary_key = "a particular value" LIMIT 0,1 I should note that the primary_key field is actually a primary key. Now LIMIT 0,1 does help when a query would otherwise carry on to find other matches. I'm assuming though that when a primary key is involved it should

MySQL WHERE NOT IN extremely slow

◇◆丶佛笑我妖孽 提交于 2019-12-23 07:04:54
问题 Below is a SQL statement inside a stored procedure ( truncated for brevity ): SELECT * FROM item a WHERE a.orderId NOT IN (SELECT orderId FROM table_excluded_item); This statement takes 30 seconds or so! But if I remove the inner SELECT query, it drops to 1s. table_excluded_item is not huge, but I suspect the inner query is being executed more than it needs to be. Is there a more efficient way of doing this? 回答1: use LEFT JOIN SELECT a.* FROM item a LEFT JOIN table_excluded_item b ON a

Oracle execution plan cost vs speed

白昼怎懂夜的黑 提交于 2019-12-23 05:03:54
问题 When building and tuning a query in Oracle, speed is generally the main concern for the developer. However, in tuning a particular query, I recently tried the FIRST_ROWS and NO_CPU_COSTING hints and an execution plan was generated that is 80% faster than the previous plan in execution time, but at a 300% higher cost. There is very little I/O in the execution plan, and it appears that all the additional cost comes from a nested loop outer join between two views. This query is paginated, so I

How to get combined result in MySQL with query optimization?

筅森魡賤 提交于 2019-12-23 04:39:14
问题 I have table like, id | OpenDate | CloseDate ------------------------------------------------ 1 | 2013-01-16 07:30:48 | 2013-01-16 10:49:48 2 | 2013-01-16 08:30:00 | NULL I needed to get combined result as below id | date | type --------------------------------- 1 | 2013-01-16 07:30:48 | Open 1 | 2013-01-16 10:49:48 | Close 2 | 2013-01-16 08:30:00 | Open I used UNION to get above output (can we achieve without UNION?) SELECT id,date,type FROM( SELECT id,`OpenDate` as date, 'Open' as 'type'

Indexing for keyset pagination in mysql

北慕城南 提交于 2019-12-23 04:38:28
问题 I am trying to build an index in mysql to support a keyset pagination query. My query looks like this: SELECT * FROM invoice WHERE company_id = 'someguid' AND id > 'lastguidfromlastpage' ORDER BY id LIMIT 10 Common knowledge on this says an index on company_id would contain the PRIMARY KEY of the table ( id ). Because of this I would expect to be able to use rows directly from the index without any need for the query to sort results first however my explain plan shows a filesort and an index