add an index on notes(mid) so we can avoid the tablescan
This commit is contained in:
parent
f6931197d2
commit
2308b136fd
@ -317,7 +317,6 @@ class ModelManager:
|
||||
|
||||
def useCount(self, m: NoteType) -> Any:
|
||||
"Number of note using M."
|
||||
print("useCount() is slow; prefer all_use_counts()")
|
||||
return self.col.db.scalar("select count() from notes where mid = ?", m["id"])
|
||||
|
||||
# Copying
|
||||
|
@ -656,7 +656,7 @@ class RustBackend:
|
||||
json=bjson, preserve_usn_and_mtime=preserve_usn
|
||||
)
|
||||
),
|
||||
release_gil=True
|
||||
release_gil=True,
|
||||
).add_or_update_notetype
|
||||
nt["id"] = id
|
||||
|
||||
|
@ -1,10 +1,13 @@
|
||||
select
|
||||
nt.id,
|
||||
nt.name,
|
||||
count(n.id)
|
||||
(
|
||||
select
|
||||
count(*)
|
||||
from notes n
|
||||
where
|
||||
nt.id = n.mid
|
||||
)
|
||||
from notetypes nt
|
||||
left join notes n on (n.mid = nt.id)
|
||||
group by
|
||||
nt.id
|
||||
order by
|
||||
nt.name
|
@ -6,6 +6,7 @@ drop table templates;
|
||||
drop table notetypes;
|
||||
drop table decks;
|
||||
drop index idx_cards_odid;
|
||||
drop index idx_notes_mid;
|
||||
update col
|
||||
set
|
||||
ver = 11;
|
@ -35,6 +35,7 @@ create table decks (
|
||||
kind bytes not null
|
||||
);
|
||||
create unique index idx_decks_name on decks (name);
|
||||
create index idx_notes_mid on notes (mid);
|
||||
create index idx_cards_odid on cards (odid)
|
||||
where
|
||||
odid != 0;
|
||||
|
Loading…
Reference in New Issue
Block a user