update 优化 对数据库表常用字段增加索引 提高查询效率

This commit is contained in:
疯狂的狮子Li
2026-04-09 10:46:57 +08:00
parent 563a397033
commit 9c25addb46
4 changed files with 74 additions and 6 deletions

View File

@@ -89,6 +89,8 @@ create table sys_dept (
alter table sys_dept add constraint pk_sys_dept primary key (dept_id);
create index idx_sys_dept_parent_id on sys_dept (parent_id);
comment on table sys_dept is '部门表';
comment on column sys_dept.dept_id is '部门id';
comment on column sys_dept.parent_id is '父部门id';
@@ -151,6 +153,11 @@ create table sys_user (
alter table sys_user add constraint pk_sys_user primary key (user_id);
create index idx_sys_user_dept_id on sys_user (dept_id);
create index idx_sys_user_create_by on sys_user (create_by);
create index idx_sys_user_user_name on sys_user (user_name);
create index idx_sys_user_phone on sys_user (phone_number);
comment on table sys_user is '用户信息表';
comment on column sys_user.user_id is '用户ID';
comment on column sys_user.dept_id is '部门ID';
@@ -201,6 +208,8 @@ create table sys_post (
alter table sys_post add constraint pk_sys_post primary key (post_id);
create index idx_sys_post_dept_id on sys_post (dept_id);
comment on table sys_post is '岗位信息表';
comment on column sys_post.post_id is '岗位ID';
comment on column sys_post.dept_id is '部门id';
@@ -248,6 +257,9 @@ create table sys_role (
alter table sys_role add constraint pk_sys_role primary key (role_id);
create index idx_sys_role_create_dept on sys_role (create_dept);
create index idx_sys_role_create_by on sys_role (create_by);
comment on table sys_role is '角色信息表';
comment on column sys_role.role_id is '角色ID';
comment on column sys_role.role_name is '角色名称';
@@ -472,6 +484,8 @@ create table sys_user_role (
alter table sys_user_role add constraint pk_sys_user_role primary key (user_id, role_id);
create index idx_sys_user_role_rid on sys_user_role (role_id);
comment on table sys_user_role is '用户和角色关联表';
comment on column sys_user_role.user_id is '用户ID';
comment on column sys_user_role.role_id is '角色ID';
@@ -777,6 +791,8 @@ create table sys_dict_data (
alter table sys_dict_data add constraint pk_sys_dict_data primary key (dict_code);
create index idx_sys_dict_data_type on sys_dict_data (dict_type);
comment on table sys_dict_data is '字典数据表';
comment on column sys_dict_data.dict_code is '字典主键';
comment on column sys_dict_data.dict_sort is '字典排序';

View File

@@ -88,6 +88,8 @@ create table if not exists sys_dept
constraint "sys_dept_pk" primary key (dept_id)
);
create index idx_sys_dept_parent_id ON sys_dept (parent_id);
comment on table sys_dept is '部门表';
comment on column sys_dept.dept_id is '部门ID';
comment on column sys_dept.parent_id is '父部门ID';
@@ -148,6 +150,11 @@ create table if not exists sys_user
constraint "sys_user_pk" primary key (user_id)
);
create index idx_sys_user_dept_id ON sys_user (dept_id);
create index idx_sys_user_create_by ON sys_user (create_by);
create index idx_sys_user_user_name ON sys_user (user_name);
create index idx_sys_user_phone ON sys_user (phone_number);
comment on table sys_user is '用户信息表';
comment on column sys_user.user_id is '用户ID';
comment on column sys_user.dept_id is '部门ID';
@@ -199,6 +206,8 @@ create table if not exists sys_post
constraint "sys_post_pk" primary key (post_id)
);
create index idx_sys_post_dept_id ON sys_post (dept_id);
comment on table sys_post is '岗位信息表';
comment on column sys_post.post_id is '岗位ID';
comment on column sys_post.dept_id is '部门id';
@@ -245,6 +254,9 @@ create table if not exists sys_role
constraint "sys_role_pk" primary key (role_id)
);
create index idx_sys_role_create_dept ON sys_role (create_dept);
create index idx_sys_role_create_by ON sys_role (create_by);
comment on table sys_role is '角色信息表';
comment on column sys_role.role_id is '角色ID';
comment on column sys_role.role_name is '角色名称';
@@ -469,6 +481,8 @@ create table if not exists sys_user_role
constraint sys_user_role_pk primary key (user_id, role_id)
);
create index idx_sys_user_role_rid ON sys_user_role (role_id);
comment on table sys_user_role is '用户和角色关联表';
comment on column sys_user_role.user_id is '用户ID';
comment on column sys_user_role.role_id is '角色ID';
@@ -774,6 +788,8 @@ create table if not exists sys_dict_data
constraint sys_dict_data_pk primary key (dict_code)
);
create index idx_sys_dict_data_type ON sys_dict_data (dict_type);
comment on table sys_dict_data is '字典数据表';
comment on column sys_dict_data.dict_code is '字典编码';
comment on column sys_dict_data.dict_sort is '字典排序';

View File

@@ -54,7 +54,8 @@ create table sys_dept (
create_time datetime comment '创建时间',
update_by bigint(20) default null comment '更新者',
update_time datetime comment '更新时间',
primary key (dept_id)
primary key (dept_id),
key idx_sys_dept_parent_id (parent_id)
) engine=innodb comment = '部门表';
-- ----------------------------
@@ -98,7 +99,11 @@ create table sys_user (
update_by bigint(20) default null comment '更新者',
update_time datetime comment '更新时间',
remark varchar(500) default null comment '备注',
primary key (user_id)
primary key (user_id),
key idx_sys_user_dept_id (dept_id),
key idx_sys_user_create_by (create_by),
key idx_sys_user_user_name (user_name),
key idx_sys_user_phone (phone_number)
) engine=innodb comment = '用户信息表';
-- ----------------------------
@@ -126,7 +131,8 @@ create table sys_post
update_by bigint(20) default null comment '更新者',
update_time datetime comment '更新时间',
remark varchar(500) default null comment '备注',
primary key (post_id)
primary key (post_id),
key idx_sys_post_dept_id (dept_id)
) engine=innodb comment = '岗位信息表';
-- ----------------------------
@@ -157,7 +163,9 @@ create table sys_role (
update_by bigint(20) default null comment '更新者',
update_time datetime comment '更新时间',
remark varchar(500) default null comment '备注',
primary key (role_id)
primary key (role_id),
key idx_sys_role_create_dept (create_dept),
key idx_sys_role_create_by (create_by)
) engine=innodb comment = '角色信息表';
-- ----------------------------
@@ -338,7 +346,8 @@ insert into sys_menu values(1761400000000001511, '测试树表导出', 176140000
create table sys_user_role (
user_id bigint(20) not null comment '用户ID',
role_id bigint(20) not null comment '角色ID',
primary key(user_id, role_id)
primary key(user_id, role_id),
key idx_sys_user_role_rid (role_id)
) engine=innodb comment = '用户和角色关联表';
-- ----------------------------
@@ -587,7 +596,8 @@ create table sys_dict_data
update_by bigint(20) default null comment '更新者',
update_time datetime comment '更新时间',
remark varchar(500) default null comment '备注',
primary key (dict_code)
primary key (dict_code),
key idx_sys_dict_data_type (dict_type)
) engine=innodb comment = '字典数据表';
insert into sys_dict_data values(1761600000000000001, 1, '', '0', 'sys_user_gender', '', '', 'Y', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '性别男');

View File

@@ -683,6 +683,9 @@ CREATE TABLE sys_dept
ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX idx_sys_dept_parent_id ON sys_dept (parent_id)
GO
EXEC sys.sp_addextendedproperty
'MS_Description', N'部门id' ,
'SCHEMA', N'dbo',
@@ -829,6 +832,9 @@ CREATE TABLE sys_dict_data
ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX idx_sys_dict_data_type ON sys_dict_data (dict_type)
GO
EXEC sys.sp_addextendedproperty
'MS_Description', N'字典编码' ,
'SCHEMA', N'dbo',
@@ -2019,6 +2025,9 @@ CREATE TABLE sys_post
ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX idx_sys_post_dept_id ON sys_post (dept_id)
GO
EXEC sys.sp_addextendedproperty
'MS_Description', N'岗位ID' ,
'SCHEMA', N'dbo',
@@ -2136,6 +2145,11 @@ CREATE TABLE sys_role
ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX idx_sys_role_create_dept ON sys_role (create_dept)
GO
CREATE NONCLUSTERED INDEX idx_sys_role_create_by ON sys_role (create_by)
GO
EXEC sys.sp_addextendedproperty
'MS_Description', N'角色ID' ,
'SCHEMA', N'dbo',
@@ -2566,6 +2580,15 @@ CREATE TABLE sys_user
ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX idx_sys_user_dept_id ON sys_user (dept_id)
GO
CREATE NONCLUSTERED INDEX idx_sys_user_create_by ON sys_user (create_by)
GO
CREATE NONCLUSTERED INDEX idx_sys_user_user_name ON sys_user (user_name)
GO
CREATE NONCLUSTERED INDEX idx_sys_user_phone ON sys_user (phone_number)
GO
EXEC sys.sp_addextendedproperty
'MS_Description', N'用户ID' ,
'SCHEMA', N'dbo',
@@ -2742,6 +2765,9 @@ CREATE TABLE sys_user_role
ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX idx_sys_user_role_rid ON sys_user_role (role_id)
GO
EXEC sys.sp_addextendedproperty
'MS_Description', N'用户ID' ,
'SCHEMA', N'dbo',