query-optimization

Searching for a specific ID in a large database?

此生再无相见时 提交于 2019-12-01 13:42:44
I need to look up an ID in a very large database. The ID is: 0167a901-e343-4745-963c-404809b74dd9 The database has hundreds of tables, and millions of rows in the big tables. I can narrow the date to within the last 2 or 3 months, but that's about it. I'm looking for any clues as to how to narrow down searches like this. One thing I'm curious about is whether using LIKE searches helps. i.e does it help to do something like select top 10 * from BIG_TABLE where DESIRED_ID like '016%' Any tips/suggestions are greatly appreciated . The database is being accessed remotely so that's part of the

Linq2Sql: query optimisation

对着背影说爱祢 提交于 2019-12-01 12:44:36
I have the following query: Get list of required team ids from DB: IList<int> teamIds = (from sector in DbContext.sectors where sector.Type=typeValue group sector by sector.TeamId into teamSectors select teamSectors.Key ).ToList(); Using this list fetch all sectors for required teams: IList<InfrStadSector> sectorsForAllTeams = (from sector in DbContext.sectors where teamIds.Contains(sector.TeamId) select sector ).ToList(); Create list of Stadiums based on sectors: IList<InftStadium> stadiums = new List<InfrStadium>(); foreach(int teamId in teamIds) { IList<InfrStadSector> teamSectors =

Linq2Sql: query optimisation

爱⌒轻易说出口 提交于 2019-12-01 10:26:30
问题 I have the following query: Get list of required team ids from DB: IList<int> teamIds = (from sector in DbContext.sectors where sector.Type=typeValue group sector by sector.TeamId into teamSectors select teamSectors.Key ).ToList(); Using this list fetch all sectors for required teams: IList<InfrStadSector> sectorsForAllTeams = (from sector in DbContext.sectors where teamIds.Contains(sector.TeamId) select sector ).ToList(); Create list of Stadiums based on sectors: IList<InftStadium> stadiums

How to Detect Select n+1 problems in Linq to SQL?

家住魔仙堡 提交于 2019-12-01 08:34:48
What is the best way to detect Select n+1 problems if i am using linq to SQL, right now we are working on a project and it seem to be pretty slow to display some lists. What is the best method to detect this? Maybe this will help: http://ayende.com/Blog/archive/2009/11/13/linq-to-sql-profiler-is-now-on-public-beta.aspx http://weblogs.asp.net/scottgu/archive/2007/07/31/linq-to-sql-debug-visualizer.aspx http://visualstudiogallery.msdn.microsoft.com/ru-ru/d5a64d5a-174a-4357-ad84-dbeeec030f23 Or you can use SQL Profiler and just check if queries are executed when you access individual list items.

JOINS, EXISTS or IN which is better? Few questions on SQL

谁说我不能喝 提交于 2019-12-01 08:31:41
I have few questions on SQL.. How to analyze the performance of a query? Any software, inbuilt features of MSSQL server 2005/2008? What should be used in place of in in queries so that the performance is better? Eg: SELECT * FROM enquiry_courses WHERE enquiry_id IN ( SELECT enquiry_id FROM enquiries WHERE session_id = '4cd3420a16dbd61c6af58f6199ac00f1' ) Which is better: JOINS , EXISTS or IN in terms of performance? Comments/Help appreciated... Use the SQL Server Management Studio, and include Actual Execution Plan and SET STATISTICS TIME and SET STATISTICS IO . This in corresponds to a JOIN ,

MySQL optimization on join tables with range criteria

微笑、不失礼 提交于 2019-12-01 08:19:10
I am going to join two tables by using a single position in one table to the range (represented by two columns) in another table. However, the performance is too slow, which is about 20 mins. I have tried adding the index on the table or changing the query. But the performance is still poor. So, I am asking for optimization of the joining speed. The following is the query to MySQL. mysql> SELECT `inVar`.chrom, `inVar`.pos, `openChrom_K562`.score -> FROM `inVar` -> LEFT JOIN `openChrom_K562` -> ON ( -> `inVar`.chrom=`openChrom_K562`.chrom AND -> `inVar`.pos BETWEEN `openChrom_K562`.chromStart

How to efficiently determine changes between rows using SQL

隐身守侯 提交于 2019-12-01 05:59:04
I have a very large MySQL table containing data read from a number of sensors. Essentially, there's a time stamp and a value column. I'll omit the sensor id, indexes other details here: CREATE TABLE `data` ( `time` datetime NOT NULL, `value` float NOT NULL ) The value column rarely changes, and I need to find the points in time when those changes occur. Suppose there's a value every minute, the following query returns exactly what I need: SELECT d.*, (SELECT value FROM data WHERE time<d.time ORDER by time DESC limit 1) AS previous_value FROM data d HAVING d.value<>previous_value OR previous

How to return rows listed in descending order of COUNT(*)?

杀马特。学长 韩版系。学妹 提交于 2019-12-01 04:18:26
I have a table called foo with these fields: - id - type - parentId I want to select a list of parent IDS, in the descending order of their COUNT(*) of how many times they appear in the table. Something like this: SELECT DISTINCT parentId FROM `foo` ORDER BY (COUNT(parentId) DESC where parentId = parentId) How can this be done in the most efficient way and putting the least load on the server? There can be thousands-hundreds of thousands of records in the table, so manually going through each record is not acceptable.. Simply by applying a GROUP BY clause, and assuming you have an index ,

How to force nolock hint for sql server logins

ぃ、小莉子 提交于 2019-12-01 04:08:57
Does anyone know of a way to force a nolock hint on all transactions issued by a certain user? I'd like to provide a login for a support team to query the production system, but I want to protect it by forcing a nolock on everything they do. I'm using SQL Server 2005. This is a painful and hacky way to do it, but it's what we're doing where I work. We're also using classic asp so we're using inline sql calls. we actually wrap the sql call in a function (here you can check for a specific user) and add "SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED" to the beginning of the call. I believe

How to efficiently determine changes between rows using SQL

☆樱花仙子☆ 提交于 2019-12-01 03:45:14
问题 I have a very large MySQL table containing data read from a number of sensors. Essentially, there's a time stamp and a value column. I'll omit the sensor id, indexes other details here: CREATE TABLE `data` ( `time` datetime NOT NULL, `value` float NOT NULL ) The value column rarely changes, and I need to find the points in time when those changes occur. Suppose there's a value every minute, the following query returns exactly what I need: SELECT d.*, (SELECT value FROM data WHERE time<d.time