indexing

Do indexes suck in SQL?

放肆的年华 提交于 2020-01-01 11:40:12
问题 Say I have a table with a large number of rows and one of the columns which I want to index can have one of 20 values. If I were to put an index on the column would it be large? If so, why? If I were to partition the data into the data into 20 tables, one for each value of the column, the index size would be trivial but the indexing effect would be the same. 回答1: It's not the indexes that will suck. It's putting indexes on the wrong columns that will suck. Seriously though, why would you need

Do indexes suck in SQL?

試著忘記壹切 提交于 2020-01-01 11:39:52
问题 Say I have a table with a large number of rows and one of the columns which I want to index can have one of 20 values. If I were to put an index on the column would it be large? If so, why? If I were to partition the data into the data into 20 tables, one for each value of the column, the index size would be trivial but the indexing effect would be the same. 回答1: It's not the indexes that will suck. It's putting indexes on the wrong columns that will suck. Seriously though, why would you need

SQL Server does not use an index comparing datetime to not null

瘦欲@ 提交于 2020-01-01 10:12:32
问题 I have a simple table not related to any other. It has a not PK column that it is a date. I have created a non-clustered index to that column. If I make this query: select * from table where datecolumn is not null <-- does not use the index and goes really slow. But if I remove the not, this way: select * from table where datecolum is null <-- uses the index and goes really fast. There are much more not nulls than nulls. Am I forgetting something? Could I use filtered index here? Thanks in

MySQL composite indexes and operator BETWEEN

家住魔仙堡 提交于 2020-01-01 10:06:17
问题 I have a question about this query: SELECT * FROM runs WHERE (NOW() BETWEEN began_at AND finished_at) Do you think it makes sense to create composite index for began_at and finished_at columns? Or it makes sense to create index only for began_at? 回答1: Your style is very uncommon. Most people would probably write WHERE began_at < NOW() AND finished_at > NOW() However. I would recommend putting an index on both fields. A combined key wont be of use to you because you it would only speed up

MySQL Hash Indexes for Optimization

感情迁移 提交于 2020-01-01 09:37:07
问题 So maybe this is noob, but I'm messing with a couple tables. I have TABLE A roughly 45,000 records I have TABLE B roughly 1.5 million records I have a query: update schema1.tablea a inner join ( SELECT DISTINCT ID, Lookup, IDpart1, IDpart2 FROM schema1.tableb WHERE IDpart1 is not NULL AND Lookup is not NULL ORDER BY ID,Lookup ) b Using(ID,Lookup) set a.Elg_IDpart1 = b.IDpart1, a.Elg_IDpart2 = b.IDpart2 where a.ID is NOT NULL AND a.Elg_IDpart1 is NULL So I am forcing the index on ID, Lookup.

Indexing & alternatives for low-selectivity columns

你说的曾经没有我的故事 提交于 2020-01-01 09:13:25
问题 What are the range of tactics available for selecting records on low selectivity columns? An example might be an orders table where, over many years, you build up a large number of completed orders but often need to select active orders. An order might go through a lifecycle such as placed, stock-allocated, picked from warehouse, despatched to customer, invoiced and paid. An order might additionally be cancelled, held, etc. The majority of records will eventually be in the final state (e.g.

Indexing & alternatives for low-selectivity columns

僤鯓⒐⒋嵵緔 提交于 2020-01-01 09:13:02
问题 What are the range of tactics available for selecting records on low selectivity columns? An example might be an orders table where, over many years, you build up a large number of completed orders but often need to select active orders. An order might go through a lifecycle such as placed, stock-allocated, picked from warehouse, despatched to customer, invoiced and paid. An order might additionally be cancelled, held, etc. The majority of records will eventually be in the final state (e.g.

My simple MySql query doesn't use index

烂漫一生 提交于 2020-01-01 09:12:26
问题 I have a very simple query: SELECT comments.* FROM comments WHERE comments.imageid=46 And this is my table: CREATE TABLE IF NOT EXISTS `comments` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `imageid` int(10) unsigned NOT NULL DEFAULT '0', `uid` bigint(20) unsigned NOT NULL DEFAULT '0', `content` text CHARACTER SET utf8, `adate` datetime DEFAULT NULL, `ip` int(10) unsigned DEFAULT NULL, PRIMARY KEY (`id`), KEY `ids` (`imageid`) USING BTREE, KEY `dt` (`adate`) USING BTREE ) ENGINE

My simple MySql query doesn't use index

此生再无相见时 提交于 2020-01-01 09:11:05
问题 I have a very simple query: SELECT comments.* FROM comments WHERE comments.imageid=46 And this is my table: CREATE TABLE IF NOT EXISTS `comments` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `imageid` int(10) unsigned NOT NULL DEFAULT '0', `uid` bigint(20) unsigned NOT NULL DEFAULT '0', `content` text CHARACTER SET utf8, `adate` datetime DEFAULT NULL, `ip` int(10) unsigned DEFAULT NULL, PRIMARY KEY (`id`), KEY `ids` (`imageid`) USING BTREE, KEY `dt` (`adate`) USING BTREE ) ENGINE

MySQL - multiple column index

廉价感情. 提交于 2020-01-01 08:54:13
问题 I'm learning MySQL index and found that index should be applied to any column named in the WHERE clause of a SELECT query. Then I found Multiple Column Index vs Multiple Indexes. First Q, I was wondering what is multiple column index. I found code bellow from Joomla, is this Multiple Column Index? CREATE TABLE `extensions` ( `extension_id` INT(11) NOT NULL AUTO_INCREMENT, `name` VARCHAR(100) NOT NULL, `type` VARCHAR(20) NOT NULL, `element` VARCHAR(100) NOT NULL, `folder` VARCHAR(100) NOT NULL