Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is MySQL much faster then SQLite 3? 1

Status
Not open for further replies.

sen5241b

IS-IT--Management
Sep 27, 2007
199
US
I created a a database table in MySQL called placenames -a simple list of 260K place names. The following code finds a name in the table super fast.

Code:
$result = mysql_query("SELECT * FROM placenames");
while($row = mysql_fetch_array($result))
{ if ($place == $row['placename'])  { do whatever etc ..

I created the same data in a SQLite 3 database with an index and it takes forever to read through the table and it hangs the server before it can finish executing this code:

Code:
foreach ($dbh->query('SELECT * FROM placenames') as $row) 
{ if ($place == FoldDiacritics($row['placename']) ) {  do whatever etc ..

Seems like there is no random access with the SQLite database even with the index. Why is MySQL so much faster?
 
Hi

Let us start with some tests :
Code:
[blue]master #[/blue] time mysql test260k <<< 'select count(*) from test260k'
count(*)
260000
time 0m0.012s

[blue]master #[/blue] time mysql test260k <<< 'select * from test260k' > /dev/null
time 0m0.515s

[blue]master #[/blue] time mysql test260k <<< 'select * from test260k order by name' > /dev/null
time 0m0.515s

[blue]master #[/blue] time sqlite3 test260.sqlite <<< 'select count(*) from test260k;'
260000
time 0m0.014s

[blue]master #[/blue] time sqlite3 test260.sqlite <<< 'select * from test260k;' > /dev/null
time 0m0.131s

[blue]master #[/blue] time sqlite3 test260.sqlite <<< 'select * from test260k order by name;' > /dev/null
time 0m0.136s
My conclusion : if your SQLite query is so slow, the difference is probably elsewhere, for example :
[ul]
[li]handled by different database abstraction layers in PHP[/li]
[li]stored on different filesystems[/li]
[/ul]


Feherke.
 
Seems the 'where' clause provides random access.
 
Hi

Their performance is still quite constant here :
Code:
[blue]master #[/blue] time mysql test260k <<< "select count(*) from test260k where name='test2011'"
count(*)
1
time 0m0.012s

[blue]master #[/blue] time sqlite3 test260k.sqlite <<< "select count(*) from test260k where name='test2011';"
1
time 0m0.003s

Feherke.
 
Seems like sqlite might even be faster.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top