Refer to the Quick start section to configure your cluster for Hybrid Transactional/Analytical Processing (HTAP) workloads, or the Advanced usage section to customize IMCI for specific business requirements.
Quick start
Step 1: Add a read-only IMCI node
Log on to the PolarDB console. In the left-side navigation pane, click Clusters. Select your cluster's region and find the cluster. In the Actions column, click Add/Remove Node to add a read-only IMCI node.
-
If you already added a read-only IMCI node when you purchased the cluster, skip this step.
-
Your cluster must meet the version requirements for IMCI. For more information, see read-only IMCI node.
Step 2: Configure request routing
You can choose automatic or manual request routing to use IMCI based on your business requirements.
-
Automatic request routing: If your Online Transactional Processing (OLTP) and Online Analytical Processing (OLAP) workloads access the database from the same application, you can automatically route read requests to either read-only IMCI nodes or read-only row store nodes based on the estimated execution cost, which is determined by the number of scanned rows.
-
Manual request routing: If your OLTP and OLAP workloads access the database from different applications, you can configure different cluster endpoints for these applications. Then, you can route requests to row and column stores by assigning read-only IMCI nodes and read-only row store nodes to the service nodes of different endpoints.
Automatic request routing
On the cluster details page, go to the Database Connections section. For the Cluster Endpoint, set Service Node to Enable.
-
Changes toService Nodetake effect only for new connections. Reconnect to the cluster after you make the change.
-
If you connect to the cluster using DMS, note that DMS uses the Primary address by default. You must manually use the cluster endpoint to connect to the PolarDB cluster.
-
The default estimated execution cost threshold for automatic request routing is 50,000 scanned rows. You can adjust this parameter based on your business requirements.
Manual request routing
On the cluster details page, go to the Database Connections section and create a custom endpoint. Ensure that the Service Node include only Service Node.
Step 3: Add an IMCI
You can add IMCIs to your tables manually or automatically based on your business requirements.
For a query to be accelerated by IMCI, all columns referenced in the SQL statement must be fully covered by an IMCI.
Manual
IMCI provides a full set of DDL statements to add or remove IMCI for business tables. Choose the option that fits your needs:
|
DDL syntax |
Example |
|
|
|
|
|
Add or remove IMCIs at the database or table level in batches |
|
-
When you add an IMCI, you can preserve existing comments. Example:
ALTER TABLE <table_name> COMMENT 'COLUMNAR=1 <original comment>';. -
By default, when you add an IMCI in batches at the database or table level, the table comment is updated to
'COLUMNAR=1 <original comment>'.
Automatic
The AutoIndex feature can automatically create IMCIs based on your slow queries to significantly improve their execution speed. This eliminates the need to understand and tune each slow query. As the application workload changes, AutoIndex continuously monitors and adjusts the IMCI strategy to ensure that your PolarDB cluster maintains optimal performance.
You can experience the benefits of this feature by simply Enable AutoIndex on the PolarDB cluster details page:

(Optional) Step 4: Check IMCI build progress
After you manually add an IMCI, check its build progress. Wait for the build to complete to benefit from query acceleration.
SELECT * FROM INFORMATION_SCHEMA.IMCI_ASYNC_DDL_STATS;
Example: Check whether the value in the STATUS column is Safe to read to confirm that the IMCI is fully built.
+-------------+------------+---------------------+---------------------+---------------------+--------------+------------------+-----------------+-------------+-------------+-------------+------------+--------------+-----------+-------------------+-----------------+
| SCHEMA_NAME | TABLE_NAME | CREATED_AT | STARTED_AT | FINISHED_AT | STATUS | APPROXIMATE_ROWS | SCANNED_ROWS | SCAN_SECOND | SORT_ROUNDS | SORT_SECOND | BUILD_ROWS | BUILD_SECOND | AVG_SPEED | SPEED_LAST_SECOND | ESTIMATE_SECOND |
+-------------+------------+---------------------+---------------------+---------------------+--------------+------------------+-----------------+-------------+-------------+-------------+------------+--------------+-----------+-------------------+-----------------+
| tpch | lineitem | 2024-10-21 13:44:02 | 2024-10-21 13:44:02 | 2024-10-21 13:50:11 | Safe to read | 590446240 | 600037902(100%) | 369 | 0 | 0 | 0(0%) | 0 | 1625058 | 0 | 0 |
+-------------+------------+---------------------+---------------------+---------------------+--------------+------------------+-----------------+-------------+-------------+-------------+------------+--------------+-----------+-------------------+-----------------+
1 row in set, 1 warning (0.00 sec)
(Optional) Step 5: Check for IMCI usage
An IMCI execution plan is displayed as a horizontal tree, which has a distinctly different format from a row-store execution plan. You can use the EXPLAIN statement to view the execution plan and determine whether a SQL statement can be accelerated by IMCI. The following examples show the difference:
IMCI execution plan
+----+----------------------------+----------+--------+--------+-----------------------------------------------------------------------------+
| ID | Operator | Name | E-Rows | E-Cost | Extra Info |
+----+----------------------------+----------+--------+--------+-----------------------------------------------------------------------------+
| 1 | Select Statement | | | | IMCI Execution Plan (max_dop = 4, max_query_mem = 858993459) |
| 2 | └─Sort | | | | Sort Key: revenue DESC,o_orderdate ASC |
| 3 | └─Hash Groupby | | | | Group Key: (lineitem.L_ORDERKEY, orders.O_ORDERDATE, orders.O_SHIPPRIORITY) |
| 4 | └─Hash Join | | | | Join Cond: orders.O_ORDERKEY = lineitem.L_ORDERKEY |
| 5 | ├─Hash Join | | | | Join Cond: customer.C_CUSTKEY = orders.O_CUSTKEY |
| 6 | │ ├─Table Scan | customer | | | Cond: (C_MKTSEGMENT = "BUILDING") |
| 7 | │ └─Table Scan | orders | | | Cond: (O_ORDERDATE < 03/24/1995) |
| 8 | └─Table Scan | lineitem | | | Cond: (L_SHIPDATE > 03/24/1995) |
+----+----------------------------+----------+--------+--------+-----------------------------------------------------------------------------+
8 rows in set (0.01 sec)
Row-store execution plan
+----+-------------+----------+------------+------+--------------------+------------+---------+-----------------------------+--------+----------+----------------------------------------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+-------------+----------+------------+------+--------------------+------------+---------+-----------------------------+--------+----------+----------------------------------------------+
| 1 | SIMPLE | customer | NULL | ALL | PRIMARY | NULL | NULL | NULL | 147630 | 10.00 | Using where; Using temporary; Using filesort |
| 1 | SIMPLE | orders | NULL | ref | PRIMARY,ORDERS_FK1 | ORDERS_FK1 | 4 | tpch100g.customer.C_CUSTKEY | 14 | 33.33 | Using where |
| 1 | SIMPLE | lineitem | NULL | ref | PRIMARY | PRIMARY | 4 | tpch100g.orders.O_ORDERKEY | 4 | 33.33 | Using where |
+----+-------------+----------+------------+------+--------------------+------------+---------+-----------------------------+--------+----------+----------------------------------------------+
3 rows in set, 1 warning (0.00 sec)
Helper tools
When you use IMCI to query complex SQL statements, you must check whether any columns in the SQL statement are not covered by an IMCI. If you find uncovered columns, you can get the DDL statements to create an IMCI for the SQL statement, or batch-get the DDL statements to create IMCIs for a specific workload. After running the DDL statements, ensure all columns referenced in the SQL statement are covered by an IMCI to enable query acceleration.
PolarDB provides the following built-in stored procedures:
-
Check whether any columns in a SQL statement are not covered by an IMCI:
dbms_imci.check_columnar_index('<query_string>');. -
Get the DDL statements to create an IMCI:
dbms_imci.columnar_advise('<query_string>');anddbms_imci.columnar_advise_by_columns('<query_string>');. -
Batch-get the DDL statements to create IMCIs:
dbms_imci.columnar_advise_begin();,dbms_imci.columnar_advise_show();, anddbms_imci.columnar_advise_end();.
FAQ
For more information, see IMCI FAQ.
Advanced usage
See the following topics to optimize your use of IMCI.
|
Advanced feature |
Description |
|
IMCI organizes data into row groups. In each row group, different columns are packed into column data blocks. These blocks are built in parallel based on the primary key order of the original row-based data, which results in an overall unordered state. You can configure a sort key to reorder the column data blocks and improve query performance. |
|
|
IMCI integrates a set of features such as columnar JSON, virtual columns, Instant DDL, and column count expansion to handle large-scale structured and semi-structured data analytics. |
|
|
The Extract, Transform, Load (ETL) feature lets you use IMCI on a read-write (RW) node. |
|
|
The Serverless feature automatically scales resources up and down based on your workload. It scales up during peak hours to handle workload spikes, and scales down during off-peak hours to reduce costs. |
|
|
A Hybrid Plan uses both column and row indexes in the same query. Hybrid Plan can significantly improve wide table query performance. In the execution plan, parts that benefit from column indexes are run on IMCI and produce intermediate results that contain only primary keys. Then, the required columns are fetched and returned by using the primary keys with the InnoDB primary index. |
|
|
For complex queries on massive data, a single read-only IMCI node may not meet performance requirements. You can use multi-node parallel processing (MPP) to accelerate queries. |
Learn more
To learn more about the principles behind IMCI, see the following documents:
-
PolarDB In-Memory Column Index (IMCI) paper published in SIGMOD 2023