query-optimization

SQL Query For Total Points Within Radius of a Location

大城市里の小女人 提交于 2019-12-09 14:03:59
问题 I have a database table of all zipcodes in the US that includes city,state,latitude & longitude for each zipcode. I also have a database table of points that each have a latitude & longitude associated with them. I'd like to be able to use 1 MySQL query to provide me with a list of all unique city/state combinations from the zipcodes table with the total number of points within a given radius of that city/state. I can get the unique city/state list using the following query: select city,state

MySQL fetch time optimization

烂漫一生 提交于 2019-12-09 12:28:18
问题 oI have a table with 2 millions of registers, but it will grow much more soon. Basically this table contains points of interest of an image with respective descriptors. When I'm trying to execute query that selects points that are spatially near to the query points, total execution time takes too long. More precisely Duration / Fetch = 0.484 sec / 27.441 sec. And the query is quite simple, which returns only ~17000 rows. My query is: SELECT fp.fingerprint_id, fp.coord_x, fp.coord_y, fp.angle,

Mysql query with Left Join is too very slow

夙愿已清 提交于 2019-12-09 10:08:48
问题 Query: select `r`.`id` as `id` from `tbl_rls` as `r` left join `tblc_comment_manager` as `cm` on `cm`.`rlsc_id` != `r`.`id` Both tables have 8k records but why is it very slow, taking 2-3 minutes and more sometimes? OMG , this query makes mysql server down. Will get back to you peoples in a second :( All peoples those suggested Indexing the columns are all Correct. Yeh the query i wrote was silly and buggy. Thanks correcting me. 回答1: Consider also indexing your tables. We're running multiple

How to make JOIN query use index?

蹲街弑〆低调 提交于 2019-12-09 05:09:18
问题 I have two tables: CREATE TABLE `articles` ( `id` int(11) NOT NULL AUTO_INCREMENT, `title` varchar(1000) DEFAULT NULL, `last_updated` datetime DEFAULT NULL, PRIMARY KEY (`id`), KEY `last_updated` (`last_updated`), ) ENGINE=InnoDB AUTO_INCREMENT=799681 DEFAULT CHARSET=utf8 CREATE TABLE `article_categories` ( `article_id` int(11) NOT NULL DEFAULT '0', `category_id` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`article_id`,`category_id`), KEY `category_id` (`category_id`) ) ENGINE=InnoDB DEFAULT

Optimizing Oracle CONNECT BY when used with WHERE clause

匆匆过客 提交于 2019-12-09 04:13:18
问题 Oracle START WITH ... CONNECT BY clause is applied before applying WHERE condition in the same query. Thus, WHERE constraints won't help optimize CONNECT BY . For example, the following query will likely perform full table scan (ignoring selectivity on dept_id ): SELECT * FROM employees WHERE dept_id = 'SALE' START WITH manager_id is null CONNECT BY PRIOR employee_id = manager_id I tried to improve performance in 2 ways: query A: SELECT * FROM employees START WITH manager_id is null AND dept

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

萝らか妹 提交于 2019-12-09 03:23:44
问题 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? 回答1: 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

MySQL select maximum length of matching string

余生长醉 提交于 2019-12-09 01:20:05
问题 I need to return all the text results(s), if any, that share the maximum length left bounded substring common to the search string. Given a search for "StackOverflow" in a table column containing "Stack", "Sta", "StackOv", "StackOverthrow", "StackOverSlow", "StackFlow", "Soverflow", "StackOverCrow", "StackOverSlow", etc. the query would return "StackOverthrow" as it contains the greatest number of matching characters, as well as StackOverSlow and StackOverCrow in a unique result set.

Count from a table, but stop counting at a certain number

我的未来我决定 提交于 2019-12-08 21:13:08
问题 Is there a way in MySQL to COUNT(*) from a table where if the number is greater than x , it will stop counting there? Basically, I only want to know if the number of records returned from a query is more or less than a particular number. If it's more than that number, I don't really care how many rows there are, if it's less, tell me the count. I've been able to fudge it like this: -- let x be 100 SELECT COUNT(*) FROM ( SELECT `id` FROM `myTable` WHERE myCriteria = 1 LIMIT 100 ) AS temp ..

Optimize Postgres deletion of orphaned records

让人想犯罪 __ 提交于 2019-12-08 17:26:19
问题 Take the following two tables: Table "public.contacts" Column | Type | Modifiers | Storage | Stats target | Description --------------------+-----------------------------+-------------------------------------------------------+----------+--------------+------------- id | integer | not null default nextval('contacts_id_seq'::regclass) | plain | | created_at | timestamp without time zone | not null | plain | | updated_at | timestamp without time zone | not null | plain | | external_id | integer

Optimizing MySQL query for integer range search

扶醉桌前 提交于 2019-12-08 12:18:12
问题 I have over 1.7 million records in a table which contains ip address range(begin and end) both primary key and corresponding details. The Table structure is mysql> desc csv; +---------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------+-------------+------+-----+---------+-------+ | begin | bigint(20) | NO | PRI | 0 | | | end | bigint(20) | NO | PRI | 0 | | | code | char(2) | YES | | NULL | | | country | varchar(50) | YES | | NULL | | |