当前位置:网站首页>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 .
边栏推荐
- Product manager experience 100 (XI) - Strategic Product Manager: model and methodology
- eBPF/Ftrace
- 以科技传递温度,vivo亮相数字中国建设峰会
- Design of network abnormal traffic analysis system
- Redis summary: cache avalanche, cache breakdown, cache penetration and cache preheating, cache degradation
- 汇量科技app出海好地:火了十几年,美国凭什么还是出海首选淘金地
- Additional: [urlencoder.encode (string to be encoded, "encoding method");] (what is it?; why do we use this to encode when we set values in cookies?) (to be improved...)
- SwiftUI 地图大全之 使用 MapKit 进行搜索
- 2. Citrix virtual apps and desktops 2203 clipboard redirection policy
- Unapp prevents continuous click errors
猜你喜欢

Seata's landing practice in ant International Banking

52:第五章:开发admin管理服务:5:开发【分页查询admin账号列表,接口】;(Swagger的@ApiParam(),对方法参数进行注释;PageHelper分页插件;拦截器拦截检查登录状态)

Design of network abnormal traffic analysis system

JS divides the array into two-dimensional arrays according to the specified attribute values

JS module, closure application

leetcode——83,24;机器学习——神经网络

腾讯云联合中国工联院发布工业AI质检标准化研究成果加速制造业智能化转型
![51: Chapter 5: develop admin management services: 4: develop [add admin account, interface]; (only [user name + password, method]; [@t...] annotation controls transactions; when setting cookies, do yo](/img/6f/4f93eca1d923a58b2ef4b1947538be.png)
51: Chapter 5: develop admin management services: 4: develop [add admin account, interface]; (only [user name + password, method]; [@t...] annotation controls transactions; when setting cookies, do yo

Use recyclerview to realize the left sliding menu of the list

电气成套企业如何借助ERP系统,做好成本利润管理?
随机推荐
【基础知识】~ 集成电路设计流程,以及各阶段所使用的EDA工具
Jianzhi offer 07 rebuild binary tree -- construct binary tree from middle order and post order traversal sequence
Redis summary: cache avalanche, cache breakdown, cache penetration and cache preheating, cache degradation
Come and watch, 17 practical skills of operation and maintenance~
Fixed positioning
SQL教程之 SQL 聚合函数入门教程
Seata 在蚂蚁国际银行业务的落地实践
汇量科技app出海好地:火了十几年,美国凭什么还是出海首选淘金地
v-show
7.26 simulation summary
Icon Font
Fiddler bag capturing Tool + night God simulator
【C进阶】指针数组 VS 数组指针
Deliver temperature with science and technology, vivo appears at the digital China Construction Summit
期货公司开户后续会有哪些服务?
MySQL高可用实战方案——MHA
SwiftUI 地图大全之 使用 MapKit 进行搜索
[2023 Fudan Microelectronics written examination questions in advance] ~ questions and reference answers
Fiddler抓包工具+夜神模拟器
Construction and application of industrial knowledge atlas (2): representation and modeling of commodity knowledge