query-optimization

How to optimize SQL query with calculating distance by longitude and latitude?

青春壹個敷衍的年華 提交于 2019-12-03 21:27:31
问题 I have a table with structure like that: table name: shop id_shop int(10) name varchar(200) latitude double longitude double And I'd like to calculate distance between given coordinates and coordinates saved in database. My current query: SELECT * FROM `shop` AS `s` WHERE ( ( 6371 * ACOS( SIN( RADIANS( latitude ) ) * SIN( RADIANS( 53.5353010379 ) ) + COS( RADIANS( latitude ) ) * COS( RADIANS( 53.5353010379 ) ) * COS( RADIANS( 14.7984442616 ) - RADIANS( longitude ) ) ) ) <= 25 ) plus some JOIN

Select query with three where conditions is slow, but the same query with any combination of two of the three where conditions is fast

时光毁灭记忆、已成空白 提交于 2019-12-03 20:21:12
问题 I have the following query: SELECT table_1.id FROM table_1 LEFT JOIN table_2 ON (table_1.id = table_2.id) WHERE table_1.col_condition_1 = 0 AND table_1.col_condition_2 NOT IN (3, 4) AND (table_2.id is NULL OR table_1.date_col > table_2.date_col) LIMIT 5000; And I have the following keys and indexes: table_1.id primary key. index on table_1.col_condition_1 index on table_1.col_condition_2 composite index on table_1.col_condition_1 and table_1.col_condition_2 The correct indexes are getting

Best way to update user rankings without killing the server

半世苍凉 提交于 2019-12-03 19:34:45
I have a website that has user ranking as a central part, but the user count has grown to over 50,000 and it is putting a strain on the server to loop through all of those to update the rank every 5 minutes. Is there a better method that can be used to easily update the ranks at least every 5 minutes? It doesn't have to be with php, it could be something that is run like a perl script or something if something like that would be able to do the job better (though I'm not sure why that would be, just leaving my options open here). This is what I currently do to update ranks: $get_users = mysql

Very big data in mysql table. Even select statements take much time

梦想与她 提交于 2019-12-03 17:25:26
I am working on a database and its a pretty big one with 1.3 billion rows and around 35 columns. Here is what i get after checking the status of the table: Name:Table Name Engine:InnoDB Version:10 Row_format:Compact Rows:12853961 Avg_row_length:572 Data_length:7353663488 Max_data_length:0 Index_length:5877268480 Data_free:0 Auto_increment:12933138 Create_time:41271.0312615741 Update_time:NULL Check_time:NULL Collation:utf8_general_ci Checksum:NULL Create_options: Comment:InnoDB free: 11489280 kB The Problem I am facing that even a single select query takes too much time to process for example

Query optimization and API throttling

▼魔方 西西 提交于 2019-12-03 14:37:51
问题 We are tracking Facebook Page and Post metrics for a number of clients, and we have some questions regarding high CPU intensity and too many calls for Post/comments - according to what is being reported by the developer insights console (Insights -> Developer -> Activity & Errors). The documentation is somewhat unclear on the limits and restrictions for the Graph API, and we'd simply like to make sure we have the correct understanding of what resources we have available. We are working on

MySQL fetch time optimization

时光毁灭记忆、已成空白 提交于 2019-12-03 14:23:40
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, fp.desc1, fp.desc2, fp.desc3, fp.desc4, fp.desc5, fp.desc6, fp.desc7, fp.desc8, fp.desc9, fp.desc10,

SQL: How to select one record per day, assuming that each day contain more than 1 value MySQL

折月煮酒 提交于 2019-12-03 14:04:21
I want to select records from '2013-04-01 00:00:00' to 'today' but, each day has lot of value, because they are saving each 15 minutes a value, so I want only the first or last value from each day. Table schema: CREATE TABLE IF NOT EXISTS `value_magnitudes` ( `id` int(11) NOT NULL AUTO_INCREMENT, `value` float DEFAULT NULL, `magnitude_id` int(11) DEFAULT NULL, `sdi_belongs_id` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `reading_date` datetime DEFAULT NULL, `created_at` datetime DEFAULT NULL, `updated_at` datetime DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8

DB design and optimization considerations for a social application

好久不见. 提交于 2019-12-03 13:46:35
问题 The usual case. I have a simple app that will allow people to upload photos and follow other people. As a result, every user will have something like a "wall" or an "activity feed" where he or she sees the latest photos uploaded from his/her friends (people he or she follows). Most of the functionalities are easy to implement. However, when it comes to this history activity feed, things can easily turn into a mess because of pure performance reasons. I have come to the following dilemma here:

Sum for multiple date ranges in a single call?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-03 12:51:38
I have the following query: SELECT SUM("balance_transactions"."fee") AS sum_id FROM "balance_transactions" JOIN charges ON balance_transactions.source = charges.balance_id WHERE "balance_transactions"."account_id" = 6 AND (balance_transactions.type = 'charge' AND charges.refunded = false AND charges.invoice IS NOT NULL) AND ("balance_transactions"."created" BETWEEN '2013-12-20' AND '2014-01-19'); What that does is adds up all the "fees" that occurred between those two dates. Great. Works fine. The problem is that I almost always need those fees for hundreds of date ranges at a time, which

Getting rid of “Using temporary; Using filesort”

有些话、适合烂在心里 提交于 2019-12-03 12:06:10
When I do an explain on my query I see that it has "Using temporary; Using filesort" under "Extra" for the first row. I understand this is bad but I don't know what exactly it means or how to fix it. If you want to see my query, here's a more general question I asked about the same query: MySQL query optimization and EXPLAIN for a noob . For reference, the query involves 24 tables and 23 joins. My questions now are: What do "Using temporary" and "Using filesort" mean? Assuming they're bad, how do I get rid of them? Galz As said already, "using filesort" and "using temporary" do not always