Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Paste
P198
improving indexing using derivative form of materialized view
Active
Public
Actions
Authored by
ardumont
on Dec 2 2017, 1:06 PM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Award Token
Flag For Later
Tags
Indexer
Subscribers
None
-- deal with new content
create or replace function content_insert() returns trigger
security definer
language plpgsql
as $$
begin
insert into content_mimetype_to_index(id)
values(new.sha1);
return new;
end;
$$;
drop trigger if exists after_content_insert_cascade_mimetype on content;
create trigger after_content_insert_cascade_mimetype after insert on content
for each row execute procedure content_insert();
-- deal with new content_mimetype
create or replace function content_mimetype_insert() returns trigger
security definer
language plpgsql
as $$
begin
-- FIXME: Deal with existing data (due to insert on existing data)
insert into content_mimetype_to_index(id, mimetype)
values(new.id, new.mimetype);
return new;
end;
$$;
drop trigger if exists after_content_mimetype_insert_cascade_mimetype on content_mimetype;
create trigger after_content_mimetype_insert_cascade_mimetype after insert on content_mimetype
for each row execute procedure content_mimetype_insert();
-- deal with content_mimetype update
create or replace function content_mimetype_update() returns trigger
security definer
language plpgsql
as $$
begin
update content_mimetype_to_index
set mimetype=new.mimetype
where id=new.id;
return new;
end;
$$;
drop trigger if exists after_content_mimetype_update_cascade_mimetype on content_mimetype;
create trigger after_content_mimetype_update_cascade_mimetype after insert on content_mimetype
for each row execute procedure content_mimetype_update();
-- bootstrap values initialization
insert into content_mimetype_to_index(id, mimetype)
select c.sha1 as id, cm.mimetype as mimetype
from content c tablesample system(0.0001) left join content_mimetype cm on c.sha1=cm.id;
-- build index for reading unindexed mimetype
create index content_mimetype_to_index_idx
on content_mimetype_to_index(id)
where mimetype is null;
create unique index content_mimetype_to_index_idx
on content_mimetype_to_index(id, mimetype)
Event Timeline
ardumont
created this paste.
Dec 2 2017, 1:06 PM
2017-12-02 13:06:05 (UTC+1)
ardumont
mentioned this in
T864: Indexers - Find and implement a proper scheduling content messages indexing method
.
Dec 2 2017, 1:08 PM
2017-12-02 13:08:42 (UTC+1)
ardumont
edited the content of this paste.
(Show Details)
Log In to Comment