tencent cloud

TDSQL for MySQL

Announcements
Alarm Upgrade
Product Introduction
Overview
Strengths
Use Cases
Regions and AZs
InnoDB engine
Purchase Guide
Billing Overview (InnoDB)
Product Pricing (InnoDB)
Purchase and Upgrade
Refund
Payment Overdue
Backup Space Billing
Getting Started
InnoDB Engine
Operation Guide(InnoDB)
Instance Management
Disaster Recovery Read-Only Instance
Changing Networks
Account Management
Security Management
Slow Query Analysis
Backup and Rollback
Data Migration
Database Audit
Practical Tutorial
Import from Standalone Instance to TDSQL Instance
Import Between TDSQL Instances
Selection of TDSQL Instance and Shard Configuration
Security White Paper
Platform Security Design
Tenant Security Features
Development Guide
InnoDB
API Documentation
History
Introduction
API Category
Security Group APIs
Other APIs
Making API Requests
TDSQL APIs
Data Types
Error Codes
FAQs
InnoDB
General References
Performance Comparison Data for Strong Sync
Glossary
Contact Us

Managing Sharded Table

PDF
フォーカスモード
フォントサイズ
最終更新日: 2024-01-06 17:33:30
This document describes how to perform simple database operations on a sharded table.

Creating a table

For the specific differences among sharded, non-sharded, and broadcast tables, see Overview.
For the restrictions on selecting the shardkey, see Creating Tables.
You need the specify the shardkey when creating a sharded table. Below is the sample code:
mysql> create table test1(id int primary key,name varchar(20),addr varchar(20))shardkey=id;
Query OK,0 rows affected(0.15 sec)

Inserting data

Note:
The insert field must contain a shardkey; otherwise, the statement will be rejected.
Insert data to the newly created table. Below is the sample code:
mysql> insert into test1(id,name) VALUES(1,'test');
Query OK,1 rows affected(0.08 sec)
mysql> insert into test3(name,addr) values('example','shenzhen');
ERROR 7013 (HY000): Proxy ERROR:get_shardkeys return error

Querying data

Note:
We recommend that you carry a shardkey when querying data, so that the corresponding shard will be automatically redirected to through distributed routing, delivering the highest efficiency; otherwise, the distributed system will automatically perform a full-table scan and aggregate the results on the gateway, which is less efficient.
Below is the sample code for data query:
mysql> select id from test1 where id=1;

Deleting data

Note:
The delete field must contain a WHERE condition. We recommend that you include the shardkey in the WHERE condition.
Below is the sample code for data deletion:
mysql> delete from test1 where id=1;
Query OK, 1 row affected (0.02 sec)

ヘルプとサポート

この記事はお役に立ちましたか?

フィードバック