Database Selection

Status
Not open for further replies.

torok

Ars Tribunus Militum
2,000
Okay, I've got a table called "searchindex" with two fields: wordid and textid. I need to find the text ids that have wordid a and b. This is the only way I have found to do it:

SELECT DISTINCT s1.textid FROM searchindex AS s1, searchindex AS s2 WHERE s1.textid=s2.textid AND s1.wordid=1670 AND s2.wordid=2375

The problem is, when I need to do more then two ands, or even just two, this can take a horribly long time because my table for searchindex is very large. Does anyone know a better way I can do this? I'm using MySQL, by the way. Thanks.
 

Ezran

Wise, Aged Ars Veteran
137
This really makes me question mySQL's ability to optimize queries.

Does anyone know why that query, without an index on the table, would take 5 minutes? It never should. Unless it's got a million rows and it's running on an 8086.

mySQL should be smart enough to look for the wordid matches first, then compare the textid on the rows it finds, right? So if I am correct, unless there were a ton of rows that matched the given values for wordid, it should not be slow.

Just trying to get info...

-- Ezran

[Edit: 100th Post! And it only took 2 years. :) ]
 

_klamath_

Ars Scholae Palatinae
770
This really makes me question mySQL's ability to optimize queries.

That seems doubtful to me. Without an index on wordid, you'd need to sequentially scan through all the tuples in the table. That is going to take a LONG time if the size of the table is large.

mySQL should be smart enough to look for the wordid matches first, then compare the textid on the rows it finds, right?

I assume so -- but if there's no index on wordid, most of the overhead should come from the seqscan of the table to do the wordid lookup. With an index on wordid, it should be very fast (2 seconds sounds pretty high, depending on the hardware you're using, the number of results from the index scan, and the number of rows that need to be checked to satisfy DISTINCT).
 
That query is a large join. 5 minutes, when unindexed, sounds perfectly reasonable. We don't have any information about the ordering of the data, whether or not it's sorted on particular attributes, or anything. So, in the worst case, you do one table scan of "searchindex" for each value that appears in "searchindex". It's called a nested loop join. It's slow and inefficient, but sometimes it's all you've got when you don't have indexes or appropriate sorts already in place.

In this case, there's no reason to question the ability of mySQL. If you want to, question the understanding of the DB architect for this set of tables and indexes, but not the engine. ;)
 

petrov

Ars Tribunus Militum
2,714
MySQL is a craptacular database that should be dumped ASAP for a better database such as Postgres or Interbase or Oracle or anything.

I have not heard any convincing arguments in favor of MySQL other than "it's sometimes fast". It has crappy features, it chokes on any non-trivial query, it sucks at serious concurrency and it scales poorly.

anything but MySQL.

--sam
 

enkafan

Wise, Aged Ars Veteran
111
While I don't think that MySql exactly has its place in a serious business environments, it is of course free. And the performance isn't too bad either. Check out this article: http://www.eweek.com/article/0,3658,s=702&a=23115,00.asp (and while you are at it make sure you look at the .net w/ sql 2000 result. holy crap!). MySQL does have some nifty stuff I'd like to see some other RDBMS systems pick up (the cache thingy sounds pretty tight) that of course helped out quite a bit for getting this thing tuned on par with Oracle.

Of course, most enterprise developers I know put MySQL on par with the Jet engine (access). Developing with it can be a royal pain in the butt compared to Oracle or SQL Server, and many companies of course do shy away from putting mission critical data on a system that they view (correctly or not) with no backing from a big name company like Oracle, IBM, Sybase or Microsoft.
 
At least Jet does subselects.

and while you are at it make sure you look at the .net w/ sql 2000 result. holy crap
Impressive, considering a number of parts are version 1.0.

I wonder what JDBC driver they used with SQL Server in the Java tests; there are a number available, but they don't seem to mention which they used.

[This message was edited by PeterB on April 14, 2002 at 17:41.]
 

clm100

Ars Legatus Legionis
13,874
Subscriptor
My-ICBIN-SQL.jpg

Personally, I don't mind MySQL. It works well enough for most really basic things, isn't slow, is decently documented and is popular enough that you can usually get help.
 
Originally posted by nsample:
That first graph shows that SQL Server 2000 is clearly the worst performer of the bunch (in the most real-world scenario). Hands down. There's nothing as bad as SQL Server in terms of throughput. Can someone please explain why that's a good thing?
I think that using OLE DB with SQL Server is an order of magnitude more common in the "real world" than JDBC, and offers very respectable performance.

SQL Server's throughput is fine. This particular unnammed JDBC driver isn't.

If SQL Server had fundamentally poor throughput, the OLE DB/ASP.NET version wouldn't be as fast as it is.
 

enkafan

Wise, Aged Ars Veteran
111
Originally posted by nsample:
That first graph shows that SQL Server 2000 is clearly the worst performer of the bunch (in the most real-world scenario). Hands down. There's nothing as bad as SQL Server in terms of throughput. Can someone please explain why that's a good thing?

the same reason reading the article is a good thing

oracle, mysql max out at 600pg/sec on the java solution
sql server maxes out at around 900 on an all microsoft solution

granted this is apples to oranges because of the different platforms, but it really does go to show why driver support is so important.
 

enkafan

Wise, Aged Ars Veteran
111
Originally posted by _klamath_:


That cache is so lame! It's just a technique to boost benchmark scores, I doubt very much whether it would help significantly for real-life workloads.

well, assuming the asp.net caching thing didn't exist, I can see all kinds of uses for our website. We have many tables that get updated maybe once or twice a month, at that. Now a good design can obviously get around constantly querying the database, but I wouldn't have to worry about maintaining that code over time with that little feature.

As it stands now though, I just enable page output caching for 12 hours on ASP.NET and VROOOOOOOOOOOOOOOOM
 
Status
Not open for further replies.