query-optimization

MySQL Join clause vs WHERE clause

坚强是说给别人听的谎言 提交于 2019-12-29 05:07:04
问题 What's the difference in a clause done the two following ways? SELECT * FROM table1 INNER JOIN table2 ON ( table2.col1 = table1.col2 AND table2.member_id = 4 ) I've compared them both with basic queries and EXPLAIN EXTENDED and don't see a difference. I'm wondering if someone here has discovered a difference in a more complex/processing intensive envornment. SELECT * FROM table1 INNER JOIN table2 ON ( table2.col1 = table1.col2 ) WHERE table2.member_id = 4 回答1: With an INNER join the two

Higher cardinality column first in an index when involving a range?

ⅰ亾dé卋堺 提交于 2019-12-28 18:14:26
问题 CREATE TABLE `files` ( `did` int(10) unsigned NOT NULL DEFAULT '0', `filename` varbinary(200) NOT NULL, `ext` varbinary(5) DEFAULT NULL, `fsize` double DEFAULT NULL, `filetime` datetime DEFAULT NULL, PRIMARY KEY (`did`,`filename`), KEY `fe` (`filetime`,`ext`), -- This? KEY `ef` (`ext`,`filetime`) -- or This? ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ; There are a million rows in the table. The filetimes are mostly distinct. There are a finite number of ext values. So, filetime has a high

Higher cardinality column first in an index when involving a range?

北慕城南 提交于 2019-12-28 18:13:43
问题 CREATE TABLE `files` ( `did` int(10) unsigned NOT NULL DEFAULT '0', `filename` varbinary(200) NOT NULL, `ext` varbinary(5) DEFAULT NULL, `fsize` double DEFAULT NULL, `filetime` datetime DEFAULT NULL, PRIMARY KEY (`did`,`filename`), KEY `fe` (`filetime`,`ext`), -- This? KEY `ef` (`ext`,`filetime`) -- or This? ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ; There are a million rows in the table. The filetimes are mostly distinct. There are a finite number of ext values. So, filetime has a high

Subquery v/s inner join in sql server

杀马特。学长 韩版系。学妹 提交于 2019-12-28 02:03:05
问题 I have following queries First one using inner join SELECT item_ID,item_Code,item_Name FROM [Pharmacy].[tblitemHdr] I INNER JOIN EMR.tblFavourites F ON I.item_ID=F.itemID WHERE F.doctorID = @doctorId AND F.favType = 'I' second one using sub query like SELECT item_ID,item_Code,item_Name from [Pharmacy].[tblitemHdr] WHERE item_ID IN (SELECT itemID FROM EMR.tblFavourites WHERE doctorID = @doctorId AND favType = 'I' ) In this item table [Pharmacy].[tblitemHdr] Contains 15 columns and 2000 records

How does the optimizer decide between merge join and hash join?

拈花ヽ惹草 提交于 2019-12-25 04:18:09
问题 Database System Concepts introduce several ways to implement a join operation. Two of them are merge join and hash join. I was wondering when the optimizer decides to use a merge join and when a hash join? In particular, from https://stackoverflow.com/a/1114288/156458 hash joins can only be used for equi-joins, but merge joins are more flexible. But Database System Concepts says both are used only for equi joins and natural joins. The merge-join algorithm (also called the sort-merge-join

Time to add default values to a new column by approach

我的梦境 提交于 2019-12-25 03:08:38
问题 I need to add a new non-null column to an existing SQL table and set it to a default value. I understand that there are two different approaches to this: ALTER TABLE Foo ADD Col CHAR(1) NOT NULL DEFAULT('N') ALTER TABLE Foo ADD Col CHAR(1) GO UPDATE Foo SET Col = 'N' GO ALTER TABLE Foo ALTER COLUMN Col CHAR(1) NOT NULL DEFAULT('N') That is, in the second approach, there are three separate batches: first the column is created, then the default value is backfilled, and then the not null

How to disable/enable different query optimizations in POSTGRESQL?

烂漫一生 提交于 2019-12-25 02:48:15
问题 I'm doing some test to see the capability of Postgresql query performance. And my plan is to disable/enable different query optimizations, such as disable (automatic) index, disable re-order joins etc. is there some configuration to achieve this quickly or what part source code should I revise? thanks. 回答1: PostgreSQL provides debug parameters for exactly this. See the enable_ params in the docs. Please don't use them in production; it might seem like a good idea at the time, but those

sql using different execution plans when running a query and when running that query inside a stored procedure?

China☆狼群 提交于 2019-12-24 18:21:50
问题 I have this query, Declare @Prcocessrate float declare @item varchar(20) declare @process varchar(20) declare @branch varchar(20) set @item = 'shirt' set @process = 'kt' set @branch = '1' select @Prcocessrate = ProcessPrice from itemwiseprocessrate where itemname=@Item and Process=@process and branchid=@branch when I run it single handed, the execution plan only shows 3 steps , see for youself.. but I have this procedure sp_newBooking as ALTER PROC sp_newbooking -- other arguements-- AS BEGIN

How to avoid a filesort on a mysql composite index for a prefix query with an order by statement?

大憨熊 提交于 2019-12-24 16:44:21
问题 I have a 1 GB mysql table with three colums (german bigrams): create table sortedindex (source varchar(60),target varchar(60),score float) engine=myisam character set utf8 collate utf8_bin; I also created a composite index: create index sortedstd_ix on sortedindex (source(60), target(60), score); additionally I compressed the table and made it read only and sorted the index using: myisamchk --keys-used=0 -rq sortedindex myisampack sortedindex myisamchk -rq sortedindex --sort_buffer=3G --sort

MySQL taking forever 'sending data'. Simple query, lots of data

瘦欲@ 提交于 2019-12-24 16:14:56
问题 I'm trying to run what I believe to be a simple query on a fairly large dataset, and it's taking a very long time to execute -- it stalls in the "Sending data" state for 3-4 hours or more. The table looks like this: CREATE TABLE `transaction` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `uuid` varchar(36) NOT NULL, `userId` varchar(64) NOT NULL, `protocol` int(11) NOT NULL, ... A few other fields: ints and small varchars `created` datetime NOT NULL, PRIMARY KEY (`id`), KEY `uuid` (