当前位置:网站首页>Add index to the field of existing data (Damon database version)
Add index to the field of existing data (Damon database version)
2022-07-27 13:45:00 【laizhenghua】
Add an index to the field of existing data
For fields with existing data , Some databases do not support adding indexes directly , Even if it supports a large amount of data, adding indexes directly is still easy to cause various problems , The safety factor is not high ... So I encounter this kind of scene , The more conservative way is to create exactly the same temporary table , First, add indexes to the fields of the temporary table that need to be indexed , Then insert the data into the temporary table , Finally, rename the temporary table to the original table . Temporary tables can be deleted or not , Data can also be backed up .
Example ( Need to give TB_EXCHANGE_LOG Tabular DATATYPE、STATE、PRIMARYID Add index to field ):
1、 Export table creation statement , Execute the table creation statement after modifying the table name , for example
# I am used to adding temp
CREATE TABLE LN.TB_EXCHANGE_LOG_TEMP (
ID NUMBER(38,0),
XZQHDM VARCHAR2(512),
PRIMARYID VARCHAR2(512),
DATATYPE NUMBER(38,0),
DATANAME VARCHAR2(200),
REMARK VARCHAR2(100),
STATE NUMBER(38,0),
CREATETIME TIMESTAMP,
PID VARCHAR(100),
DESTINATION VARCHAR(100)
);
2、 Add indexes to the fields of the temporary table , for example
# Index naming conventions recommendations IDX1_ Field name IDX2_ Field name Adding the table name can avoid duplicate Index Names
CREATE INDEX IDX1_DATATYPE ON LN.TB_EXCHANGE_LOG_TEMP(DATATYPE) TABLESPACE LN;
CREATE INDEX IDX2_STATE ON LN.TB_EXCHANGE_LOG_TEMP(STATE) TABLESPACE LN;
CREATE INDEX IDX3_PRIMARYID ON LN.TB_EXCHANGE_LOG_TEMP(PRIMARYID) TABLESPACE LN;
3、 Insert the data of the formal table into the temporary table , for example
INSERT INTO LN.TB_EXCHANGE_LOG_TEMP(ID, XZQHDM, PRIMARYID, DATATYPE, DATANAME, REMARK,
STATE, CREATETIME, PID, DESTINATION) SELECT ID, XZQHDM, PRIMARYID, DATATYPE, DATANAME, REMARK,
STATE, CREATETIME, PID, DESTINATION FROM LN.TB_EXCHANGE_LOG;
4、 Compare the number of records in the temporary table and the formal table , for example
SELECT COUNT(*) FROM LN.TB_EXCHANGE_LOG_TEMP;
SELECT COUNT(*) FROM LN.TB_EXCHANGE_LOG;
5、 Change the temporary table name to the formal table name
ALTER TABLE TB_EXCHANGE_LOG RENAME TO TB_EXCHANGE_LOG1;
ALTER TABLE TB_EXCHANGE_LOG_TEMP RENAME TO TB_EXCHANGE_LOG;
ALTER TABLE TB_EXCHANGE_LOG1 RENAME TO TB_EXCHANGE_LOG_TEMP;
OK, perfect .
边栏推荐
- Arrays and functions of knowledge in every corner of C language
- 滑环设备怎么进行维护
- Adhesive positioning
- Qt剪切板QClipboard 复制粘贴自定义数据
- 双料第一!
- 2022ACM夏季集训周报(四)
- MFC FTP creates multi-level folders and uploads files to the specified directory of FTP
- Rotation chart
- Intranet penetration based on FRP -- SSH Remote connection to intranet server with the help of public server
- Seata 在蚂蚁国际银行业务的落地实践
猜你喜欢

责任链模式在转转精准估价中的应用
![[300 + selected interview questions from big companies continued to share] big data operation and maintenance sharp knife interview question column (IX)](/img/cf/44b3983dd5d5f7b92d90d918215908.png)
[300 + selected interview questions from big companies continued to share] big data operation and maintenance sharp knife interview question column (IX)

【C进阶】指针数组 VS 数组指针

leetcode——83,24; Machine learning - neural networks

滑环使用如何固定

SCI thesis writing

附加:【URLEncoder.encode(待编码字符串, “编码方式“);】(是什么?;我们向cookie中设置值的时候,为什么要使用这个去编码?)(待完善……)

Training in the second week of summer vacation on July 24, 2022

3D laser slam:aloam---ceres optimization part and code analysis

Vertical and horizontal shooting range - the mystery of the picture
随机推荐
V-on basic instruction
Using ebpf to detect rootkit vulnerabilities
Huiliang technology app is a good place to go to sea: after more than ten years of popularity, why should the United States still choose to go to sea for gold
Can I only use tidb binlog tool to synchronize tidb to MySQL in real time?
Absolute positioning
软考 系统架构设计师 简明教程 | 软件测试
Install the wireless network card driver
MySQL高可用实战方案——MHA
Go语言系列:如何搭建Go语言开发环境?
Getting started for beginners: build your own blog with WordPress
Construction and application of industrial knowledge atlas (2): representation and modeling of commodity knowledge
期货公司开户后续会有哪些服务?
leetcode——83,24; Machine learning - neural networks
3D laser slam:aloam---ceres optimization part and code analysis
使用putty设置基于 SSH 密钥的身份验证
v-show
剑指Offer 07 重建二叉树 -- 从中序与后序遍历序列构造二叉树
52: Chapter 5: developing admin management services: 5: developing [paging query admin account list, interface]; (swagger's @apiparam(), annotate the method parameters; PageHelper paging plug-in; Inte
What are the precautions for using carbon brushes
leetcode——83,24;机器学习——神经网络