DROP TRIGGER one_fti_trigger on table1;
DROP TRIGGER two_fti_trigger on table2;
DROP TRIGGER three_fti_trigger on table3;
DROP FUNCTION fti() CASCADE;

--DROP INDEX one_fti_string_idx;
--DROP INDEX one_fti_id_idx;
--DROP INDEX one_fti_oid_idx;

--DROP INDEX two_fti_string_idx;
--DROP INDEX two_fti_id_idx;
--DROP INDEX two_fti_oid_idx;

--DROP INDEX three_fti_string_idx;
--DROP INDEX three_fti_id_idx;
--DROP INDEX three_fti_oid_idx;

DROP TABLE table1;
DROP TABLE table2;
DROP TABLE table3;

DROP TABLE table1_fti;
DROP TABLE table2_fti;
DROP TABLE table3_fti;

CREATE FUNCTION fti() RETURNS OPAQUE AS '/usr/lib/postgresql/lib/fti.so' LANGUAGE 'C';

-- Create tables

CREATE TABLE table1(id int4, label	VARCHAR(64));
CREATE TABLE table2(id int4, label	VARCHAR(64));
CREATE TABLE table3(id int4, label	VARCHAR(64));

CREATE TABLE table1_fti(string VARCHAR(5120), id oid);
CREATE TABLE table2_fti(string VARCHAR(4351), id oid);
CREATE TABLE table3_fti(string VARCHAR(1000), id oid);

-- Triggers for FTI
CREATE TRIGGER "one_fti_trigger" AFTER UPDATE OR INSERT OR DELETE
ON table1 FOR EACH ROW
EXECUTE PROCEDURE fti(table1_fti, label);

CREATE TRIGGER "two_fti_trigger" AFTER UPDATE OR INSERT OR DELETE
ON table2 FOR EACH ROW
EXECUTE PROCEDURE fti(table2_fti, label);

CREATE TRIGGER "three_fti_trigger" AFTER UPDATE OR INSERT OR DELETE
ON table3 FOR EACH ROW
EXECUTE PROCEDURE fti(table3_fti, label);



-- Indexes for FTI
--CREATE INDEX one_fti_string_idx ON table1_fti(string);
--CREATE INDEX one_fti_id_idx ON table1_fti(id);
--CREATE INDEX one_fti_oid_idx ON table1_fti(oid);

--CREATE INDEX two_fti_string_idx ON table2_fti(string);
--CREATE INDEX two_fti_id_idx ON table2_fti(id);
--CREATE INDEX two_fti_oid_idx ON table2_fti(oid);

--CREATE INDEX three_fti_string_idx ON table3_fti(string);
--CREATE INDEX three_fti_id_idx ON table3_fti(id);
--CREATE INDEX three_fti_oid_idx ON table3_fti(oid);

INSERT INTO table1 values (1, 'test');
INSERT INTO table2 values (1, 'test');
INSERT INTO table3 values (1, 'test');
