mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
add partial index on odid, and search odid as well
the odid != 0 check in cards_for_deck.sql is necessary for sqlite to be able to take advantage of the index
This commit is contained in:
parent
0bb80329e8
commit
3ffb37270d
5 changed files with 14 additions and 3 deletions
|
@ -366,8 +366,6 @@ impl Collection {
|
|||
}
|
||||
|
||||
fn delete_all_cards_in_normal_deck(&mut self, did: DeckID) -> Result<()> {
|
||||
// fixme: need to search on odid as well
|
||||
// fixme: the odid requirement will require a table scan, which will be slow when deleting a large tree
|
||||
let cids = self.storage.all_cards_in_single_deck(did)?;
|
||||
self.remove_cards_inner(&cids)
|
||||
}
|
||||
|
|
9
rslib/src/storage/deck/cards_for_deck.sql
Normal file
9
rslib/src/storage/deck/cards_for_deck.sql
Normal file
|
@ -0,0 +1,9 @@
|
|||
select
|
||||
id
|
||||
from cards
|
||||
where
|
||||
did = ?1
|
||||
or (
|
||||
odid != 0
|
||||
and odid = ?1
|
||||
)
|
|
@ -117,7 +117,7 @@ impl SqliteStorage {
|
|||
|
||||
pub(crate) fn all_cards_in_single_deck(&self, did: DeckID) -> Result<Vec<CardID>> {
|
||||
self.db
|
||||
.prepare_cached("select id from cards where did = ?")?
|
||||
.prepare_cached(include_str!("cards_for_deck.sql"))?
|
||||
.query_and_then(&[did], |r| r.get(0).map_err(Into::into))?
|
||||
.collect()
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ drop table fields;
|
|||
drop table templates;
|
||||
drop table notetypes;
|
||||
drop table decks;
|
||||
drop index idx_cards_odid;
|
||||
update col
|
||||
set
|
||||
ver = 11;
|
|
@ -35,6 +35,9 @@ create table decks (
|
|||
kind bytes not null
|
||||
);
|
||||
create unique index idx_decks_id on decks (id);
|
||||
create index idx_cards_odid on cards (odid)
|
||||
where
|
||||
odid != 0;
|
||||
update col
|
||||
set
|
||||
ver = 15;
|
||||
|
|
Loading…
Reference in a new issue