Je crée 4 tables et j'en sélectionne ensuite. La sélection fonctionne parfaitement pour les 3 premières instructions select, mais la 4ème prend environ 10 secondes sur le simulateur iPhone, et 5 secondes sur la console sqlite3. Aussi, je reçois 0 résultats sur le simulateur de l'iPhone, mais 1 sur la console. Mais c'est un problème que je veux résoudre après avoir résolu le problème de performance. J'ai lu quelque chose à propos des index et comment ils peuvent améliorer les performances, mais je n'ai aucune idée de la façon de les implémenter dans mon code.Sélectionnez une instruction extrêmement lente
sql0 = [[NSString alloc]initWithFormat:@"
create table v%i
as select id_produkt
from v%i natural join produkt_eigenschaft
where id_eigenschaft =
(select id_eigenschaft from eigenschaft where at = '%@')",counter,counter-1,selectedStringItem];
et après:
NSString *sqleig = [[NSString alloc]initWithFormat:@"
select at
from eigenschaft
where id_eigenschaft IN
(select distinct id_eigenschaft
from produkt_eigenschaft
where id_produkt IN (select * from v%i))
AND rubrik = '%i'",counter-1, [sender tag] + 1];
Pourquoi cette instruction exécutée si lentement? Et comment puis-je le résoudre? Merci d'avance.
EDIT: expliquer plan de requête et .schema
explain query plan create table v3 as select id_produkt from v2 natural join produkt_eigenschaft where id_eigenschaft = (select id_eigenschaft from eigenschaft where at = '101-170');
0|0|1|SCAN TABLE produkt_eigenschaft (~100000 rows)
0|0|0|EXECUTE SCALAR SUBQUERY 1
1|0|0|SEARCH TABLE eigenschaft USING AUTOMATIC COVERING INDEX (at=?) (~7 rows)
0|1|0|SEARCH TABLE v2 USING AUTOMATIC COVERING INDEX (id_produkt=?) (~7 rows)
explain query plan select at from eigenschaft where id_eigenschaft IN (select distinct id_eigenschaft from produkt_eigenschaft where id_produkt IN (select * from v3)) AND rubrik = '5';
0|0|0|SCAN TABLE eigenschaft (~10000 rows)
0|0|0|EXECUTE LIST SUBQUERY 1
1|0|0|SCAN TABLE produkt_eigenschaft (~100000 rows)
1|0|0|EXECUTE LIST SUBQUERY 2
2|0|0|SCAN TABLE v3 (~1000000 rows)
1|0|0|USE TEMP B-TREE FOR DISTINCT
CREATE TABLE eigenschaft (id_eigenschaft integer,rubrik integer,en text,at text,ba text,bg text,hr text,cz text,hu text,pl text,ro text,ru text,rs text,sk text,si text);
CREATE TABLE farbe (id_farbe integer,hexcode text,farbton integer,farbname text);
CREATE TABLE produkt (id_produkt integer,code text,pdf_link text,image_link text,image_small blob,link text,en text,at text,ba text,bg text,hr text,cz text,hu text,pl text,ro text,ru text,rs text,sk text,si text,active integer);
CREATE TABLE produkt_eigenschaft (id_produkt integer,id_eigenschaft integer);
CREATE TABLE produkt_farbe (id_produkt integer,id_farbe integer);
CREATE TABLE produkt_surface (id_surface integer,id_produkt integer,image_link text);
CREATE TABLE produkt_text (id_produkt integer,en text,at text,ba text,bg text,hr text,cz text,hu text,pl text,ro text,ru text,rs text,sk text,si text);
CREATE TABLE rubrik (id integer,en text,at text,ba text,bg text,hr text,cz text,hu text,pl text,ro text,ru text,rs text,sk text,si text);
CREATE TABLE v0(id_produkt INT);
CREATE TABLE v1(id_produkt INT);
CREATE TABLE v2(id_produkt INT);
CREATE TABLE v3(id_produkt INT);
Afficher la sortie de l'exécution de ces requêtes avec [ 'EXPLIQUER QUERY PLAN'] (http://www.sqlite.org/lang_explain.html) dans la console, et votre schéma (utilisez la commande '.schema'). –
ajouté dans le message principal – oybcs
Je ne sais vraiment pas comment ma table v3 a 1 million de lignes o_O – oybcs