Overview
Indexes are critical for query performance in the TiendaRopa database. This page documents all indexes defined in the schema, their purposes, and which queries benefit from them.Index Strategy
The database uses a combination of:- Primary key indexes for unique identification
- Foreign key indexes for join performance
- Composite indexes for multi-column queries
- Single-column indexes for common search patterns
- Unique indexes for data integrity
Primary Key Indexes
All tables have primary key indexes for unique row identification and fast lookups.actualizacion Table
- Fast lookup of specific price updates
- Ensures no duplicate update records
- Enables efficient joins when querying update history
categoria Table
- Fast joins with
prendatable - Quick category lookups by ID
color Table
- Fast joins with
prendatable - Quick color lookups by ID
empleado Table
- Fast joins with
actualizacion,movimiento_stock, andregistro - Quick employee lookups by ID
movimiento_stock Table
- Fast lookup of specific stock movements
- Ensures no duplicate movement records
prenda Table
- Fast garment lookups by ID
- Enables efficient joins with all operational tables
- Core index for most database queries
proveedor Table
- Fast joins with
registrotable - Quick supplier lookups by ID
registro Table
- Fast lookup of specific registrations
- Ensures no duplicate registration records
talla Table
- Fast joins with
prendatable - Quick size lookups by ID
Foreign Key Indexes
Indexes on foreign key columns improve join performance and referential integrity checks.actualizacion Foreign Key Indexes
fk_act_prenda: Find all price updates for a specific garmentfk_act_emp: Find all price updates performed by a specific employee
movimiento_stock Foreign Key Indexes
fk_mov_prenda: Find all stock movements for a specific garmentfk_mov_emp: Find all stock movements performed by a specific employee
prenda Foreign Key Indexes
fk_prenda_talla: Find all garments of a specific sizefk_prenda_color: Find all garments of a specific color
registro Foreign Key Indexes
fk_reg_prenda: Find registration records for a specific garmentfk_reg_emp: Find all registrations performed by a specific employeefk_reg_prov: Find all garments supplied by a specific supplier
Special Purpose Indexes
These indexes optimize specific query patterns and business operations.Date-Based Queries: idx_movimiento_fecha
Name Search: idx_prenda_nombre
LIKE 'prefix%') but not infix searches (LIKE '%substring%').
Composite Index: idx_prenda_cat_talla
id_categoria first, then id_talla. This means:
- Queries filtering by
id_categoriaalone can use this index - Queries filtering by
id_tallaalone cannot use this index efficiently - Queries filtering by both columns get optimal performance
Unique Indexes
Unique indexes enforce data integrity constraints beyond primary keys.proveedor Telephone Uniqueness
- Prevents duplicate supplier entries
- Fast lookups by phone number
- Data integrity enforcement at the database level
Index Maintenance
Automatic Maintenance
MariaDB/MySQL automatically maintains indexes when:- Inserting new rows
- Updating indexed columns
- Deleting rows
Performance Considerations
Indexes improve:- SELECT queries with WHERE clauses on indexed columns
- JOIN operations on indexed foreign keys
- ORDER BY clauses on indexed columns
- GROUP BY operations on indexed columns
- INSERT operations (must update all indexes)
- UPDATE operations on indexed columns
- DELETE operations (must update all indexes)
Best Practices
- Use indexes for frequent queries - The indexes in this schema are optimized for common operations
- Foreign keys are automatically indexed - All FK columns have indexes for join performance
- Composite indexes follow query patterns -
idx_prenda_cat_tallamatches common search criteria - Date indexes for time-based queries -
idx_movimiento_fechaoptimizes reports and audits
Query Performance Tips
Leveraging Indexes Effectively
Good: Uses idx_prenda_cat_tallaAnalyzing Query Performance
Use EXPLAIN to verify index usage:type: refortype: range(good - using index)type: ALL(bad - full table scan)key: idx_prenda_cat_talla(confirms index usage)
Related Pages
- Database Schema - Complete schema structure
- Database Relationships - Foreign key relationships
- Tables Reference - Detailed table documentation