Database performance and index statistics when operating Vertec on-premises
Product line
Standard
|Expert
Operating mode
CLOUD ABO
|ON-PREMISES
Modules
Services & CRM
Budget & Phases
Purchases
Resource Planning
Business Intelligence
A SQL database needs not only indexes on important fields to enable a SQL query to run efficiently, but also information about how selective a certain index is, so that the best tactic can be chosen before executing a SQL statement.
For example, the selectivity for a boolean (yes/no) field and a flat distribution is 50%. For an index on the ZIP code of an address, the selectivity is much higher. So if you query a postcode with a boolean field at the same time, the selectivity tells the query analyzer that it is better to search for the ZIP code first and then for the boolean field.
For this purpose, so-called index statistics are created, which save information about the value distribution of the indexed columns. Index statistics – just like the indices themselves – must be maintained regularly. Outdated or not created index statistics can lead to the corresponding indices not being used at all, which has a measurable and sometimes very large effect on the performance of certain SQL statements.
In general, the following applies:
In Vertec databases, customer-specific indexes can be created after careful analysis and consideration. In order to maintain indexes after a database convert, you must use the prefix CIX_
start.
Custom indices are created as follows:
CREATE [UNIQUE] INDEX indexname ON tablename (column1, column2, column3)
The syntax for Firebird and SQL for creating simple indexes is similar, but when more information is added, there are differences.
Example:
CREATE INDEX CIX_INVOICENUMBER ON INVOICE (NUMBER);
Creating indices can improve performance, but there are also risks. For example, inserting or updating a record takes more time if an index needs to be edited, and even with a SELECT index, an index does not always produce better results: for example, a field with good selectivity but many values like ““ or NULL at the same time may even perform worse. Also, an index only works for a = comparison, not for a LIKE.
Before deciding to add a new index, the effect of the entire application should be thoroughly tested.
By default, SQL Server automatically recalculates the index statistics when a table changes “substantially,” i.e. by at least 10%.
This is not always enough. We recommend that the index statistics be compiled with a Maintenance Job regularly. For this purpose, there is the Stored Procedure:
EXEC sp_updatestats;
which is scheduled or can simply be initiated by hand.
For migrations – i.e. when started with an empty Vertec database and migrating a lot of data – the SQL Server calculates the index statistics independently based on the 10% rule.
Firebird does not have a method for manually recalculating index statistics like Microsoft SQL Server (see above).
For a Vertec database convert, the statistics are recalculated. This is done at each Vertec update.
However, during migrations – i.e. when started with an empty Vertec database and migrating a lot of data – the statistics are not calculated. In this case, the index statistics still need to be created. There are the following options:
SP_VTC_UPDATESTATS
:Start with
EXECUTE PROCEDURE sp_vtc_updatestats;
And important: Only the commit performs the actual action:
“C:\Program Files\Firebird\isql.exe” -user sysdba -password xyz localhost:\Program Files\Vertec\DB\Vertec.FDB -input C:\Program Files\Vertec\DB\indexstats.txt
In the file Indexstats.txt
itself contains the following rows:
EXECUTE PROCEDURE SP_VTC_UPDATESTATS; COMMIT;
set term ^; execute block as declare variable ix varchar(31); begin for select rdb$indices.rdb$index_name from rdb$indices into ix do execute statement 'SET STATISTICS INDEX '||ix ; end^ set term ;^
The code can simply be copied into the SQL Editor and click on the button as above
Execute
and then on Commit
clicked: