query-optimization

Multithreading in MySQL?

橙三吉。 提交于 2019-12-22 06:34:51
问题 Are MySQL operations multithreaded? Specifically, on running a select, does the select (or join) algorithm spawn multiple threads to run together? Would being multi-threaded prevent being able to support a lot of concurrent users? 回答1: Several background threads run in a MySQL server. Also, each database connection is served by a single thread. Parallel queries (selects using multiple threads) are not implemented in MySQL. MySQL as is can support "a lot of concurrent useres". For example

Is it a slow query? Can it be improved?

守給你的承諾、 提交于 2019-12-22 05:57:54
问题 I was going through SQLZOO "SELECT within SELECT tutorial" and here's one of the queries that did the job (task 7 ) world(name, continent, area, population, gdp) SELECT w1.name, w1.continent, w1.population FROM world w1 WHERE 25000000 >= ALL(SELECT w2.population FROM world w2 WHERE w2.continent=w1.continent) My questions are about effectiveness of such query. The sub-query will run for each row (country) of the main query and thus repeatedly re-populating the ALL list for a given continent.

How to optimize SQL query with window functions

自闭症网瘾萝莉.ら 提交于 2019-12-22 05:17:12
问题 This question is related to this one. I have table which contains power values for devices and I need to calculate power consumption for given time span and return 10 most power consuming devices. I have generated 192 devices and 7742208 measurement records (40324 for each). This is roughly how much records devices would produce in one month. For this amount of data my current query takes over 40s to execute which is too much because time span and amount of devices and measurements could be

What is an automatic covering index?

醉酒当歌 提交于 2019-12-22 04:26:12
问题 When using EXPLAIN QUERY PLAN in SQLite 3 it sometimes gives me output such as SEARCH TABLE staff AS s USING AUTOMATIC COVERING INDEX (is_freelancer=? AND sap=?) (~6 rows) Where does the index come from and what does it do? The table has no manually created indices on it. 回答1: "Automatic" means that SQLite creates a temporary index that is used only for this query, and deleted afterwards. This happens when the cost of creating the index is estimated to be smaller than the cost of looking up

How can i force sql server to execute subquery first and filter the 'where' statement

筅森魡賤 提交于 2019-12-22 04:08:51
问题 i have a query like this: select * from ( select * from TableX where col1 % 2 = 0 ) subquery where col1 % 4 = 0 The actual subquery is more complicated. when i execute the subquery alone it returns maybe 200rows quickly, but when i execute the whole query, it takes too long to wait. I know sql server takes some optimization here and merge the where statement into the subquery, and produce the new execution plan which is not that efficient. Althought i can dive into the execution plan and

Is storing counts of database record redundant?

坚强是说给别人听的谎言 提交于 2019-12-21 11:21:13
问题 I'm using Rails and MySQL, and have an efficiency question based on row counting. I have a Project model that has_many :donations . I want to count the number of unique donors for a project. Is having a field in the projects table called num_donors , and incrementing it when a new donor is created a good idea? Or is something like @num_donors = Donor.count(:select => 'DISTINCT user_id') going to be similar or the same in terms of efficiency thanks to database optimization? Will this require

MySQL EXPLAIN UPDATE

落花浮王杯 提交于 2019-12-21 06:58:11
问题 I am trying to answer the following question as part of my college revision: Create an index on at least one attribute of a table in the ‘employees’ database, where you use the MySQL ‘EXPLAIN’ tool to clearly show the benefit (in terms or retreival) and the negative (in terms of update) of the creation of the index in question. For the first part I have created an index on the employees table and used the following query before and after the index to prove it's beneficial from a retrieval

Best way to update user rankings without killing the server

江枫思渺然 提交于 2019-12-21 06:08:13
问题 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

Best way to update user rankings without killing the server

戏子无情 提交于 2019-12-21 06:07:19
问题 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

Optimize escape JSON in PostgreSQL 9.0

懵懂的女人 提交于 2019-12-21 05:07:11
问题 I'm currently using this JSON escaping function in PostgreSQL as a stand in for future native JSON support. While it works, it's also limiting our systems performance. How can I go about optimizing it? Maybe some kind of lookup array? CREATE OR REPLACE FUNCTION escape_json(i_text TEXT) RETURNS TEXT AS $body$ DECLARE idx INTEGER; text_len INTEGER; cur_char_unicode INTEGER; rtn_value TEXT := i_text; BEGIN -- $Rev: $ -- text_len = LENGTH(rtn_value); idx = 1; WHILE (idx <= text_len) LOOP cur_char