Hi all,
I have an application that currently works with two very large n-ary
trees. A lot of time is spent doing depth-first searches on these
trees.
I'm thinking of moving away from using trees to using a database
backend, and using SQL to query the database. Would I get any
performance improvement this way?
That's impossible to answer: we don't know what performance you are getting
with your current code! Database queries can run very quickly under ideal
circumstances but a lot depends on:
- what sort of database you are using - flat file, hierarchical, relational,
etc. Since you mention SQL, I assume you want a relational database but
there are some non-relational databases that use some form of SQL.
- what specific database you are using, e.g. DB2, Oracle, MySQL
- how well you have normalized and de-normalized your data
- how fast your hardware is
- how your data is clustered
- how efficient your SQL is
- etc. etc.
What sort of datastructure does a database use?
I'm not sure what you mean by that. Logically, you always think of
relational database data being stored as rows in tables; that's the paradigm
underlying SQL. Internally, however, a relational database may use other
structures to make it easier to find your data. For instance, DB2 uses
b-trees very heavily "under the covers", although you don't need to worry
about that when you are writing your SQL. Other vendors use other approaches
and it's not unusual to see a mix of approaches in each vendor's product.
What sort of Big-Oh times would I be likely to get?
I've been working with database for 25+ years and I've never heard the term
"Big-Oh": what is it? Assuming that it is some kind of performance
measurement, refer to my earlier remarks.
In short, databases have many virtues and can have excellent performance but
that doesn't mean they will _inevitably_ perform better than whatever you're
doing now.
If you're new to databases, you will need to allow time for you - and the
rest of your development team if you are not working alone - to get up to
speed. You'll need to learn proper database design and all of the various
issues surrounding databases, like installation, administration,
maintenance, etc. It might be best for you to attempt a smallish prototype
first so that you can get familiar with all of the implications of using a
database; you can do some benchmarking with your prototype and see if you
are getting the performance you want without having to invest an excessive
amount of time and money on databases.