Я пытаюсь найти решение для ускорения запроса, который у меня уже есть. Индексирование нескольких столбцов помогает, но не очень. В настоящее время для достижения всех результатов мне нужно выполнить запрос несколько раз с несколькими вариациями условия where, и это займет всего несколько часов, чтобы выполнить все.
Basi c пример того, чего я пытаюсь достичь:
select
col1
,col2
,...
from table
where <few conditions>
Могу ли я получить результат в col1 от куда и для col2 от куда и некоторых других полей, но не добавив их в условие where? Я знаю, что есть возможность, но я не знаю, как искать пример.
Большое спасибо
Пример того, что я должен сделать сейчас
procedure trigger_reporting
is
type id_tt is table of customers.id%type index by binary_integer;
type org_tt is table of customers.org_nr%type index by binary_integer;
lt_id id_tt;
lt_org org_tt;
l_total pls_integer;
l_res1 pls_integer;
l_res2 pls_integer;
...etc
--Here I just give an example
l_start_date date := '01.02.2020';
l_end_date date := '29.02.2020';
begin
select id, org_nr
into lt_id, lt_org
from customers
where is_active = 1;
if lt_id.count > 0 then
for i in lt_id.first..lt_id.last loop
select count(*)
into l_total
from invoices
where customer_id = lt_id(i)
and orgnr = lt_org(i)
and some_date between l_start_date and l_end_date;
select count(*)
into l_res1
from invoices
where customer_id = lt_id(i)
and orgnr = lt_org(i)
and some_date between l_start_date and l_end_date
and deleted = 0;
select count(*)
into l_res2
from invoices
where customer_id = lt_id(i)
and orgnr = lt_org(i)
and some_date between l_start_date and l_end_date
and status = 'Something';
...etc
end loop;
end if;
end;