MyISAM

InnoDB索引实现原理以及注意点和建议

江枫思渺然 提交于 2020-01-07 21:27:28
一、InnoDB实现原理 虽然InnoDB也使用B+Tree作为索引结构,但具体实现方式却与MyISAM截然不同。因为InnoDB支持聚簇索引(主键索引),聚簇索引就是表,所以InnoDB不用像MyISAM那样需要独立的行存储。也就是说,InnoDB的数据文件本身就是索引文件。 聚簇索引的每一个叶子节点都包含了主键值、事务ID、用于事务和MVCC的回滚指针以及所有的剩余列。假设我们以col1为主键,则下图是一个InnoDB表的聚簇索引(主键索引)(Primary key)示意。 与MyISAM不同的是,InnoDB的二级索引和聚簇索引很不相同。InnoDB的二级索引的叶子节点存储的不是行号(行指针),而是主键列。这种策略的缺点是二级索引需要两次索引查找,第一次在二级索引中查找主键,第二次在聚簇索引中通过主键查找需要的数据行。 画外音:可以通过我们前面提到过的索引覆盖来避免回表查询,这样就只需要一次回表查询,对于InnoDB而言,就是只需要一次索引查找就可以查询到需要的数据记录,因为需要的数据记录已经被索引到二级索引中,直接就可以找到。 因为InnoDB的索引的方式通过主键聚集数据,严重依赖主键。索引如果没有定义主键,那么InnoDB会选择一个唯一的非空索引代替。如果没有这样的索引,InnoDB会隐式定义一个主键来作为聚簇索引。 二、优缺点 优点 可以把相关数据存储在一起

MySQL中的行级锁,表级锁,页级锁

风流意气都作罢 提交于 2020-01-07 05:14:15
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 在计算机科学中,锁是在执行多线程时用于强行限制资源访问的同步机制,即用于在并发控制中保证对互斥要求的满足。 在 数据库的锁机制 中介绍过,在DBMS中,可以按照锁的粒度把数据库锁分为行级锁(INNODB引擎)、表级锁(MYISAM引擎)和页级锁(BDB引擎)。 行级锁 行级锁是Mysql中锁定粒度最细的一种锁,表示只针对当前操作的行进行加锁。行级锁能大大减少数据库操作的冲突。其加锁粒度最小,但加锁的开销也最大。行级锁分为 共享锁 和 排他锁 。 只有通过索引条件检索数据,InnoDB才使用行级锁(MySQL的行锁是针对索引加的锁,不是针对记录加的锁,所以虽然是访问不同行的记录,但是如果是使用相同的索引键,是会出现锁冲突的。 ),否则,InnoDB将使用表锁! 即便在条件中使用了索引字段,但是否使用索引来检索数据是由MySQL通过判断不同执行计划的代价来决定的,如果MySQL认为全表扫描效率更高,比如对一些很小的表,它就不会使用索引,这种情况下InnoDB将使用表锁,而不是行锁。因此,在分析锁冲突时,别忘了检查SQL的执行计划,以确认是否真正使用了索引。 在MySQL中,行级锁并不是直接锁记录,而是锁索引。索引分为主键索引和非主键索引两种,如果一条sql语句操作了主键索引,MySQL就会锁定这条主键索引

Convert InnoDB to MyISAM with InnoDB disabled

可紊 提交于 2020-01-06 05:38:04
问题 I'm the lucker owner of a webhotel where the host changes settings without telling. When thats said, I have some tables in my database that are running with InnoDB engine. But over the night the host have disabled InnoDB, so I cant convert it to MyISAM with ALTER command. Anyway I can get the data out of the database, or convert it to MyISAM when InnoDB is disabled? Only thing I see all the time is, #1033 - Incorrect information in file: 'file.frm' Thanks. 回答1: Unfortunately, you need to have

Convert InnoDB to MyISAM with InnoDB disabled

China☆狼群 提交于 2020-01-06 05:38:02
问题 I'm the lucker owner of a webhotel where the host changes settings without telling. When thats said, I have some tables in my database that are running with InnoDB engine. But over the night the host have disabled InnoDB, so I cant convert it to MyISAM with ALTER command. Anyway I can get the data out of the database, or convert it to MyISAM when InnoDB is disabled? Only thing I see all the time is, #1033 - Incorrect information in file: 'file.frm' Thanks. 回答1: Unfortunately, you need to have

MySQL: Converting from MyISAM to InnoDB makes queries faster…?

半世苍凉 提交于 2020-01-03 05:16:09
问题 I had a table with 3,000,000 rows which has IP ranges and their corresponding country, region(province) and city. The table was in MyISAM engine. I wrote a script to fetch the geographic location for users by their IP and some of the queries took up to 17sec. I then converted the table to InnoDB and retried the querying process, some of the problematic queries known to be time consuming before has been improved in performance significantly, taking as short as 0.02 seconds. Although there

彪悍开源的分析数据库-ClickHouse

夙愿已清 提交于 2020-01-02 09:17:29
https://zhuanlan.zhihu.com/p/22165241 今天介绍一个来自俄罗斯的凶猛彪悍的分析数据库: ClickHouse ,它是今年6月开源,俄语社区为主,好酒不怕巷子深。 本文内容较长,分为三个部分: 走马观花,死而后生,遥指杏花村 ;第一章,走马观花,初步了解一下基本特性;第二章,死而后生,介绍ClickHouse的技术架构演化的今生前世;第三章,遥指杏花村,介绍一些参考资料,包括一些俄文资料。 第一章,走马观花 俄罗斯的‘百度’叫做Yandex,覆盖了俄语搜索超过68%的市场,有俄语的地方就有Yandex;有中文的地方,就有百度么?好像不一定 :) 。 Yandex在2016年6月15日开源了一个数据分析的数据库,名字叫做ClickHouse,这对保守俄罗斯人来说是个特大事。更让人惊讶的是, 这个列式存储数据库的跑分要超过很多流行的商业MPP数据库软件,例如Vertica。 如果你没有听过Vertica,那你一定听过 Michael Stonebraker,2014年图灵奖的获得者,PostgreSQL和Ingres发明者(Sybase和SQL Server都是继承 Ingres而来的), Paradigm4和SciDB的创办者。Michael Stonebraker于2005年创办Vertica公司,后来该公司被HP收购,HP

MySQL why logged as slow query/log-queries-not-using-indexes when have indexes?

断了今生、忘了曾经 提交于 2020-01-01 18:18:04
问题 Mysql 5.1.x in my.cnf: log-queries-not-using-indexes = 1 long_query_time = 30 and slow queries are logged Why I show this at log? Not slow and all fields are indexed. From mysql.slow.log: # Query_time: 0.001492 Lock_time: 0.000031 Rows_sent: 229 Rows_examined: 458 use database1; SET timestamp=1393342939; SELECT id,name FROM database1 ORDER BY name ASC; This table has 229 rows, MYISAM. id and name are indexed id = auto increment int unsigned name = varchar(255) utf-8 Can you explain why I show

MySQL why logged as slow query/log-queries-not-using-indexes when have indexes?

北战南征 提交于 2020-01-01 18:17:47
问题 Mysql 5.1.x in my.cnf: log-queries-not-using-indexes = 1 long_query_time = 30 and slow queries are logged Why I show this at log? Not slow and all fields are indexed. From mysql.slow.log: # Query_time: 0.001492 Lock_time: 0.000031 Rows_sent: 229 Rows_examined: 458 use database1; SET timestamp=1393342939; SELECT id,name FROM database1 ORDER BY name ASC; This table has 229 rows, MYISAM. id and name are indexed id = auto increment int unsigned name = varchar(255) utf-8 Can you explain why I show

MySQL: Concurrent updates (through threads) on a simple table

只谈情不闲聊 提交于 2020-01-01 07:00:13
问题 In my application (VC++/Windows 8) I am having 7 threads each have opened connection to MySQL database. All these threads concurrently try to increment value of single field in a table. To do this I've created a sample table DEMO_TABLE having columns MyIndex and MyCounter (both integers) and added a row to it having MyIndex field value 0. Then I am calling executeUpdate through each thread using MySQL Connector C++ : executeUpdate("UPDATE DEMO_TABLE SET MyCounter = (MyCounter + 1) WHERE

Speed-up of readonly MyISAM table

倾然丶 夕夏残阳落幕 提交于 2020-01-01 06:36:33
问题 We have a large MyISAM table that is used to archive old data. This archiving is performed every month, and except from these occasions data is never written to the table. Is there anyway to "tell" MySQL that this table is read-only, so that MySQL might optimize the performance of reads from this table? I've looked at the MEMORY storage engine, but the problem is that this table is so large that it would take a large portion of the servers memory, which I don't want. Hope my question is clear