Developing a new script has shown abnormal execution time in a specific part.
The issue has been isolated so far with the following:
- pl/sql block
- listagg function
- nested sub-select
- tested version : QueryTool v25.0.118
Within a PSQL block, the execution run for an unknown time (tested over 6 minutes and running). The trace view shows heavy prints, which means the engine works.
declare
l_html varchar2;
begin
/* Build one big HTML table string using LISTAGG in a sub-select */
select
'<table border="1" style="border-collapse: collapse; width: 100%; margin-bottom: 20px;">'
|| '<tr style="background-color: #f2f2f2;">'
|| '<th>Month</th>'
|| '<th>Total Days</th>'
|| '<th>Weekdays</th>'
|| '<th>Weekends</th>'
|| '<th>First Day</th>'
|| '<th>Last Day (via subselect)</th>'
|| '</tr>'
|| (
select listagg(
'<tr>'
|| '<td>' || to_char(month_number) || '</td>'
|| '<td style="text-align:center;">' || total_days || '</td>'
|| '<td style="text-align:center;">' || weekday_days || '</td>'
|| '<td style="text-align:center;">' || weekend_days || '</td>'
|| '<td>' || to_char(first_day, 'YYYY-MM-DD') || '</td>'
|| '<td>' || to_char(last_day_via_sub, 'YYYY-MM-DD') || '</td>'
|| '</tr>'
, ''
) within group (order by month_number)
from (
/* Dummy aggregation over CALENDAR@DataDictionary with subselects */
select
c.month_number,
count(*) as total_days,
-- Simple aggregates
sum(case when c.day_in_week between 2 and 6
then 1 else 0 end) as weekday_days,
sum(case when c.day_in_week in (1,7)
then 1 else 0 end) as weekend_days,
-- First day in the month
min(c.day_date) as first_day,
-- Last day in the month, *computed via a correlated subselect*
max(
case
when c.day_date =
( select max(d.day_date)
from calendar@DataDictionary d LIMIT 50
)
then c.day_date
end
) as last_day_via_sub
from calendar@DataDictionary c
where c.year_number in (2024,2025) -- any year you like
group by c.year_number, c.month_number
)
)
|| '</table>'
into l_html
from dual;
/* Just to see the result */
dbms_output.put_line(l_html);
end;
Without the PSQL block, the execution run in less than 2 seconds:
/* Build one big HTML table string using LISTAGG in a sub-select */
select
'<table border="1" style="border-collapse: collapse; width: 100%; margin-bottom: 20px;">'
|| '<tr style="background-color: #f2f2f2;">'
|| '<th>Month</th>'
|| '<th>Total Days</th>'
|| '<th>Weekdays</th>'
|| '<th>Weekends</th>'
|| '<th>First Day</th>'
|| '<th>Last Day (via subselect)</th>'
|| '</tr>'
|| (
select listagg(
'<tr>'
|| '<td>' || to_char(month_number) || '</td>'
|| '<td style="text-align:center;">' || total_days || '</td>'
|| '<td style="text-align:center;">' || weekday_days || '</td>'
|| '<td style="text-align:center;">' || weekend_days || '</td>'
|| '<td>' || to_char(first_day, 'YYYY-MM-DD') || '</td>'
|| '<td>' || to_char(last_day_via_sub, 'YYYY-MM-DD') || '</td>'
|| '</tr>'
, ''
) within group (order by month_number)
from (
/* Dummy aggregation over CALENDAR@DataDictionary with subselects */
select
c.month_number,
count(*) as total_days,
-- Simple aggregates
sum(case when c.day_in_week between 2 and 6
then 1 else 0 end) as weekday_days,
sum(case when c.day_in_week in (1,7)
then 1 else 0 end) as weekend_days,
-- First day in the month
min(c.day_date) as first_day,
-- Last day in the month, *computed via a correlated subselect*
max(
case
when c.day_date =
( select max(d.day_date)
from calendar@DataDictionary d LIMIT 50
)
then c.day_date
end
) as last_day_via_sub
from calendar@DataDictionary c
where c.year_number in (2024,2025) -- any year you like
group by c.year_number, c.month_number
)
)
|| '</table>'
from dual;