Buenas! 🙂

Uma das atividades que mais demandam tempo, tato, expertise, xícaras de café, lágrimas, diálogo, consultas com o terapeuta, enfim… é o Tuning.

Com várias solicitações, e a obrigação de aprender o dito, resolvi documentar essa cruzada.

Quem sabe esse manual não é útil para algum de vocês que nos acompanham…

Não sou o dono da verdade, e o conteúdo aqui é baseado no meu entendimento de tuning e em materiais que estão disponíveis na internet. Todo material utilizado aqui será creditado.

Traduzindo Tuning…

O que é tuning?
– Basicamente é eliminar CUSTO desnecessário;
– Pode ser alcançado de diversos modos: criação de index, alteração de parâmetro, remodelagem, estatística, reescrita do SQL;

Planos de execução
– Atividades de manipulação ou consulta a dados previamente criam um plano de execução, o caminho mais fácil que o otimizador acredita percorrer para alcançar o resultado;
– O oracle nem sempre escolhe o melhor plano;
– Força-se um plano diferente utilizando o ‘HINT‘;

Gerando um plano de execução: (utilizando o ‘schema sample’ SCOTT que pode ser instalado junto com o banco)

[et_pb_dmb_code_snippet _builder_version=”4.0.6″ code=”ZGVsZXRlIHBsYW5fdGFibGU7CmNvbW1pdDsKCkVYUExBSU4gUExBTiBGT1IKU0VMRUNUICoKRlJPTSAgIHNjb3R0LmVtcCBlLCBzY290dC5kZXB0IGQKV0hFUkUgIGUuZGVwdG5vID0gZC5kZXB0bm8KQU5EICAgIGUuZW5hbWUgID0gJ1NNSVRIJzsKCkVYUExBSU4gUExBTiBzdWNjZWVkZWQuCgpzZWxlY3QgcGxhbl90YWJsZV9vdXRwdXQgZnJvbSB0YWJsZShkYm1zX3hwbGFuLmRpc3BsYXkoJ3BsYW5fdGFibGUnLG51bGwsJ3NlcmlhbCcpKTsKUExBTl9UQUJMRV9PVVRQVVQgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCi0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS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