Append-only Data

Source: Internet
Author: User

1. Description

Think it's still necessary to illustrate this type of index, Phoenix divides its two-level indexing technology into Global and local indexing 2, but if it continues to be subdivided, it is divided into mutable global Indexing, mutable local indexing, immutable global indexing, immutable local indexing altogether four kinds.

The default two-level index created is mutable (mutable global ing or mutable local indexing). Both of these indexing techniques are outlined in both of the previous articles. The index of the immutable type is primarily for scenarios where data is never changed once it is put into storage (only written once and never updated).

2. Append-only Data

For a table in which the data was only written once and never updated in-place, certain optimizations could be made to reduce The write-time overhead for incremental maintenance. This is common with time-series data such as log or event data, where once a row is written, it'll never be updated. To take advantage of these optimizations, declare your table as immutable by adding the Immutable_rows=true property to Yo ur DDL statement:

CREATE TABLE my_table (k VARCHAR PRIMARY KEY, v VARCHAR) IMMUTABLE_ROWS=true;
    • 1

All indexes to a table declared with Immutable_rows=true is considered immutable (note that by default, tables is Consid Ered mutable). For global immutable indexes, the index was maintained entirely on the client-side with the index table being generated as Change to the data table occur. Local immutable indexes, on the other hand, is maintained on the server-side. Note that no safeguards is in-place to enforce, a table declared as immutable doesn ' t actually mutate data (as that W Ould negate the performance gain achieved). If that is to occur, the index would no longer is in sync with the table.

In a scenario where data is written once and never updated, the core optimization is to reduce the overhead of performance when writing data. For example, the log data and event type data are written once and never updated. By declaring Immutable_rows=true at the time of the scene data table, all indexes of the table are immutable (the default is the mutable type). The Global immutable indexes is maintained by the client, while the local immutable indexes is maintained by the service side. even if you use the immutable declaration when creating a table, the data in the data table can be updated. If this is done, it causes the data table's data to be out of sync with the data in the Index table.

2.1 Creating a table

When you create a data table, declare immutable_rows=true to show that all indexes of the table are immutable.

> create table company_immutable(id varchar primary key, name varchar, address varchar) IMMUTABLE_ROWS=true; 
    • 1

2.2 Creating an index

Create an index on the name field of the Company_immutable table.

create index name_test on company_immutable(name); 
    • 1

2.3 Inserting Data

Insert test data.

company_immutable(id, name, address) values(‘001‘, ‘dimensoft‘, ‘nanjing‘);
    • 1

2.4 Querying Data

Querying data tables and index table data.

select * from company_immutable;> select * from name_test;
    • 1
    • 2

2.5 Updating Data

Update the data with ID 001 (This is for testing only for data update operations, otherwise it is best not to update the table that declares the immutable).

company_immutable(id, name, address) values(‘001‘, ‘baidu‘, ‘beijing‘);
    • 1

Requery the data table and Index table.

select * from company_immutable;> select * from name_test;
    • 1
    • 2

You can see that the data in the index table has not been modified, but is appended! This is the index of the immutable type.

Append-only Data

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.