日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql --The MEMORY Storage Engine--官方文档

發布時間:2025/4/5 数据库 47 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql --The MEMORY Storage Engine--官方文档 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

原文地址:http://dev.mysql.com/doc/refman/5.7/en/memory-storage-engine.html

The?MEMORY?storage engine (formerly known as?HEAP) creates special-purpose tables with contents that are stored in memory. Because the data is vulnerable to crashes, hardware issues, or power outages, only use these tables as temporary work areas or read-only caches for data pulled from other tables.

Table?15.4?MEMORY?Storage Engine Features

Storage limitsRAMTransactionsNoLocking granularityTable
MVCCNoGeospatial data type supportNoGeospatial indexing supportNo
B-tree indexesYesT-tree indexesNoHash indexesYes
Full-text search indexesNoClustered indexesNoData cachesN/A
Index cachesN/ACompressed dataNoEncrypted data[a]Yes
Cluster database supportNoReplication support[b]YesForeign key supportNo
Backup / point-in-time recovery[c]YesQuery cache supportYesUpdate statistics for data dictionaryYes

[a]?Implemented in the server (via encryption functions), rather than in the storage engine.

[b]?Implemented in the server, rather than in the storage engine.

[c]?Implemented in the server, rather than in the storage engine.

?

When to Use MEMORY or MySQL Cluster.??Developers looking to deploy applications that use the?MEMORYstorage engine for important, highly available, or frequently updated data should consider whether MySQL Cluster is a better choice. A typical use case for the?MEMORY?engine involves these characteristics:

  • Operations involving transient, non-critical data such as session management or caching. When the MySQL server halts or restarts, the data in?MEMORY?tables is lost.

  • In-memory storage for fast access and low latency. Data volume can fit entirely in memory without causing the operating system to swap out virtual memory pages.

  • A read-only or read-mostly data access pattern (limited updates).

MySQL Cluster offers the same features as the?MEMORY?engine with higher performance levels, and provides additional features not available with?MEMORY:

  • Row-level locking and multiple-thread operation for low contention between clients.

  • Scalability even with statement mixes that include writes.

  • Optional disk-backed operation for data durability.

  • Shared-nothing architecture and multiple-host operation with no single point of failure, enabling 99.999% availability.

  • Automatic data distribution across nodes; application developers need not craft custom sharding or partitioning solutions.

  • Support for variable-length data types (including?BLOB?and?TEXT) not supported by?MEMORY.

For a white paper with more detailed comparison of the?MEMORY?storage engine and MySQL Cluster, see?Scaling Web Services with MySQL Cluster: An Alternative to the MySQL Memory Storage Engine. This white paper includes a performance study of the two technologies and a step-by-step guide describing how existing?MEMORYusers can migrate to MySQL Cluster.

Performance Characteristics

MEMORY?performance is constrained by contention resulting from single-thread execution and table lock overhead when processing updates. This limits scalability when load increases, particularly for statement mixes that include writes.

Despite the in-memory processing for?MEMORY?tables, they are not necessarily faster than?InnoDB?tables on a busy server, for general-purpose queries, or under a read/write workload. In particular, the table locking involved with performing updates can slow down concurrent usage of?MEMORY?tables from multiple sessions.

Depending on the kinds of queries performed on a?MEMORY?table, you might create indexes as either the default hash data structure (for looking up single values based on a unique key), or a general-purpose B-tree data structure (for all kinds of queries involving equality, inequality, or range operators such as less than or greater than). The following sections illustrate the syntax for creating both kinds of indexes. A common performance issue is using the default hash indexes in workloads where B-tree indexes are more efficient.

Physical Characteristics of MEMORY Tables

The?MEMORY?storage engine associates each table with one disk file, which stores the table definition (not the data). The file name begins with the table name and has an extension of?.frm.

MEMORY?tables have the following characteristics:

  • Space for?MEMORY?tables is allocated in small blocks. Tables use 100% dynamic hashing for inserts. No overflow area or extra key space is needed. No extra space is needed for free lists. Deleted rows are put in a linked list and are reused when you insert new data into the table.?MEMORY?tables also have none of the problems commonly associated with deletes plus inserts in hashed tables.

  • MEMORY?tables use a fixed-length row-storage format. Variable-length types such as?VARCHAR?are stored using a fixed length.

  • MEMORY?tables cannot contain?BLOB?or?TEXT?columns.

  • MEMORY?includes support for?AUTO_INCREMENT?columns.

  • Non-TEMPORARY?MEMORY?tables are shared among all clients, just like any other non-TEMPORARY?table.

DDL Operations for MEMORY Tables

To create a?MEMORY?table, specify the clause?ENGINE=MEMORY?on the?CREATE TABLE?statement.

CREATE TABLE t (i INT) ENGINE = MEMORY;

As indicated by the engine name,?MEMORY?tables are stored in memory. They use hash indexes by default, which makes them very fast for single-value lookups, and very useful for creating temporary tables. However, when the server shuts down, all rows stored in?MEMORY?tables are lost. The tables themselves continue to exist because their definitions are stored in?.frm?files on disk, but they are empty when the server restarts.

This example shows how you might create, use, and remove a?MEMORY?table:

mysql> CREATE TABLE test ENGINE=MEMORY-> SELECT ip,SUM(downloads) AS down-> FROM log_table GROUP BY ip; mysql> SELECT COUNT(ip),AVG(down) FROM test; mysql> DROP TABLE test;

The maximum size of?MEMORY?tables is limited by the?max_heap_table_size?system variable, which has a default value of 16MB. To enforce different size limits for?MEMORY?tables, change the value of this variable. The value in effect for?CREATE TABLE, or a subsequent?ALTER TABLE?or?TRUNCATE TABLE, is the value used for the life of the table. A server restart also sets the maximum size of existing?MEMORY?tables to the globalmax_heap_table_size?value. You can set the size for individual tables as described later in this section.

Indexes

The?MEMORY?storage engine supports both?HASH?and?BTREE?indexes. You can specify one or the other for a given index by adding a?USING?clause as shown here:

CREATE TABLE lookup(id INT, INDEX USING HASH (id))ENGINE = MEMORY; CREATE TABLE lookup(id INT, INDEX USING BTREE (id))ENGINE = MEMORY;

For general characteristics of B-tree and hash indexes, see?Section?8.3.1, “How MySQL Uses Indexes”.

MEMORY?tables can have up to 64 indexes per table, 16 columns per index and a maximum key length of 3072 bytes.

If a?MEMORY?table hash index has a high degree of key duplication (many index entries containing the same value), updates to the table that affect key values and all deletes are significantly slower. The degree of this slowdown is proportional to the degree of duplication (or, inversely proportional to the index cardinality). You can use a?BTREE?index to avoid this problem.

MEMORY?tables can have nonunique keys. (This is an uncommon feature for implementations of hash indexes.)

Columns that are indexed can contain?NULL?values.

User-Created and Temporary Tables

MEMORY?table contents are stored in memory, which is a property that?MEMORY?tables share with internal temporary tables that the server creates on the fly while processing queries. However, the two types of tables differ in thatMEMORY?tables are not subject to storage conversion, whereas internal temporary tables are:

  • If an internal temporary table becomes too large, the server automatically converts it to on-disk storage, as described in?Section?8.4.4, “How MySQL Uses Internal Temporary Tables”.

  • User-created?MEMORY?tables are never converted to disk tables.

Loading Data

To populate a?MEMORY?table when the MySQL server starts, you can use the?--init-file?option. For example, you can put statements such as?INSERT INTO ... SELECT?or?LOAD DATA INFILE?into this file to load the table from a persistent data source. See?Section?5.1.3, “Server Command Options”, and?Section?13.2.6, “LOAD DATA INFILE Syntax”.

MEMORY Tables and Replication

A server's?MEMORY?tables become empty when it is shut down and restarted. If the server is a replication master, its slaves are not aware that these tables have become empty, so you see out-of-date content if you select data from the tables on the slaves. To synchronize master and slave?MEMORY?tables, when a?MEMORY?table is used on a master for the first time since it was started, a?DELETE?statement is written to the master's binary log, to empty the table on the slaves also. The slave still has outdated data in the table during the interval between the master's restart and its first use of the table. To avoid this interval when a direct query to the slave could return stale data, use the?--init-file?option to populate the?MEMORY?table on the master at startup.

Managing Memory Use

The server needs sufficient memory to maintain all?MEMORY?tables that are in use at the same time.

Memory is not reclaimed if you delete individual rows from a?MEMORY?table. Memory is reclaimed only when the entire table is deleted. Memory that was previously used for deleted rows is re-used for new rows within the same table. To free all the memory used by a?MEMORY?table when you no longer require its contents, execute?DELETE?orTRUNCATE TABLE?to remove all rows, or remove the table altogether using?DROP TABLE. To free up the memory used by deleted rows, use?ALTER TABLE ENGINE=MEMORY?to force a table rebuild.

The memory needed for one row in a?MEMORY?table is calculated using the following expression:

SUM_OVER_ALL_BTREE_KEYS(max_length_of_key + sizeof(char*) * 4) + SUM_OVER_ALL_HASH_KEYS(sizeof(char*) * 2) + ALIGN(length_of_row+1, sizeof(char*))

ALIGN()?represents a round-up factor to cause the row length to be an exact multiple of the?char?pointer size.sizeof(char*)?is 4 on 32-bit machines and 8 on 64-bit machines.

As mentioned earlier, the?max_heap_table_size?system variable sets the limit on the maximum size of?MEMORYtables. To control the maximum size for individual tables, set the session value of this variable before creating each table. (Do not change the global?max_heap_table_size?value unless you intend the value to be used forMEMORY?tables created by all clients.) The following example creates two?MEMORY?tables, with a maximum size of 1MB and 2MB, respectively:

mysql> SET max_heap_table_size = 1024*1024; Query OK, 0 rows affected (0.00 sec)mysql> CREATE TABLE t1 (id INT, UNIQUE(id)) ENGINE = MEMORY; Query OK, 0 rows affected (0.01 sec)mysql> SET max_heap_table_size = 1024*1024*2; Query OK, 0 rows affected (0.00 sec)mysql> CREATE TABLE t2 (id INT, UNIQUE(id)) ENGINE = MEMORY; Query OK, 0 rows affected (0.00 sec)

Both tables revert to the server's global?max_heap_table_size?value if the server restarts.

You can also specify a?MAX_ROWS?table option in?CREATE TABLE?statements for?MEMORY?tables to provide a hint about the number of rows you plan to store in them. This does not enable the table to grow beyond themax_heap_table_size?value, which still acts as a constraint on maximum table size. For maximum flexibility in being able to use?MAX_ROWS, set?max_heap_table_size?at least as high as the value to which you want eachMEMORY?table to be able to grow.

Additional Resources

A forum dedicated to the?MEMORY?storage engine is available at?http://forums.mysql.com/list.php?92.

轉載于:https://www.cnblogs.com/davidwang456/p/4451242.html

總結

以上是生活随笔為你收集整理的mysql --The MEMORY Storage Engine--官方文档的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 亚洲 欧美 自拍偷拍 | 日韩 欧美 综合 | 免费播放片大片 | 自拍日韩亚洲一区在线 | 精品人妻一区二区三区香蕉 | 精品一区久久 | 天堂v在线观看 | 99久久99久久精品国产片 | 一级片在线观看免费 | 午夜激情综合 | 一区二区三区日 | 午夜免费福利视频 | 天天舔天天射天天干 | 国产精品视频第一页 | 国内av自拍 | 婷婷日 | 特色黄色片 | 玩弄白嫩少妇xxxxx性 | 亚洲精品国产成人久久av盗摄 | 国产美女精品久久 | 日本五十路在线 | 欧美在线专区 | 性做久久久久久久久 | 欧美国产视频一区 | 亚洲第一成年人网站 | www.av在线| 国产精品揄拍100视频 | 91超薄肉色丝袜交足高跟凉鞋 | a网站在线 | 国产女人18毛片水真多18精品 | 欧美国产日韩一区二区 | 女同视频网站 | 青青草视频免费播放 | a视频网站 | 日韩激情国产 | 6699嫩草久久久精品影院 | 国产乱子视频 | 国产在线精品福利 | 国产在线免费观看 | av毛片网 | 亚洲精品日韩丝袜精品 | 日本午夜网 | 麻豆精品免费 | 韩国电影大尺度在线观看 | www.国产com | 国产精品蜜臀 | 亚洲一区二区日韩 | 亚洲欧洲视频在线观看 | 精品99在线观看 | 欧美人妻精品一区二区三区 | 青青草视频在线看 | 波多野结衣毛片 | 宅男av在线| 成人看片黄a免费看视频 | 开元在线观看视频国语 | 999热精品视频 | 中文字幕av影视 | 懂色av色吟av夜夜嗨 | 日本男女网站 | 国产chinese中国hdxxxx | 中文字幕乱码中文乱码777 | 亚洲综合在线成人 | 四虎伊人 | 欧美在线激情视频 | 亚洲午夜久久久久久久久 | 午夜久久久久久久 | 国产精品国产三级国产普通话对白 | 综合视频一区二区 | 超碰在线cao| 狠狠干青青草 | 国产在线播 | 国产91免费观看 | 天天射天天拍 | 欧美又大粗又爽又黄大片视频 | 折磨小男生性器羞耻的故事 | 天天操婷婷 | 五月天丁香婷 | 久久三级精品 | 成年精品 | 午夜精品99 | 丰满少妇被猛烈进入 | 亚洲永久精品视频 | 成人区精品一区二区婷婷 | 影音先锋成人资源 | 污视频在线网站 | 国产免费黄网站 | 91精品国| 福利视频一区 | 国产乱妇4p交换乱免费视频 | 日日操夜夜 | 国产 日韩 欧美 制服丝袜 | 苏晴忘穿内裤坐公交车被揉到视频 | a视频在线免费观看 | 艳妇乳肉豪妇荡乳av无码福利 | 天堂成人国产精品一区 | 91福利网址 | 51国产偷自视频区视频 | 人妖天堂狠狠ts人妖天堂狠狠 | 操xxxx |