Hi,

I am kind of new to postgres and have to insert a bulk data into a table.

I have a query like this:

INSERT into MAINTABLE(COL1,COL2,COL3,COL4,COL5,COL6)
SELECT X.a,
Y.b,
Y.c,
Z.d,
Z.e,
Z.f
FROM
(SELECT a,a1 FROM WRKTABLE1 WHERE a in (SELECT a1 from WRKTABLE2)) X,
(SELECT b, c FROM WRKTABLE3) Y,
(SELECT d,e,f FROM WRKTABLE4) Z
WHERE Y.b = X.a1 AND Y.b = Z.d


Number of rows in Work tables above are as follows:

WRKTABLE1 -5288779 rows
WRKTABLE2 - 203220 rows
WRKTABLE3- 26443895 rows
WRKTABLE2 -7978485 rows

how can I speed up the insertion of this huge data?? Will creation of indexes help, if yes then on what columns?

Thanks