This commit is contained in:
@@ -7,6 +7,54 @@ todo: Search indexing performance improvement and exception avoidance (Search.cs
|
||||
Idea: do the insert manually with the clause "on conflict do nothing"
|
||||
if detect it hasn't inserted (conflict) trigger a fetch instead
|
||||
like what is being done now but won't have the exception to deal with!!
|
||||
var CtAdd.SearchDictionary.FromSqlRaw("insert into asearchdictionary (word) values('{0}') on conflict (word) do update set word=excluded.word returning id",KeyWord ).FirstOrDefaultAsync();
|
||||
|
||||
stored procedure?
|
||||
https://www.postgresqltutorial.com/plpgsql-loop-statements/
|
||||
-------
|
||||
-- PROCEDURE: public.pdoindex(text[], bigint, integer, boolean)
|
||||
|
||||
-- DROP PROCEDURE public.pdoindex(text[], bigint, integer, boolean);
|
||||
|
||||
CREATE OR REPLACE PROCEDURE public.pdoindex(
|
||||
words text[],
|
||||
objectid bigint,
|
||||
objecttype integer,
|
||||
isupdate boolean DEFAULT false)
|
||||
LANGUAGE 'plpgsql'
|
||||
|
||||
AS $BODY$DECLARE
|
||||
s text;
|
||||
wordid bigint;
|
||||
BEGIN
|
||||
IF objectid=0 THEN
|
||||
RAISE EXCEPTION 'Bad object id --> %', objectid;
|
||||
END IF;
|
||||
|
||||
IF objecttype=0 THEN
|
||||
RAISE EXCEPTION 'Bad object type --> %', objecttype;
|
||||
END IF;
|
||||
|
||||
|
||||
|
||||
-- insert into asearchdictionary (word) values('{0}') on conflict (word) do update set word=excluded.word returning *
|
||||
-- iterate text in loop
|
||||
FOREACH s IN ARRAY words
|
||||
LOOP
|
||||
insert into asearchdictionary (word) values(s) on conflict (word) do update set word=excluded.word returning id into wordid;
|
||||
insert into asearchkey (wordid,objectid,objecttype) values(wordid,objectid,objecttype);
|
||||
--RAISE info 'word is %', s;
|
||||
--RAISE info 'word id is %', wordid;
|
||||
END LOOP;
|
||||
END;
|
||||
$BODY$;
|
||||
|
||||
|
||||
-------
|
||||
|
||||
ALTER FUNCTION public.doindex(text[], bigint, integer, boolean)
|
||||
OWNER TO postgres;
|
||||
|
||||
|
||||
todo: Search confirm indexes are actually being used
|
||||
|
||||
|
||||
Reference in New Issue
Block a user