-- Índices para melhorar a performance de filtragem e busca de agentes CREATE INDEX IF NOT EXISTS idx_agents_org_unit ON agents(org_unit_id); CREATE INDEX IF NOT EXISTS idx_agents_position ON agents(position_id); CREATE INDEX IF NOT EXISTS idx_agents_functional_situation ON agents(functional_situation); CREATE INDEX IF NOT EXISTS idx_agents_appointment_type ON agents(appointment_type); CREATE INDEX IF NOT EXISTS idx_agents_hire_date ON agents(hire_date); -- Índices para os relacionamentos carregados em lote (Corrigido para nomes de tabela no singular) CREATE INDEX IF NOT EXISTS idx_agent_contract_active ON agent_contract(agent_id) WHERE is_active = true; CREATE INDEX IF NOT EXISTS idx_agent_bank_account_primary ON agent_bank_account(agent_id) WHERE is_primary = true; -- Índices para o módulo de Orçamento CREATE INDEX IF NOT EXISTS idx_budget_execution_line ON budget_execution(budget_line_id); CREATE INDEX IF NOT EXISTS idx_budget_execution_period ON budget_execution(period_id); CREATE INDEX IF NOT EXISTS idx_budget_execution_type ON budget_execution(movement_type); CREATE INDEX IF NOT EXISTS idx_budget_line_fiscal_year ON budget_line(fiscal_year_id);