quando executar

Sempre que o cliente reclamar de problemas de lentidão esse é mais um script que podemos executar para saber se existe algum problema


Firebird


EXECUTE BLOCK AS
DECLARE VARIABLE stmt VARCHAR(1000);
BEGIN
for select 'ALTER INDEX '||rdb$index_name ||' ACTIVE;'
from rdb$indices
where (rdb$system_flag is null or rdb$system_flag = 0 AND rdb$index_inactive=1)
order by rdb$foreign_key nulls first
into :stmt
do EXECUTE STATEMENT :stmt;
END

Em alguns casos é necessário desativar todos os índices para forçar uma reindexação geral, depois de desativa tem que ativar novamente, esse processo é bem demorado.


para desativar, pode usar:

EXECUTE BLOCK AS
DECLARE VARIABLE stmt VARCHAR(1000);
BEGIN
for select 'ALTER INDEX '||rdb$index_name ||' INACTIVE;'
from rdb$indices
where (rdb$system_flag is null or rdb$system_flag = 0 AND rdb$index_inactive=0 AND RDB$INDEX_NAME NOT LIKE 'RDB$%')
order by rdb$foreign_key nulls first
into :stmt
do EXECUTE STATEMENT :stmt;
END

sql server

Select
Comando = 'Alter Index [' + I.name + '] on [' + S.name + '].[' + O.name + '] Rebuild'
Into #Comandos
From sys.indexes I Join sys.objects O on (I.object_id = O.object_id)
Join sys.schemas S on (S.schema_id = O.schema_id)
Where
S.name = 'dbo' and I.type = 2 and i.is_disabled <> 0;

Declare @ComandoAtual VarChar(500) = '';

While (Select Count(*) From #Comandos) > 0
Begin
Select top 1 @ComandoAtual = Comando From #Comandos
Exec (@ComandoAtual)
Delete #Comandos Where (Comando = @ComandoAtual)
End;

Drop Table #Comandos;

  • Sem rótulos