Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
On this page

Show all

Case: Setting Partial Cluster Keys

Updated on 2022-08-16 GMT+08:00

You can add PARTIAL CLUSTER KEY(column_name[,...]) to the definition of a column-store table to set one or more columns of this table as partial cluster keys. In this way, each 70 CUs (4.2 million rows) will be sorted based on the cluster keys by default during data import and the value range is narrowed down for each of the new 70 CUs. If the where condition in the query statement contains these columns, the filtering performance will be improved.

  1. Use partial cluster keys.
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    CREATE TABLE lineitem
    (
    L_ORDERKEY    BIGINT NOT NULL
    , L_PARTKEY     BIGINT NOT NULL
    , L_SUPPKEY     BIGINT NOT NULL
    , L_LINENUMBER  BIGINT NOT NULL
    , L_QUANTITY    DECIMAL(15,2) NOT NULL
    , L_EXTENDEDPRICE  DECIMAL(15,2) NOT NULL
    , L_DISCOUNT    DECIMAL(15,2) NOT NULL
    , L_TAX         DECIMAL(15,2) NOT NULL
    , L_RETURNFLAG  CHAR(1) NOT NULL
    , L_LINESTATUS  CHAR(1) NOT NULL
    , L_SHIPDATE    DATE NOT NULL
    , L_COMMITDATE  DATE NOT NULL
    , L_RECEIPTDATE DATE NOT NULL
    , L_SHIPINSTRUCT CHAR(25) NOT NULL
    , L_SHIPMODE     CHAR(10) NOT NULL
    , L_COMMENT      VARCHAR(44) NOT NULL
    )
    with (orientation = column)
    distribute by hash(L_ORDERKEY);
    
    select
    sum(l_extendedprice * l_discount) as revenue
    from
    lineitem
    where
    l_shipdate >= '1994-01-01'::date
    and l_shipdate < '1994-01-01'::date + interval '1 year'
    and l_discount between 0.06 - 0.01 and 0.06 + 0.01
    and l_quantity < 24;
    

    In the where condition, both the l_shipdate and l_quantity columns have a few distinct values, and their values can be used for min/max filtering. Therefore, modify the table definition as follows:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    CREATE TABLE lineitem
    (
    L_ORDERKEY    BIGINT NOT NULL
    , L_PARTKEY     BIGINT NOT NULL
    , L_SUPPKEY     BIGINT NOT NULL
    , L_LINENUMBER  BIGINT NOT NULL
    , L_QUANTITY    DECIMAL(15,2) NOT NULL
    , L_EXTENDEDPRICE  DECIMAL(15,2) NOT NULL
    , L_DISCOUNT    DECIMAL(15,2) NOT NULL
    , L_TAX         DECIMAL(15,2) NOT NULL
    , L_RETURNFLAG  CHAR(1) NOT NULL
    , L_LINESTATUS  CHAR(1) NOT NULL
    , L_SHIPDATE    DATE NOT NULL
    , L_COMMITDATE  DATE NOT NULL
    , L_RECEIPTDATE DATE NOT NULL
    , L_SHIPINSTRUCT CHAR(25) NOT NULL
    , L_SHIPMODE     CHAR(10) NOT NULL
    , L_COMMENT      VARCHAR(44) NOT NULL
    , partial cluster key(l_shipdate, l_quantity)
    )
    with (orientation = column)
    distribute by hash(L_ORDERKEY);
    

    Import the data again and run the query statement. Then, compare the execution time before and after partial cluster keys are used.

    Figure 1 Partial cluster keys not used
    Figure 2 CU loading without partial cluster keys
    Figure 3 Partial cluster keys used
    Figure 4 CU loading with partial cluster keys

    After partial cluster keys are used, the execution time of 5-- CStore Scan on public.lineitem decreases by 1.2s because 84 CUs are filtered out.

  2. Select partial cluster keys.
    • The following data types support cluster keys: character varying(n), varchar(n), character(n), char(n), text, nvarchar2, timestamp with time zone, timestamp without time zone, date, time without time zone, and time with time zone.
    • Smaller number of distinct values in a partial cluster key generates higher filtering performance.
    • Columns that can filter out larger amount of data is preferentially selected as partial cluster keys.
    • If multiple columns are selected as partial cluster keys, the columns are used in sequence to sort data. You are advised to select a maximum of three columns.
  3. Modify parameters to reduce the impact of partial cluster keys on the import performance.

    After partial cluster keys are used, data will be sorted when they are imported, affecting the import performance. If all the data can be sorted in the memory, the keys have little impact on import. If some data cannot be sorted in the memory and is written into a temporary file for sorting, the import performance will be greatly affected.

    The memory used for sorting is specified by the psort_work_mem parameter. You can set it to a larger value so that the sorting has less impact on the import performance.

    The volume of data to be sorted is specified by the PARTIAL_CLUSTER_ROWS parameter of the table. Decreasing the value of this parameter reduces the amount of data to be sorted at a time. PARTIAL_CLUSTER_ROWS is usually used along with the MAX_BATCHROW parameter. The value of PARTIAL_CLUSTER_ROWS must be an integer multiple of the MAX_BATCHROW value. MAX_BATCHROW specifies the maximum number of rows in a CU.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback