query-optimization

Query cache efficiency

耗尽温柔 提交于 2019-12-04 08:37:30
问题 I'm using MySQLTuner.pl to optimize my site.... though I'm not entirely sure how to resolve some of these issues and am wondering if someone can help me out. I'm running 16GB of RAM with the following MySQL settings: key_buffer = 1024M max_allowed_packet = 16M thread_stack = 192K thread_cache_size = 8 myisam-recover = BACKUP max_connections = 1500 table_cache = 256 thread_concurrency = 4 query_cache_limit = 2M query_cache_size = 32M query_cache_type = 1 tmp_table_size = 512M max_heap_table

EF Code First improving performance for self referencing, one to many relationships

浪子不回头ぞ 提交于 2019-12-04 08:17:31
I have an AccountGroup which is a self-referencing entity. A leaf AccountGroup can contain 1 or more Accounts . Both entities have Balance property. Each AccountGroup has a Balance which is either a sum of Balance s in sub-groups or sum of Balance s of all Accounts (in case of leaf group). In order to build a tree listing of all AccountGroup s and Account s I have to traverse this object graph recursively, which causes a lot (I mean a lot!!!) of calls to DB... Is there any way to improve upon this in such way that # of DB calls is reduced? Thanks Here is the trimmed down code Account (belongs

Which is the best choice in delete-insert vs if-update else-insert?

泪湿孤枕 提交于 2019-12-04 06:06:02
Update : My bad...I have an primary key on those tables..I meant no further indexing currently on the tables. We might have it in the future after seeing the performance and since we have too many filters on the data in retrieving data it did not show much improvement on indexing last time we ran database tuning. I have a 4 huge tables over millions of records. Now there is stored procedure which is called frequently and updates these table. Here is the scenario - Now if entry exists for today I need to update it for today and else if entry is not there for the user I need to go ahead and

MySQL explain filtered column jumping 4,100 with index

混江龙づ霸主 提交于 2019-12-04 06:04:42
My Query: EXPLAIN EXTENDED SELECT `artwork`.`id` , `artwork`.`added` FROM `artwork` ORDER BY `artwork`.`added` DESC LIMIT 0 , 6 When I added an index on "added" to avoid using filesort and use index instead the output of explained went from id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE artwork ALL NULL NULL NULL NULL 302 100.00 Using filesort to id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE artwork index NULL added 4 NULL 6 5033.33 and I'm concerned about the filtered going up approximently 4,100 - I can't find on

Very slow subqueries when using “NOT IN”

混江龙づ霸主 提交于 2019-12-04 05:04:16
I'm working on generating reports for data contained within a large pre-existing Access database (~500 mb after compact & repair), and I'm having trouble with a slow subquery. The database has a big table which contains a record of every customer purchase. Here's a simple query which finds customers who have bought a blue widget. It completes within a few seconds and returns about ten thousand records. SELECT DISTINCT CustomerId FROM ProductSales WHERE Product = 'BLUE' Here's a query which tries to find customers who have bought a blue widget, but not a red widget. It takes about an hour to

MySQL indexes - what are the best practices according to this table and queries

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 03:06:17
i have this table (500,000 row) CREATE TABLE IF NOT EXISTS `listings` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `type` tinyint(1) NOT NULL DEFAULT '1', `hash` char(32) NOT NULL, `source_id` int(10) unsigned NOT NULL, `link` varchar(255) NOT NULL, `short_link` varchar(255) NOT NULL, `cat_id` mediumint(5) NOT NULL, `title` mediumtext NOT NULL, `description` mediumtext, `content` mediumtext, `images` mediumtext, `videos` mediumtext, `views` int(10) unsigned NOT NULL, `comments` int(11) DEFAULT '0', `comments_update` int(11) NOT NULL DEFAULT '0', `editor_id` int(11) NOT NULL DEFAULT '0',

Does the order of columns in a query matter?

狂风中的少年 提交于 2019-12-04 02:54:06
When selecting columns from a MySQL table, is performance affected by the order that you select the columns as compared to their order in the table (not considering indexes that may cover the columns)? For example, you have a table with rows uid, name, bday, and you have the following query. SELECT uid, name, bday FROM table Does MySQL see the following query any differently and thus cause any sort of performance hit? SELECT uid, bday, name FROM table The order doesn't matter, actually, so you are free to order them however you'd like. edit: I guess a bit more background is helpful: As far as

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

谁都会走 提交于 2019-12-04 01:42:26
问题 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... 回答1: Use the SQL Server Management Studio, and

Foreign key optimization in SQLite

旧街凉风 提交于 2019-12-04 00:22:56
I know that SQLite does not enforce foreign keys natively, but that's not my primary concern. The question is: If I declare CREATE TABLE invoice ( invoiceID INTEGER PRIMARY KEY, clientID INTEGER REFERENCES client(clientID), ... ) will sqlite at least use the information that clientID is a foreign key to optimize queries and automatically index invoice.clientID, or is this constraint a real no-op? Even if it is not actually a no-op (a data structure describing the constraint is added to the table), foreign key related statement doesn't create any index on involved columns. Indexes are

SQL Query For Total Points Within Radius of a Location

▼魔方 西西 提交于 2019-12-03 21:27:51
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,latitude,longitude from zipcodes group by city,state order by state,city; I can get the number of