Doris data model is currently divided into three categories: AGGREGATE KEY, UNIQUE KEY, DUPLICATE KEY. Data in all three models are sorted by KEY.
1.1.1. AGGREGATE KEY
When AGGREGATE KEY is the same, old and new records are aggregated. The aggregation functions currently supported are SUM, MIN, MAX, REPLACE.
AGGREGATE KEY model can aggregate data in advance and is suitable for reporting and multi-dimensional analysis business.
CREATE TABLE site_visit ( siteid INT, City: SMALLINT, username VARCHAR (32), pv BIGINT SUM DEFAULT '0' ) AGGREGATE KEY(siteid, city, username) DISTRIBUTED BY HASH(siteid) BUCKETS 10;
1.1.2. UNIQUE KEY
When UNIQUE KEY is the same, the new record covers the old record. Before version 1.2, UNIQUE KEY implements the same REPLACE aggregation method as AGGREGATE KEY, and they are essentially the same. We introduced a new merge-on-write implementation for UNIQUE KEY since version 1.2, which have better performance on many scenarios. Suitable for analytical business with updated requirements.
CREATE TABLE sales_order ( orderid BIGINT, status TINYINT, username VARCHAR (32), amount BIGINT DEFAULT '0' ) KEY (orderid) UNIT DISTRIBUTED BY HASH(orderid) BUCKETS 10;
1.1.3. DUPLICATE KEY
Only sort columns are specified, and the same rows are not merged. It is suitable for the analysis business where data need not be aggregated in advance.
CREATE TABLE session_data ( visitorid SMALLINT, sessionid BIGINT, visit time DATETIME, City CHAR (20), province CHAR(20), ip. varchar (32), brower CHAR(20), url: VARCHAR (1024) ) DUPLICATE KEY (visitor time, session time) DISTRIBUTED BY HASH(sessionid, visitorid) BUCKETS 10;
When the business side builds tables, in order to adapt to the front-end business, they often do not distinguish between dimension information and indicator information, and define the Schema as a large wide table, this operation is actually not so friendly to the database, we recommend users to use the star model.
In the process of using Star Schema, users are advised to use Star Schema to distinguish dimension tables from indicator tables as much as possible. Frequently updated dimension tables can also be placed in MySQL external tables. If there are only a few updates, they can be placed directly in Doris. When storing dimension tables in Doris, more copies of dimension tables can be set up to improve Join's performance.
Doris supports two-level partitioned storage. The first level is partition, which currently supports both RANGE and LIST partition types, and the second layer is HASH bucket.
1.3.1. Partitioning
Partition is used to divide data into different intervals, which can be logically understood as dividing the original table into multiple sub-tables. Data can be easily managed by partition, for example, to delete data more quickly.
1.3.1.1. Range Partitioning
In business, most users will choose to partition on time, which has the following advantages:
1.3.1.2. List Partitioning
In business,, users can select cities or other enumeration values for partition.
1.3.2. Hash Bucketing
The data is divided into different buckets according to the hash value.
Doris stores the data in an orderly manner, and builds a sparse index for Doris on the basis of ordered data. The index granularity is block (1024 rows).
Sparse index chooses fixed length prefix in schema as index content, and Doris currently chooses 36 bytes prefix as index.
Rollup can essentially be understood as a physical index of the original table. When creating Rollup, only some columns in Base Table can be selected as Schema. The order of fields in Schema can also be different from that in Base Table.
Rollup can be considered in the following cases:
1.5.1. Low ratio of data aggregation in the Base Table
This is usually due to the fact that Base Table has more differentiated fields. At this point, you can consider selecting some columns and establishing Rollup.
For the `site_visit'table:
site -u visit (siteid, city, username, pv)
Siteid may lead to a low degree of data aggregation. If business parties often base their PV needs on city statistics, they can build a city-only, PV-based rollup:
ALTER TABLE site_visit ADD ROLLUP rollup_city(city, pv);
1.5.2. The prefix index in Base Table cannot be hit
Generally, the way Base Table is constructed cannot cover all query modes. At this point, you can consider adjusting the column order and establishing Rollup.
Database Session
session -u data (visitorid, sessionid, visittime, city, province, ip, browser, url)
In addition to visitorid analysis, there are Brower and province analysis cases, Rollup can be established separately.
ALTER TABLE session_data ADD ROLLUP rollup_brower(brower,province,ip,url) DUPLICATE KEY(brower,province);
Users can modify the Schema of an existing table through the Schema Change operation, currently Doris supports the following modifications:
For details, please refer to Schema Change