You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
3.4 KiB
81 lines
3.4 KiB
-- 数据库索引创建脚本
|
|
-- 此脚本用于优化应用性能,为常用查询字段创建索引
|
|
|
|
-- ============================================
|
|
-- 用户相关表索引
|
|
-- ============================================
|
|
|
|
-- users表索引
|
|
CREATE INDEX IF NOT EXISTS idx_users_userId ON users(userId);
|
|
CREATE INDEX IF NOT EXISTS idx_users_phoneNumber ON users(phoneNumber);
|
|
CREATE INDEX IF NOT EXISTS idx_users_type ON users(type);
|
|
CREATE INDEX IF NOT EXISTS idx_users_level ON users(level);
|
|
CREATE INDEX IF NOT EXISTS idx_users_created_at ON users(created_at);
|
|
|
|
-- ============================================
|
|
-- 管理员相关表索引
|
|
-- ============================================
|
|
|
|
-- managers表索引
|
|
CREATE INDEX IF NOT EXISTS idx_managers_id ON managers(id);
|
|
CREATE INDEX IF NOT EXISTS idx_managers_userName ON managers(userName);
|
|
CREATE INDEX IF NOT EXISTS idx_managers_managerId ON managers(managerId);
|
|
CREATE INDEX IF NOT EXISTS idx_managers_organization ON managers(organization);
|
|
CREATE INDEX IF NOT EXISTS idx_managers_managerdepartment ON managers(managerdepartment);
|
|
|
|
-- ============================================
|
|
-- 用户管理相关表索引
|
|
-- ============================================
|
|
|
|
-- usermanagements表索引
|
|
CREATE INDEX IF NOT EXISTS idx_usermanagements_userId ON usermanagements(userId);
|
|
CREATE INDEX IF NOT EXISTS idx_usermanagements_managerId ON usermanagements(managerId);
|
|
CREATE INDEX IF NOT EXISTS idx_usermanagements_userName ON usermanagements(userName);
|
|
CREATE INDEX IF NOT EXISTS idx_usermanagements_organization ON usermanagements(organization);
|
|
CREATE INDEX IF NOT EXISTS idx_usermanagements_managerdepartment ON usermanagements(managerdepartment);
|
|
|
|
-- ============================================
|
|
-- 产品相关表索引
|
|
-- ============================================
|
|
|
|
-- products表索引
|
|
CREATE INDEX IF NOT EXISTS idx_products_sellerId ON products(sellerId);
|
|
CREATE INDEX IF NOT EXISTS idx_products_created_at ON products(created_at);
|
|
|
|
-- ============================================
|
|
-- 购物车相关表索引
|
|
-- ============================================
|
|
|
|
-- cart_items表索引
|
|
CREATE INDEX IF NOT EXISTS idx_cart_items_userId ON cart_items(userId);
|
|
CREATE INDEX IF NOT EXISTS idx_cart_items_productId ON cart_items(productId);
|
|
|
|
-- ============================================
|
|
-- 企业相关表索引
|
|
-- ============================================
|
|
|
|
-- enterprise表索引 (假设存在)
|
|
CREATE INDEX IF NOT EXISTS idx_enterprise_id ON enterprise(id);
|
|
CREATE INDEX IF NOT EXISTS idx_enterprise_name ON enterprise(name);
|
|
|
|
-- ============================================
|
|
-- 联系方式相关表索引
|
|
-- ============================================
|
|
|
|
-- contacts表索引
|
|
CREATE INDEX IF NOT EXISTS idx_contacts_userId ON contacts(userId);
|
|
|
|
-- ============================================
|
|
-- 注意事项
|
|
-- ============================================
|
|
-- 1. 此脚本使用IF NOT EXISTS语法,可重复执行而不会报错
|
|
-- 2. 索引创建会占用额外的磁盘空间,提高写操作开销,但显著提升查询性能
|
|
-- 3. 建议在低峰期执行此脚本
|
|
-- 4. 执行后建议监控应用性能,确认优化效果
|
|
-- 5. 对于MySQL数据库,索引创建命令可能略有不同
|
|
-- ============================================
|
|
|
|
-- MySQL版本的部分索引创建语法示例(仅供参考)
|
|
-- ALTER TABLE users ADD INDEX idx_users_userId (userId);
|
|
-- ALTER TABLE users ADD INDEX idx_users_phoneNumber (phoneNumber);
|
|
-- 以此类推...
|