16
16
<para>
17
17
Fast random access on the primary key.
18
18
This can result in significant performance benefits when
19
- working with data that has to be moved to RAM and requires
20
- a very high read and write access rate,
21
- especially on multi-core systems.
19
+ working with data that requires a very high read and write
20
+ access rate, especially on multi-core systems.
22
21
</para>
23
22
</listitem>
24
23
<listitem>
25
24
<para>
26
- Saving disk space: there is no primary key
27
- duplication as all data is stored directly in the index.
25
+ Effective space usage.
26
+ There is no primary key duplication as all data
27
+ is stored directly in the index.
28
28
</para>
29
29
</listitem>
30
30
</itemizedlist>
31
31
</para>
32
32
33
33
<para>
34
- Just like regular heap-organized tables,
35
- in-memory tables support transactions, including savepoints.
34
+ In-memory tables support transactions, including savepoints.
36
35
However, the data in such tables is stored only while the server is running.
37
36
Once the server is shut down, all in-memory data gets truncated.
38
37
When using in-memory tables, you should also take into account the following
@@ -202,20 +201,20 @@ OPTIONS (INDICES '(id, author COLLATE "ru_RU" ASC)');
202
201
Fill the <structname>blog_views</structname>
203
202
table with initial zero values for initial ten blog posts:
204
203
<programlisting>
205
- # INSERT INTO blog_views (SELECT id, 0 FROM generate_series(1, 10) AS id);
204
+ postgres= # INSERT INTO blog_views (SELECT id, 0 FROM generate_series(1, 10) AS id);
206
205
</programlisting>
207
206
</para>
208
207
209
208
<para>Increment the view count for a couple of posts
210
209
and display the result:
211
210
<programlisting>
212
- # UPDATE blog_views SET views = views + 1 WHERE id = 1;
211
+ postgres= # UPDATE blog_views SET views = views + 1 WHERE id = 1;
213
212
UPDATE 1
214
- # UPDATE blog_views SET views = views + 1 WHERE id = 1;
213
+ postgres= # UPDATE blog_views SET views = views + 1 WHERE id = 1;
215
214
UPDATE 2
216
- # UPDATE blog_views SET views = views + 1 WHERE id = 2;
215
+ postgres= # UPDATE blog_views SET views = views + 1 WHERE id = 2;
217
216
UPDATE 1
218
- # SELECT * FROM blog_views WHERE id = 1 OR id = 2;
217
+ postgres= # SELECT * FROM blog_views WHERE id = 1 OR id = 2;
219
218
id | views
220
219
----+-------
221
220
1 | 2
@@ -227,7 +226,7 @@ UPDATE 1
227
226
Check planning and execution costs for a query that
228
227
only requires a primary key lookup:
229
228
<programlisting>
230
- # EXPLAIN ANALYZE SELECT * FROM blog_views WHERE id = 1;
229
+ postgres= # EXPLAIN ANALYZE SELECT * FROM blog_views WHERE id = 1;
231
230
QUERY PLAN
232
231
-------------------------------------------------------------------
233
232
Foreign Scan on blog_views (cost=0.02..0.03 rows=1 width=16)
@@ -242,7 +241,7 @@ Execution time: 0.035 ms
242
241
Check the costs of calculating the sum of all views, which requires
243
242
a full index scan:
244
243
<programlisting>
245
- # EXPLAIN ANALYZE SELECT SUM(views) FROM blog_views;
244
+ postgres= # EXPLAIN ANALYZE SELECT SUM(views) FROM blog_views;
246
245
QUERY PLAN
247
246
--------------------------------------------------------------------
248
247
Aggregate (cost=1.62..1.63 rows=1 width=32)
@@ -319,7 +318,7 @@ Execution time: 0.353 ms
319
318
as well as the total number of pages allocated for in-memory tables.
320
319
For example:
321
320
<screen>
322
- # SELECT * FROM in_memory.in_memory_page_stats();
321
+ postgres= # SELECT * FROM in_memory.in_memory_page_stats();
323
322
used_pages | free_pages | all_pages
324
323
------------+------------+-----------
325
324
576 | 7616 | 8192
0 commit comments