mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 23:52:03 +00:00
Update memory.md
This commit is contained in:
parent
4d6aeaa151
commit
f67eae6d7b
@ -22,8 +22,7 @@ Normally, using this table engine is not justified. However, it can be used for
|
|||||||
|
|
||||||
The Memory engine is used by the system for temporary tables with external query data (see the section “External data for processing a query”), and for implementing `GLOBAL IN` (see the section “IN operators”).
|
The Memory engine is used by the system for temporary tables with external query data (see the section “External data for processing a query”), and for implementing `GLOBAL IN` (see the section “IN operators”).
|
||||||
|
|
||||||
Upper and lower bounds can be specified to limit Memory engine table size, effectively allowing it to act as a circular
|
Upper and lower bounds can be specified to limit Memory engine table size, effectively allowing it to act as a circular buffer (see [Engine Parameters](#engine-parameters)).
|
||||||
buffer (see [Engine Parameters](#engine-parameters)).
|
|
||||||
|
|
||||||
## Engine Parameters {#engine-parameters}
|
## Engine Parameters {#engine-parameters}
|
||||||
|
|
||||||
@ -40,9 +39,6 @@ buffer (see [Engine Parameters](#engine-parameters)).
|
|||||||
|
|
||||||
## Usage {#usage}
|
## Usage {#usage}
|
||||||
|
|
||||||
``` sql
|
|
||||||
CREATE TABLE memory (i UInt32) ENGINE = Memory;
|
|
||||||
```
|
|
||||||
|
|
||||||
**Initialize settings**
|
**Initialize settings**
|
||||||
``` sql
|
``` sql
|
||||||
@ -56,16 +52,42 @@ CREATE TABLE memory (i UInt32) ENGINE = Memory SETTINGS min_rows_to_keep = 100,
|
|||||||
CREATE TABLE memory (i UInt32) ENGINE = Memory SETTINGS min_bytes_to_keep = 4096, max_bytes_to_keep = 16384;
|
CREATE TABLE memory (i UInt32) ENGINE = Memory SETTINGS min_bytes_to_keep = 4096, max_bytes_to_keep = 16384;
|
||||||
|
|
||||||
/* 1. testing oldest block doesn't get deleted due to min-threshold - 3000 rows */
|
/* 1. testing oldest block doesn't get deleted due to min-threshold - 3000 rows */
|
||||||
INSERT INTO memory SELECT * FROM numbers(0, 1600);
|
INSERT INTO memory SELECT * FROM numbers(0, 1600); -- 8'192 bytes
|
||||||
|
|
||||||
/* 2. adding block that doesn't get deleted */
|
/* 2. adding block that doesn't get deleted */
|
||||||
INSERT INTO memory SELECT * FROM numbers(1000, 100);
|
INSERT INTO memory SELECT * FROM numbers(1000, 100); -- 1'024 bytes
|
||||||
|
|
||||||
/* 3. testing oldest block gets deleted - 9216 bytes - 1100 */
|
/* 3. testing oldest block gets deleted - 9216 bytes - 1100 */
|
||||||
INSERT INTO memory SELECT * FROM numbers(9000, 1000);
|
INSERT INTO memory SELECT * FROM numbers(9000, 1000); -- 8'192 bytes
|
||||||
|
|
||||||
/* 4. checking a very large block overrides all */
|
/* 4. checking a very large block overrides all */
|
||||||
INSERT INTO memory SELECT * FROM numbers(9000, 10000);
|
INSERT INTO memory SELECT * FROM numbers(9000, 10000); -- 65'536 bytes
|
||||||
|
|
||||||
|
SELECT total_bytes, total_rows FROM system.tables WHERE name = 'memory' and database = currentDatabase();
|
||||||
|
```
|
||||||
|
|
||||||
|
``` text
|
||||||
|
┌─total_bytes─┬─total_rows─┐
|
||||||
|
│ 65536 │ 10000 │
|
||||||
|
└─────────────┴────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
also, for rows:
|
||||||
|
|
||||||
|
``` sql
|
||||||
|
CREATE TABLE memory (i UInt32) ENGINE = Memory SETTINGS min_rows_to_keep = 4000, max_rows_to_keep = 10000;
|
||||||
|
|
||||||
|
/* 1. testing oldest block doesn't get deleted due to min-threshold - 3000 rows */
|
||||||
|
INSERT INTO memory SELECT * FROM numbers(0, 1600); -- 1'600 rows
|
||||||
|
|
||||||
|
/* 2. adding block that doesn't get deleted */
|
||||||
|
INSERT INTO memory SELECT * FROM numbers(1000, 100); -- 100 rows
|
||||||
|
|
||||||
|
/* 3. testing oldest block gets deleted - 9216 bytes - 1100 */
|
||||||
|
INSERT INTO memory SELECT * FROM numbers(9000, 1000); -- 1'000 rows
|
||||||
|
|
||||||
|
/* 4. checking a very large block overrides all */
|
||||||
|
INSERT INTO memory SELECT * FROM numbers(9000, 10000); -- 10'000 rows
|
||||||
|
|
||||||
SELECT total_bytes, total_rows FROM system.tables WHERE name = 'memory' and database = currentDatabase();
|
SELECT total_bytes, total_rows FROM system.tables WHERE name = 'memory' and database = currentDatabase();
|
||||||
```
|
```
|
||||||
|
Loading…
Reference in New Issue
Block a user