-- vandelay.match_bib_record() is strictly in service of that function.
CREATE TYPE vandelay.match_set_test_result AS (record BIGINT, quality INTEGER);
+-- These are always empty from the point of view of a new transaction
+CREATE UNLOGGED TABLE vandelay.tmp_qrows ( q INTEGER );
+CREATE UNLOGGED TABLE vandelay.tmp_jrows ( j TEXT );
+
CREATE OR REPLACE FUNCTION vandelay.match_set_test_marcxml(
match_set_id INTEGER, record_xml TEXT, bucket_id INTEGER
) RETURNS SETOF vandelay.match_set_test_result AS $$
tags_rstore := vandelay.flatten_marc_hstore(record_xml);
svf_rstore := vandelay.extract_rec_attrs(record_xml);
- CREATE TEMPORARY TABLE _vandelay_tmp_qrows (q INTEGER);
- CREATE TEMPORARY TABLE _vandelay_tmp_jrows (j TEXT);
-
-- generate the where clause and return that directly (into wq), and as
-- a side-effect, populate the _vandelay_tmp_[qj]rows tables.
wq := vandelay.get_expr_from_match_set(match_set_id, tags_rstore);
-- qrows table is for the quality bits we add to the SELECT clause
SELECT STRING_AGG(
'COALESCE(n' || q::TEXT || '.quality, 0)', ' + '
- ) INTO coal FROM _vandelay_tmp_qrows;
+ ) INTO coal FROM vandelay.tmp_qrows;
-- our query string so far is the SELECT clause and the inital FROM.
-- no JOINs yet nor the WHERE clause
-- jrows table is for the joins we must make (and the real text conditions)
SELECT STRING_AGG(j, E'\n') INTO joins
- FROM _vandelay_tmp_jrows;
+ FROM vandelay.tmp_jrows;
-- add those joins and the where clause to our query.
query_ := query_ || joins || E'\n';
RETURN NEXT rec;
END LOOP;
- DROP TABLE _vandelay_tmp_qrows;
- DROP TABLE _vandelay_tmp_jrows;
+ DELETE FROM vandelay.tmp_qrows;
+ DELETE FROM vandelay.tmp_jrows;
RETURN;
END;
$$ LANGUAGE PLPGSQL;
) RETURNS VOID AS $$
DECLARE
BEGIN
- INSERT INTO _vandelay_tmp_qrows (q) VALUES (node.id);
+ INSERT INTO vandelay.tmp_qrows (q) VALUES (node.id);
END;
$$ LANGUAGE PLPGSQL;
-- remember $1 is tags_rstore, and $2 is svf_rstore
caseless := FALSE;
- SELECT COUNT(*) INTO jrow_count FROM _vandelay_tmp_jrows;
+ SELECT COUNT(*) INTO jrow_count FROM vandelay.tmp_jrows;
IF jrow_count > 0 THEN
my_using := ' USING (record)';
my_join := 'FULL OUTER JOIN';
jrow := jrow || ' ' || my_alias || my_using || E'\n';
END IF;
- INSERT INTO _vandelay_tmp_jrows (j) VALUES (jrow);
+ INSERT INTO vandelay.tmp_jrows (j) VALUES (jrow);
END;
$$ LANGUAGE PLPGSQL;