# table tbl_a
ID
Name
> tbl_a: 10000 record
CREATE INDEX ID on tbl_a USING btree (ID COLLATE pg_catalog."default")
# table tbl_b
Branch
ID
name
> tbl_b: 1000 record
CREATE INDEX ID on tbl_b USING btree (ID COLLATE pg_catalog."default")
My function
CREATE OR REPLACE FUNCTION name_func()
RETURNS SETOF AS
$BODY$DECLARE
_r record;
BEGIN
CREATE TEMP TABLE tmp_table AS
SELECT branch, ID, Name from tbl_b where 1 = 0;
FOR _r IN SELECT branch, ID, Name from tbl_b order by name
LOOP
INSERT INTO tmp_table
SELECT _r.branch, ID, Name FROM tbl_a where ID = _r.ID and Name = _r.Name;
END LOOP;
//do something with tmp_table
END
function performance slow in
For ... Loop
Do you have any advice for performance improvements? Please help me!