query-optimization

Why is SQLite refusing to use available indexes when adding a JOIN?

我的梦境 提交于 2019-12-10 14:47:16
问题 This is related to Why is SQLite refusing to use available indexes? The queries to create the database is: CREATE TABLE foo(id TEXT); CREATE INDEX `foo.index` ON foo(id); CREATE TABLE bar(id TEXT); CREATE INDEX `bar.index` ON bar(id); CREATE VIEW baz AS SELECT id FROM foo UNION ALL SELECT id FROM bar; CREATE TABLE bam(id TEXT, value TEXT); INSERT INTO foo VALUES('123'); INSERT INTO foo VALUES('1123'); INSERT INTO foo VALUES('2123'); INSERT INTO foo VALUES('3123'); INSERT INTO bar VALUES(

optimizing Query with datediff() in mysql

依然范特西╮ 提交于 2019-12-10 12:08:30
问题 I have a Query like below select id,name,baseid,member_card_type,membercard_num,last_draw,counter from details_dest where datediff(curdate(),basedate)<100; i have used the explain on that and found it is using index which is on basedate and i think date_diff is the problem so please suggest me is there any other way to execute it without any functions and kindly tell me which is better datediff() or to_days() in according to performance i am using mysql 5.5 回答1: I would suggest the following

No execution plan caching for dynamic SQL in PostgreSQL 9.4?

依然范特西╮ 提交于 2019-12-10 11:49:15
问题 This is just a prospective question, at work we're thinking of moving from SQL Server to PostgreSQL, please tell me I didn't understand this correctly from the PostgreSQL 9.4 documentation: "There is no plan caching for commands executed via EXECUTE". We have a critical SP that builds a dynamic query and executes it, initially I didn't build the dynamic SQL correctly (the dynamic query was not parameterized) and because of that each time when this SP was hit, it spend ~ 1500ms to recompile

SQL Server Profiler: How to inspect/understand the duration for the Audit Logout event in more detail?

橙三吉。 提交于 2019-12-10 11:36:21
问题 I am profiling some MS SQL queries with the SQL Server Profiler for my C# Application that I develop with Visual Studio and IIS Express: The duration that is given for the event "Audit Logout" (16876 ms) is the total time between login and logout. The duration for the query is only 60 ms. Login/Logout events are related to the setting up / tearing down. From What is "Audit Logout" in SQL Server Profiler? I would like to understand the time difference of 16816 ms (= 16876 ms - 60ms) in more

Why does Grails issue SELECT statements on instance save()?

梦想与她 提交于 2019-12-10 11:15:15
问题 Each time I save() a new domain object in Grails I see Hibernate issuing Select statements for each of the unique constraints in my Grails domain class. If I save without validation, I don't see the Select statements. Example: new Person(name: 'Foo').save(validate: false) Is there a way to stop these extra Select statements from occurring while still having validation enabled? One of my goals is to decrease appserver/database chattiness since I am expecting my Grails app to run on a high

Mysql slow query: JOIN + multiple WHERES + ORDER BY

二次信任 提交于 2019-12-10 03:54:06
问题 long time lurker, first question! I am struggling to optimize this query, which selects the lowest priced items that match the chosen filters: SELECT product_info.*, MIN(product_all.sale_price) as sale_price, product_all.buy_link FROM product_info NATURAL JOIN (SELECT * FROM product_all WHERE product_all.date = '2010-09-30') as product_all WHERE (product_info.category = 2 AND product_info.gender = 'W' ) GROUP BY product_all.prod_id ORDER BY MIN(product_all.sale_price) ASC LIMIT 13 Its explain

How to throttle or prioritize a query in MySql

我只是一个虾纸丫 提交于 2019-12-10 03:39:33
问题 Is there anyway to prioritize or throttle a query at all in MySQL? I'm a DBA on a server that sees a lot of unoptimized queries come into the server and they just destroy the CPU. I'm looking at throttling certain users that hit on the database in poor fashion. Clarification: I realize that MySQL has facilities built in to limit number of queries, connections, etc. But those aren't really the issue, it's that once in a blue moon a user will send an unoptimized query, and I'd need to time it

RethinkDB - Find documents with missing field

帅比萌擦擦* 提交于 2019-12-10 02:44:55
问题 I'm trying to write the most optimal query to find all of the documents that do not have a specific field. Is there any better way to do this than the examples I have listed below? // Get the ids of all documents missing "location" r.db("mydb").table("mytable").filter({location: null},{default: true}).pluck("id") // Get a count of all documents missing "location" r.db("mydb").table("mytable").filter({location: null},{default: true}).count() Right now, these queries take about 300-400ms on a

SQL ROW_NUMBER() over performance problem

折月煮酒 提交于 2019-12-09 22:51:49
问题 I have this SQL that works fine. Want the my filter to return the LATEST unique SessionGuids with the highest UserSessionSequenceID. Problem is performance sucks - even though I have good indexes. How can I rewrite this - to omit the ROW_NUMBER line? SELECT TOP(@resultCount) * FROM ( SELECT [UserSessionSequenceID] ,[SessionGuid] ,[IP] ,[Url] ,[UrlTitle] ,[SiteID] ,[BrowserWidth] ,[BrowserHeight] ,[Browser] ,[BrowserVersion] ,[Referer] ,[Timestamp] ,ROW_NUMBER() over (PARTITION BY [SessionGuid

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

丶灬走出姿态 提交于 2019-12-09 16:06:06
问题 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)