'Pivoting on table with huge number of records

I have the following tables:

Create Table A
(rpt_id number,
Acct_id number,
type vatchar2(10));


Create Table 2
(rpt_id number,
Acct_id number,
tp varchar2(10),
information varchar2(100));


Insert into A1 (RPT_ID,ACCT_ID,TYPE) values (1,11,'type1');
Insert into A1 (RPT_ID,ACCT_ID,TYPE) values (2,22,'type2');


Insert into A2 (RPT_ID,ACCT_ID,TP,INFORMATION) values (1,11,'billnum','2341');
Insert into A2 (RPT_ID,ACCT_ID,TP,INFORMATION) values (1,11,'billname','abcd');

I need to take information as below:

RPT_ID ACCT_ID billnum billname
------ ------- ------- --------
1       11      2341    abcd

This table will have a huge amount of data, around 200000 records in A1 and related records in A2 - atleast 4 to 5 rows for each RPT_ID.

Should I be creating a pivot direct from these two joins to improve performance?

So far I have used this approach:

Insert into t3
as select a2.*
     from a1
     join a2 on a1.rpt_id = a2.rpt_id and a1.ACCT_ID = a2.ACCT_ID
    where a1.type = 'type1';

Pivot on t3 to make the following structure and insert into t4 to use it later in the code.

RPT_ID ACCT_ID billnum billname
------ ------- ------- --------
1      11      2341    abcd

This is going full scan for the A2 table. Are there any ways to avoid a full scan? Will pivot have performance issues with huge data?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source