In addition,

- make a new index only on column1
- move the prepare before the loop to avoid reparsing the SELECT each time
- use sqlite3_bind_* and sqlite3_reset in the loop.
- move finalize after the loop.
- query the test table directly - not the temporary ttest table.
- don't SELECT * if you only need a column or two

--- RaghavendraK 70574 <[EMAIL PROTECTED]> wrote:
> int main()
> {
>   sqlite3* db;
>   int ret = sqlite3_open("abc",&db);
> 
>   char* errmsg;
>   char buf[1024];
>   sprintf(buf,"create temporary table ttest(column1 text,column2 text,primary 
> key
> (column1,column2));"); 
>   ret = sqlite3_exec(db , buf, NULL ,NULL,&errmsg);
> 
> 
>   sprintf(buf,"insert into ttest select * from test;");
>   ret = sqlite3_exec(db , buf, NULL ,NULL,&errmsg);
> 
> 
>   //read all the srvName from file and store it in arr and query.
>   fstream fin("query.sql",ios::in);
>   string data[100000];
>    
>    for(int j=0;!fin.eof();j++)
>    {
>       fin>>data[j];
>       //cout<<data[j]<<endl;
>    } 
>    fin.close();
> 
>    cout<<"Calling Test Now"<<endl;
>    sleep(1);
> 
>    //Now Query Data.
>    time_t start = time(0);
>    list<string> lst;
> 
>    char* szError=0;
>    const char* szTail=0;
>    sqlite3_stmt* pVM;
> 
>    for(int k=0;k<100000;k++)
>    {
>       sprintf(buf,"select * from ttest where column1 = 
> '%s'",data[k].c_str());      
>         
> 
>       ret = sqlite3_prepare(db, buf, -1, &pVM, &szTail);  
>       ret = sqlite3_step(pVM);                 
>       //lst.push_back();
>       ret = sqlite3_finalize(pVM);    
>    }
>    //
>    time_t end = time(0);
>    cout<<"start="<<start<<endl;
>    cout<<"end="<<end<<endl;
> 
>   return 0;
> }
> 
> //Result: It takes 17 sec to read 100,000 records. Can it be reduced to 1 
> sec.???



       
____________________________________________________________________________________
Take the Internet to Go: Yahoo!Go puts the Internet in your pocket: mail, news, 
photos & more. 
http://mobile.yahoo.com/go?refer=1GNXIC

-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to