Subject | Re: Newbie: Query speed and DB size |
---|---|
Author | Adam |
Post date | 2008-03-26T22:41:47Z |
> 1) Does the query speed depend on the number of rows in a table?If you have appropriate indices in place then no. Most databases
(including Firebird) can use an index to only read the rows that match
a particular condition. Firebird can go one step further than many
DBMS in that it can simultaneously use multiple indices at the same time.
Furthermore, if you create a constraint (primary key, foreign key,
unique), Firebird will automatically create an ascending index on that
field.
Of course if you fail to create such an index, it would leave Firebird
no choice but to check every record in a table to see if the
conditions are met, and under such a case the query speed would depend
on the number of rows in the table.
You can check this by looking at the PLAN.
For example, a query such as
SELECT * FROM SITE WHERE SITEID = 10;
Might use the plan:
PLAN (SITE INDEX (PK_SITE))
That shows the index PK_SITE was used, so this would be fast even with
millions of records in SITE.
Another query such as
SELECT * FROM SITE WHERE NAME='Foo';
Might use the plan:
PLAN (SITE NATURAL)
That shows the table SITE was read naturally, but the database will
still only *return* the records where the name matches, it just needs
to read a whole lot more to know which records they are. You certainly
wouldn't want to be running such a query too frequently if you have
millions of records without an index on Name.
> 2) Does the query speed depend on the number of columns in a table,It is certainly dependent on the number of fields returned, but I have
> assuming that I will only query the PK column (select ID from mytable)?
never observed performance penalties based on fields not returned.
> 3) OK, I know this is a vague question.Firstly, 'select * from table' is not a simple query. You are asking
> On a "normal" desktop computer say 2MHz and 2GB RAM or something like
> it. How many simple queries (like select * from table) can I make in a
> second. Is it in the 100's, 1000's etc.?
the database to return all data from the table, so it is entirely
dependent on the size of that dataset. Performing such a query on a
table with 10 records and 5 columns will probably under 10ms, but if
there are hundreds of thousands of records you may be waiting for minutes.
On a 2MHz machine it would take an awful long time to do anything ;)
A simple query would be a prepared insert statement. I would expect
somewhere approaching 5000-10000 inserted records per second on a
typical desktop machine.
But everything is dependent on your disk speed, whether various
caching mechanisms are enabled, the size of the cache, etc.
Adam