SlideShare a Scribd company logo
45 ways to optimize
firebirdSQL
Fabio Codebue
Firebird Foundation
Committe Member
WHERE OPTIMIZE
•Hardware optimization
•Firebird server configuration
optimization
•Programming optimization
•SQL optimization
HARDWARE OPTIMIZATION
HARDWARE OPTIMIZATION
•Put database to SSD
• Put your database on SSD.
• SSD drive provides much better random IO than
traditional drives.
• Random IO is critical for reading and
writing data distributed through
big database file - the majority of
database operations require
intensive parallel random IO.
HARDWARE OPTIMIZATION
•Use RAID 10
• If you use RAID1 or RAID5, consider RAID10
• RAID10 it is 15-25% faster.
HARDWARE OPTIMIZATION
•Use BBU
• If you are using RAID controller, check that it has Backup
Battery Unit (BBU) installed and operational – some vendors
do not provide BBU by default.
• Without BBU, the controller disables the cache, and RAID
works very slow, even slower than usual SATA drives.
• Usually, you can check BBU status in the RAID configuration
tool.
HARDWARE OPTIMIZATION
•Set write cache to write-back
• If you are using RAID controller with installed BBU (and
server with UPS), check that its cache is set to write-back
(not write-through).
• «Write-back» enables write cache of the controller.
HARDWARE OPTIMIZATION
•Enable read cache
• If you use RAID controller
check that it has enabled read cache
HARDWARE OPTIMIZATION
•Check disk subsystem
• Check your drives for bad blocks and other hardware
problems (including overheating).
• Hardware problems can significantly decrease IO
performance and lead to database corruptions.
FIREBIRD CONF OPTIMIZATION
Firebird 2.5
•Use SuperClassic or Classic in Firebird
• If you use Firebird 2.5 SuperServer with many
connections, try to use SuperClassic or Classic, they can
scale better by using all cores of CPU.
FIREBIRD OPTIMIZATION
Firebird 3.x
•Use SuperServer 3.0
• If you use Classic or SuperClassic in 2.5, consider
migration to Firebird 3.0 SuperServer
• Now it can use multiple cores and combine it with the
advantages of the shared cache.
FIREBIRD CONF OPTIMIZATION
•Increase page buffers cache
• Increase the size of page buffers cache (parameter
DefaultDBCachePages) from the default values.
• For 2.5 SuperServer we recommend 10000 pages,
• For 3.0 SuperServer – 50000 pages
• For Classic and SuperClassic – from 256 to 2048 pages.
• However, don't set page buffers cache value too high – cache
synchronization has its cost, and the idea to put all database
into RAM by tuning this value will not work.
FIREBIRD CONF OPTIMIZE
FIREBIRD CONF OPTIMIZATION
•Increase memory size for sort operations
• Increase the value of TempCacheLimit parameter in
firebird.conf
• It specifies the size of the cache of the temporary space for
sorting.
• Default values are too low
• 8Mb for Classic and 64Mb for SuperServer
• Use at least
• 64Mb for Classic
• 1Gb for SuperServer and SuperClassic.
FIREBIRD CONF OPTIMIZATION
•Set Forced Writes Off – ATTENTION!!!
• If you have intensive insert or update activity
• You can check it with HQbird MonLogger,
• If you have UPS and replication installed to protect from
hardware failures, consider to set Forced Writes settings to
OFF, it can increase speed of write operations up to 3 times.
FIREBIRD CONF OPTIMIZATION
•Increase number of hash slots for
Classic/SuperClassic
• Increase the value of LockHashSlots parameter for Classic
and SuperClassic from the default 1009 to some big prime
number (30011, for example)
• It will decrease queues in the internal locking mechanism
FIREBIRD CONF OPTIMIZATION
Firebird 2.5
•Use CPU Affinity for Super Server
•Set CPUAffinity parameter to the value equal to the
number of databases in use:
•SuperServer in 2.5 can use different CPU cores to
process requests for the certain databases.
• CpuAffinityMask = n
The value is taken from a bit map in which each bit represents a CPU.
Thus, to use only the first processor, the value is 1.
To use both
CPU 1 and CPU 2, the value is 3.
To use CPU 2 and CPU 3, the value is 6.
FIREBIRD CONF OPTIMIZATION
•Use fast drive for temp space
• Set the first part of TempDirectory parameter in
firebird.conf to the fast disk – SSD or RAM drive.
• It will decrease the time of big sortings – for example
when the database is being restored.
TempDirectories = c:temp;d:temp
FIREBIRD CONF OPTIMIZATION
•Store backups on another drive
• Store database backups on the dedicated physical drive
(RAID).
• It will separate read and write IO during backup, and
increase backup speed and decrease load for the main
drive.
• It is especially important when backups are taken while
users are working with the database.
PROGRAMMING OPTIMIZATION
PROGRAMMING OPTIMIZATION
•Deactivate indices for bulk inserts
• If you insert or update many records (more than 25% of
the table), deactivate indices for the table where records
are inserted and reactivate them after insert or update.
• The index rebuild operation can be faster than many
updates of the index.
PROGRAMMING OPTIMIZATION
•Use Global Temporary Tables for fast
inserts
• To speed up inserts and updates, use Global Temporary
Tables for bulk inserts of the large recordsets,
• and then transfer records into the permanent table.
GTT TABLE
Massive
insert
process
PROGRAMMING OPTIMIZATION
•Avoid unnecessary indices
• Use fewer indices for tables with intensive inserts and
updates.
• Each index adds significant overhead for insert, update,
delete, and garbage collection operations
• There could be 3-4 additional page reads and writes when
the single record is being inserted, updated, deleted,
cleaned for each index.
PROGRAMMING OPTIMIZATION
•Replace UDFs with embedded functions
calls
• Replace UDF calls with embedded functions calls.
• Many embedded functions were added in the recent
versions of Firebird, which offer functionality previously
available only in UDF libraries.
• Replace such functions where possible, since embedded
functions work up to 3 times faster than UDFs.
PROGRAMMING OPTIMIZATION
•Use read-only transactions for read
operations
• Use read-only transactions for operations which do not
change record (i.e., SELECTs) with isolation mode = read
committed.
• Such transactions do not retain record versions from the
garbage collection, and can run indefinitely
• They do not affect database performance.
PROGRAMMING OPTIMIZATION
•Use short write transactions and get rid
of ALL long-running
• Use short writeable transactions (for operations INSERT,UPDATE,
DELETE).
• The shorter writeable transaction is, the better.
• The short transactions retain proportionally less number of record
versions from garbage collection than long-running. Unfortunately,
even the single long-running transaction (from the development tool
left open, for example) can screw the good effect of all other short
writeable transaction.
• That's why you need to monitor long-running transaction and fix the
appropriate places in the source code.
PROGRAMMING OPTIMIZATION
•Avoid long record chains
• Avoid situations when one record has many record
versions
• Firebird works much slower with long record chains. (to
see how many record versions some tables has, and what
is the longest record chain you can use HQbird IBAnalyst
tool, tab Tables, sort on "Max Version").
• Use the combination of inserts and scheduled delete of
old records instead of multiple updates of the same
record.
SQL OPTIMIZATION
SQL OPTIMIZATION
•Use PREPARE correctly
• Use prepared statements to run SQL queries where only
parameters are changed
for example, make prepare before the loop of such queries.
• Prepare can take significant time (especially for big
tables), and preparing the query only once will greatly
increase the overall performance.
SQL OPTIMIZATION
•Don't COMMIT too often during bulk
insert/update operation
• In the case of bulk INSERT/UPDATE/DELETE operation,
don't commit the transaction after each change
• It can happen if you are using auto commit option in your
database driver
• Commit transactions at least after 1000 operations or
more.
• Each transaction commit runs several read/write IO
operations against the database, that's why often
commits decrease database performance.
SQL OPTIMIZATION
•"Turn off" indices if you are using IN
with many constants
• If you are using construction
WHERE fieldX IN (Constant1, Constant2,… ConstantN)
and there is an index on fieldX, Firebird will use an index as
many times as many constants are in the IN list.
Disable index search by turning fieldX into expression +0:
WHERE fieldX+0 IN (Constant1, Constant2,… ConstantN), or,
for strings, use fieldX||''
SQL OPTIMIZATION
•Replace IN with JOIN
• Avoid using queries with nested WHERE IN(SELECT...
WHERE IN (SELECT.. WHERE IN() ))
• It can confuse Firebird optimizer.
• Transform nested INs into joins.
SQL OPTIMIZATION
•Use LEFT JOIN in the correct way
• If you are using LEFT OUTER joins, explicitly put tables in
the join from the smallest one to the largest one.
SQL OPTIMIZATION
•Limit fetch of SELECT queries
• Always try to limit the large output for SELECT queries
with FIRST… SKIP or ROWS clauses.
• If the query is not designed specifically as a report (which
requires all records to be printed/exported), usually it is
enough to show top 10-100 records.
• Fetch only necessary records.
SQL OPTIMIZATION
•Specify less number of columns in
SELECT with ORDER BY/GROUP BY
• Reduce the number of columns and their summary width in
queries with ORDER BY/GROUP BY both in SELECT part (i.e.,
fields to be shown) and in the ORDER BY clause.
• Firebird merges columns from SELECT and ORDER BY/GROUP
BY clauses and sorts them in memory (or, if memory is not
enough, on the disk).
• A long VARCHAR in SELECT, the size of the sort files can be
really large (many gigabytes).
SQL OPTIMIZATION
•Use derived tables to optimize SELECT
with ORDER BY/GROUP BY
• Another way to optimize SQL query with sorting is to use
derived tables to avoid unnecessary sort operations.
SELECT T.FIELD_KEY, T.FIELD1, T.FIELD2, ... T.FIELD_N
FROM (SELECT FIELD_KEY FROM T ORDER BY FIELD2)
T2
JOIN T ON T.FIELD_KEY = T2.FIELD_KEY
SELECT FIELD_KEY, FIELD1, FIELD2, ... FIELD_N
FROM T
ORDER BY FIELD2
SQL OPTIMIZATION
•Store short strings in VARCHAR, large in
BLOBs
• To store short character data, use VARCHARs,
• To store long texts, use BLOBs.
Varchars are faster for the small pieces of data because they
are stored in the record, and the whole record is read during
the same IO cycle, and if record size is less than 2/3 of the
database page size, the whole record is stored on the same
database page.
BLOBs are stored outside of the record, and require the
additional round of IO to read it, and they show the advantage
with reading and writing long strings.
SQL OPTIMIZATION
•Exclude BLOB columns from the large
SELECTs
• Exclude BLOB columns from the large SELECTs.
• Use a kind of late binding with sub-selects to selectively
show information from BLOBs
(for example, show the content of the document).
SQL OPTIMIZATION
•Use BIGINT for primary and unique keys
• Use BIGINT type for auto-incremented primary and
unique keys and for identifiers of all types.
• Operations with BIGINT are the fastest
• BIGINT has enough capacity to store almost all data
ranges.
SQL OPTIMIZATION
•Don't use VARCHARs for keys
• Don't use VARCHAR for identifiers unless it is really
necessary
• Operations with them are far less effective than with
integer columns.
• Especially avoid GUIDs, as identifier
due to the random distribution of GUID values
INSERT/UPDATE operations with Primary/Unique Keys
GUIDs can be 20 times slower than with integers.
SQL OPTIMIZATION
•Recalculate indices statistics
• Recalculate indices statistics regularly.
• Update indices statistics for the tables with frequent or
massive changes with command SET STATISTICS
• It allows Firebird optimizer to choose better SQL plans.
• HQbird Firebird DataGuard can perform such recalculation of
indices statistics automatically according to the desired
schedule (usually once a week).
SQL OPTIMIZATION
•Use connection pool
• If database connections to Firebird database are short use
connection pool
typical for web-app in PHP use
function ibase_pconnect
instead of
ibase_connect
SQL OPTIMIZATION
Firebird 3.0
•Use LINGER option
• Database connections are short
• LINGER option to keep cache active during the specified amount
of time
• It will keep frequently used pages in the cache even if there will
be no other connections.
• For example, ALTER DATABASE SET LINGER TO 60 will keep the
cache for 60 seconds after the end of the last connection.
SQL OPTIMIZATION
Firebird 3.0
•Use HASH JOINs
• Case the of joining big and small tables, HASH JOIN could be
much faster than normal join which uses «nested loop» with
index.
• To make Firebird optimizer to use HASH join, use +0 in the
join condition:
T1 JOIN T2 ON T1.FIELD1+0 = T2.FIELD2+0
SQL OPTIMIZATION
Firebird 3.0
•Mark appropriate PSQL functions as
DETERMINISTIC
• Mark your PSQL functions which do not have parameters
and return constant values with keyword DETERMINISTIC.
• The deterministic functions are calculated and cached in the
scope of the current query.
SQL OPTIMIZATION
Firebird 3.0
•Use analytical (window) functions
• If you are running SELECT with simultaneous output of some
column and aggregated function for it, use window (analytical)
functions
• it is faster than the subquery or 2 queries
SELECT id, department, salary, salary /
(select sum(salary) from employee) percentage
FROM employee
SELECT id, department, salary, salary /
sum(salary) OVER () percentage
FROM employee
SQL OPTIMIZATION
•Use switch -se for gbak
• Use switch –se to increase gbak backup and/or restore
speed up to 20%
gbak -b -g -se service_mgr c:dbdata.fdb e:backupdata.fbk
SQL OPTIMIZATION
•WHERE CURRENT OF
• The fastest way to process records fetched by the cursor in
PSQL is the clause
where current of <>
It is faster than
where rb$db_key = :v_db_key
and much faster than search with a primary or unique key.
SQL OPTIMIZATION
•Avoid often queries to monitoring tables
• Don't run queries to Firebird monitoring tables (MON$)
too often
such queries consume significant resources and can greatly
decrease the performance of the main business logic.
Recommend running MON$ queries not often than once
per minute.
SQL OPTIMIZATION
•Use NO_AUTO_UNDO option for bulk
inserts/updates
• If you are running many DML (Update/Insert/Delete)
commands in the frames of the same transaction, Firebird
merges undo-log of each command with undo-log of the
transaction.
• To speed up bulk DML operations start the transaction
with «NO AUTO UNDO» option, in order to do not merge
undo-logs of each command with the transaction's undo-
log.
SQL OPTIMIZATION
Firebird 3.0
•Do not use SRP authentication in if you
don't need it
• Does not use SRP users authentication if you don't really
need it
• Connect with SRP authentication is established slower
than the regular connection.
Thanks…
Fabio Codebue
Firebird Foundation
Committe Member
f.codebue@p-soft.biz
www.p-soft.biz
Firebird Optimization www.ibsurgeon.it
Ad

More Related Content

What's hot (20)

Spark Shuffle Deep Dive (Explained In Depth) - How Shuffle Works in Spark
Spark Shuffle Deep Dive (Explained In Depth) - How Shuffle Works in SparkSpark Shuffle Deep Dive (Explained In Depth) - How Shuffle Works in Spark
Spark Shuffle Deep Dive (Explained In Depth) - How Shuffle Works in Spark
Bo Yang
 
Css position
Css positionCss position
Css position
Webtech Learning
 
Spark SQL Join Improvement at Facebook
Spark SQL Join Improvement at FacebookSpark SQL Join Improvement at Facebook
Spark SQL Join Improvement at Facebook
Databricks
 
JavaScript guide 2020 Learn JavaScript
JavaScript guide 2020 Learn JavaScriptJavaScript guide 2020 Learn JavaScript
JavaScript guide 2020 Learn JavaScript
Laurence Svekis ✔
 
Xampp installation guide
Xampp installation guideXampp installation guide
Xampp installation guide
Amira Elsayed Ismail
 
Db2 recovery IDUG EMEA 2013
Db2 recovery IDUG EMEA 2013Db2 recovery IDUG EMEA 2013
Db2 recovery IDUG EMEA 2013
Dale McInnis
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
Jussi Pohjolainen
 
Useful Linux and Unix commands handbook
Useful Linux and Unix commands handbookUseful Linux and Unix commands handbook
Useful Linux and Unix commands handbook
Wave Digitech
 
DYNAMIC HYPERTEXT MARKUP LANGUAGE (DHTML) & CSS WITH Application of JavaScript
DYNAMIC HYPERTEXT MARKUP LANGUAGE (DHTML) & CSS WITH Application of JavaScriptDYNAMIC HYPERTEXT MARKUP LANGUAGE (DHTML) & CSS WITH Application of JavaScript
DYNAMIC HYPERTEXT MARKUP LANGUAGE (DHTML) & CSS WITH Application of JavaScript
Soumen Santra
 
Web browser architecture.pptx
Web browser architecture.pptxWeb browser architecture.pptx
Web browser architecture.pptx
BabarHussain607332
 
Div tag presentation
Div tag presentationDiv tag presentation
Div tag presentation
alyssa_lum11
 
Html vs xhtml
Html vs xhtmlHtml vs xhtml
Html vs xhtml
Yastee Shah
 
ORC improvement in Apache Spark 2.3
ORC improvement in Apache Spark 2.3ORC improvement in Apache Spark 2.3
ORC improvement in Apache Spark 2.3
DataWorks Summit
 
Xhtml
XhtmlXhtml
Xhtml
Manav Prasad
 
Html and css
Html and cssHtml and css
Html and css
Sukrit Gupta
 
Html tutorials
Html tutorialsHtml tutorials
Html tutorials
Deputy Chief Librarian & Head
 
Javascript alert and confrim box
Javascript alert and confrim boxJavascript alert and confrim box
Javascript alert and confrim box
Jesus Obenita Jr.
 
PostgreSQL Tuning: O elefante mais rápido que um leopardo
PostgreSQL Tuning: O elefante mais rápido que um leopardoPostgreSQL Tuning: O elefante mais rápido que um leopardo
PostgreSQL Tuning: O elefante mais rápido que um leopardo
elliando dias
 
Understanding How CQL3 Maps to Cassandra's Internal Data Structure
Understanding How CQL3 Maps to Cassandra's Internal Data StructureUnderstanding How CQL3 Maps to Cassandra's Internal Data Structure
Understanding How CQL3 Maps to Cassandra's Internal Data Structure
DataStax
 
Html
HtmlHtml
Html
Nandakumar Ganapathy
 
Spark Shuffle Deep Dive (Explained In Depth) - How Shuffle Works in Spark
Spark Shuffle Deep Dive (Explained In Depth) - How Shuffle Works in SparkSpark Shuffle Deep Dive (Explained In Depth) - How Shuffle Works in Spark
Spark Shuffle Deep Dive (Explained In Depth) - How Shuffle Works in Spark
Bo Yang
 
Spark SQL Join Improvement at Facebook
Spark SQL Join Improvement at FacebookSpark SQL Join Improvement at Facebook
Spark SQL Join Improvement at Facebook
Databricks
 
JavaScript guide 2020 Learn JavaScript
JavaScript guide 2020 Learn JavaScriptJavaScript guide 2020 Learn JavaScript
JavaScript guide 2020 Learn JavaScript
Laurence Svekis ✔
 
Db2 recovery IDUG EMEA 2013
Db2 recovery IDUG EMEA 2013Db2 recovery IDUG EMEA 2013
Db2 recovery IDUG EMEA 2013
Dale McInnis
 
Useful Linux and Unix commands handbook
Useful Linux and Unix commands handbookUseful Linux and Unix commands handbook
Useful Linux and Unix commands handbook
Wave Digitech
 
DYNAMIC HYPERTEXT MARKUP LANGUAGE (DHTML) & CSS WITH Application of JavaScript
DYNAMIC HYPERTEXT MARKUP LANGUAGE (DHTML) & CSS WITH Application of JavaScriptDYNAMIC HYPERTEXT MARKUP LANGUAGE (DHTML) & CSS WITH Application of JavaScript
DYNAMIC HYPERTEXT MARKUP LANGUAGE (DHTML) & CSS WITH Application of JavaScript
Soumen Santra
 
Div tag presentation
Div tag presentationDiv tag presentation
Div tag presentation
alyssa_lum11
 
ORC improvement in Apache Spark 2.3
ORC improvement in Apache Spark 2.3ORC improvement in Apache Spark 2.3
ORC improvement in Apache Spark 2.3
DataWorks Summit
 
Javascript alert and confrim box
Javascript alert and confrim boxJavascript alert and confrim box
Javascript alert and confrim box
Jesus Obenita Jr.
 
PostgreSQL Tuning: O elefante mais rápido que um leopardo
PostgreSQL Tuning: O elefante mais rápido que um leopardoPostgreSQL Tuning: O elefante mais rápido que um leopardo
PostgreSQL Tuning: O elefante mais rápido que um leopardo
elliando dias
 
Understanding How CQL3 Maps to Cassandra's Internal Data Structure
Understanding How CQL3 Maps to Cassandra's Internal Data StructureUnderstanding How CQL3 Maps to Cassandra's Internal Data Structure
Understanding How CQL3 Maps to Cassandra's Internal Data Structure
DataStax
 

Similar to 45 ways to speed up firebird database (20)

Maaz Anjum - IOUG Collaborate 2013 - An Insight into Space Realization on ODA...
Maaz Anjum - IOUG Collaborate 2013 - An Insight into Space Realization on ODA...Maaz Anjum - IOUG Collaborate 2013 - An Insight into Space Realization on ODA...
Maaz Anjum - IOUG Collaborate 2013 - An Insight into Space Realization on ODA...
Maaz Anjum
 
Azure Data Factory Data Flow Performance Tuning 101
Azure Data Factory Data Flow Performance Tuning 101Azure Data Factory Data Flow Performance Tuning 101
Azure Data Factory Data Flow Performance Tuning 101
Mark Kromer
 
VLDB Administration Strategies
VLDB Administration StrategiesVLDB Administration Strategies
VLDB Administration Strategies
Murilo Miranda
 
Pre and post tips to installing sql server correctly
Pre and post tips to installing sql server correctlyPre and post tips to installing sql server correctly
Pre and post tips to installing sql server correctly
Antonios Chatzipavlis
 
Mapping Data Flows Perf Tuning April 2021
Mapping Data Flows Perf Tuning April 2021Mapping Data Flows Perf Tuning April 2021
Mapping Data Flows Perf Tuning April 2021
Mark Kromer
 
Tuning Linux Windows and Firebird for Heavy Workload
Tuning Linux Windows and Firebird for Heavy WorkloadTuning Linux Windows and Firebird for Heavy Workload
Tuning Linux Windows and Firebird for Heavy Workload
Marius Adrian Popa
 
Taking Splunk to the Next Level - Architecture Breakout Session
Taking Splunk to the Next Level - Architecture Breakout SessionTaking Splunk to the Next Level - Architecture Breakout Session
Taking Splunk to the Next Level - Architecture Breakout Session
Splunk
 
MariaDB Performance Tuning and Optimization
MariaDB Performance Tuning and OptimizationMariaDB Performance Tuning and Optimization
MariaDB Performance Tuning and Optimization
MariaDB plc
 
Redshift overview
Redshift overviewRedshift overview
Redshift overview
Amazon Web Services LATAM
 
Presentation db2 best practices for optimal performance
Presentation   db2 best practices for optimal performancePresentation   db2 best practices for optimal performance
Presentation db2 best practices for optimal performance
solarisyougood
 
Webinar slides: Our Guide to MySQL & MariaDB Performance Tuning
Webinar slides: Our Guide to MySQL & MariaDB Performance TuningWebinar slides: Our Guide to MySQL & MariaDB Performance Tuning
Webinar slides: Our Guide to MySQL & MariaDB Performance Tuning
Severalnines
 
505 kobal exadata
505 kobal exadata505 kobal exadata
505 kobal exadata
Kam Chan
 
MySQL Performance - Best practices
MySQL Performance - Best practices MySQL Performance - Best practices
MySQL Performance - Best practices
Ted Wennmark
 
MariaDB Server Performance Tuning & Optimization
MariaDB Server Performance Tuning & OptimizationMariaDB Server Performance Tuning & Optimization
MariaDB Server Performance Tuning & Optimization
MariaDB plc
 
Colvin exadata mistakes_ioug_2014
Colvin exadata mistakes_ioug_2014Colvin exadata mistakes_ioug_2014
Colvin exadata mistakes_ioug_2014
marvin herrera
 
Presentation db2 best practices for optimal performance
Presentation   db2 best practices for optimal performancePresentation   db2 best practices for optimal performance
Presentation db2 best practices for optimal performance
xKinAnx
 
Dba tuning
Dba tuningDba tuning
Dba tuning
Maximiliano Accotto
 
Red Hat Ceph Storage Acceleration Utilizing Flash Technology
Red Hat Ceph Storage Acceleration Utilizing Flash Technology Red Hat Ceph Storage Acceleration Utilizing Flash Technology
Red Hat Ceph Storage Acceleration Utilizing Flash Technology
Red_Hat_Storage
 
Aioug vizag oracle12c_new_features
Aioug vizag oracle12c_new_featuresAioug vizag oracle12c_new_features
Aioug vizag oracle12c_new_features
AiougVizagChapter
 
VMworld Europe 2014: Advanced SQL Server on vSphere Techniques and Best Pract...
VMworld Europe 2014: Advanced SQL Server on vSphere Techniques and Best Pract...VMworld Europe 2014: Advanced SQL Server on vSphere Techniques and Best Pract...
VMworld Europe 2014: Advanced SQL Server on vSphere Techniques and Best Pract...
VMworld
 
Maaz Anjum - IOUG Collaborate 2013 - An Insight into Space Realization on ODA...
Maaz Anjum - IOUG Collaborate 2013 - An Insight into Space Realization on ODA...Maaz Anjum - IOUG Collaborate 2013 - An Insight into Space Realization on ODA...
Maaz Anjum - IOUG Collaborate 2013 - An Insight into Space Realization on ODA...
Maaz Anjum
 
Azure Data Factory Data Flow Performance Tuning 101
Azure Data Factory Data Flow Performance Tuning 101Azure Data Factory Data Flow Performance Tuning 101
Azure Data Factory Data Flow Performance Tuning 101
Mark Kromer
 
VLDB Administration Strategies
VLDB Administration StrategiesVLDB Administration Strategies
VLDB Administration Strategies
Murilo Miranda
 
Pre and post tips to installing sql server correctly
Pre and post tips to installing sql server correctlyPre and post tips to installing sql server correctly
Pre and post tips to installing sql server correctly
Antonios Chatzipavlis
 
Mapping Data Flows Perf Tuning April 2021
Mapping Data Flows Perf Tuning April 2021Mapping Data Flows Perf Tuning April 2021
Mapping Data Flows Perf Tuning April 2021
Mark Kromer
 
Tuning Linux Windows and Firebird for Heavy Workload
Tuning Linux Windows and Firebird for Heavy WorkloadTuning Linux Windows and Firebird for Heavy Workload
Tuning Linux Windows and Firebird for Heavy Workload
Marius Adrian Popa
 
Taking Splunk to the Next Level - Architecture Breakout Session
Taking Splunk to the Next Level - Architecture Breakout SessionTaking Splunk to the Next Level - Architecture Breakout Session
Taking Splunk to the Next Level - Architecture Breakout Session
Splunk
 
MariaDB Performance Tuning and Optimization
MariaDB Performance Tuning and OptimizationMariaDB Performance Tuning and Optimization
MariaDB Performance Tuning and Optimization
MariaDB plc
 
Presentation db2 best practices for optimal performance
Presentation   db2 best practices for optimal performancePresentation   db2 best practices for optimal performance
Presentation db2 best practices for optimal performance
solarisyougood
 
Webinar slides: Our Guide to MySQL & MariaDB Performance Tuning
Webinar slides: Our Guide to MySQL & MariaDB Performance TuningWebinar slides: Our Guide to MySQL & MariaDB Performance Tuning
Webinar slides: Our Guide to MySQL & MariaDB Performance Tuning
Severalnines
 
505 kobal exadata
505 kobal exadata505 kobal exadata
505 kobal exadata
Kam Chan
 
MySQL Performance - Best practices
MySQL Performance - Best practices MySQL Performance - Best practices
MySQL Performance - Best practices
Ted Wennmark
 
MariaDB Server Performance Tuning & Optimization
MariaDB Server Performance Tuning & OptimizationMariaDB Server Performance Tuning & Optimization
MariaDB Server Performance Tuning & Optimization
MariaDB plc
 
Colvin exadata mistakes_ioug_2014
Colvin exadata mistakes_ioug_2014Colvin exadata mistakes_ioug_2014
Colvin exadata mistakes_ioug_2014
marvin herrera
 
Presentation db2 best practices for optimal performance
Presentation   db2 best practices for optimal performancePresentation   db2 best practices for optimal performance
Presentation db2 best practices for optimal performance
xKinAnx
 
Red Hat Ceph Storage Acceleration Utilizing Flash Technology
Red Hat Ceph Storage Acceleration Utilizing Flash Technology Red Hat Ceph Storage Acceleration Utilizing Flash Technology
Red Hat Ceph Storage Acceleration Utilizing Flash Technology
Red_Hat_Storage
 
Aioug vizag oracle12c_new_features
Aioug vizag oracle12c_new_featuresAioug vizag oracle12c_new_features
Aioug vizag oracle12c_new_features
AiougVizagChapter
 
VMworld Europe 2014: Advanced SQL Server on vSphere Techniques and Best Pract...
VMworld Europe 2014: Advanced SQL Server on vSphere Techniques and Best Pract...VMworld Europe 2014: Advanced SQL Server on vSphere Techniques and Best Pract...
VMworld Europe 2014: Advanced SQL Server on vSphere Techniques and Best Pract...
VMworld
 
Ad

Recently uploaded (20)

Expand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchangeExpand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchange
Fexle Services Pvt. Ltd.
 
Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]
saniaaftab72555
 
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
Andre Hora
 
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRYLEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
NidaFarooq10
 
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
steaveroggers
 
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Orangescrum
 
Societal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainabilitySocietal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainability
Jordi Cabot
 
Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025
kashifyounis067
 
Adobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest VersionAdobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest Version
kashifyounis067
 
Landscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature ReviewLandscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature Review
Hironori Washizaki
 
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Dele Amefo
 
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Lionel Briand
 
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage DashboardsAdobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
BradBedford3
 
EASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License CodeEASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License Code
aneelaramzan63
 
Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025
mu394968
 
PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025
mu394968
 
Top 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docxTop 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docx
Portli
 
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
ssuserb14185
 
FL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full VersionFL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full Version
tahirabibi60507
 
Kubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptxKubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptx
CloudScouts
 
Expand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchangeExpand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchange
Fexle Services Pvt. Ltd.
 
Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]
saniaaftab72555
 
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
Andre Hora
 
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRYLEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
NidaFarooq10
 
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
steaveroggers
 
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Orangescrum
 
Societal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainabilitySocietal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainability
Jordi Cabot
 
Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025
kashifyounis067
 
Adobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest VersionAdobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest Version
kashifyounis067
 
Landscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature ReviewLandscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature Review
Hironori Washizaki
 
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Dele Amefo
 
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Lionel Briand
 
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage DashboardsAdobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
BradBedford3
 
EASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License CodeEASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License Code
aneelaramzan63
 
Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025
mu394968
 
PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025
mu394968
 
Top 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docxTop 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docx
Portli
 
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
ssuserb14185
 
FL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full VersionFL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full Version
tahirabibi60507
 
Kubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptxKubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptx
CloudScouts
 
Ad

45 ways to speed up firebird database

  • 1. 45 ways to optimize firebirdSQL Fabio Codebue Firebird Foundation Committe Member
  • 2. WHERE OPTIMIZE •Hardware optimization •Firebird server configuration optimization •Programming optimization •SQL optimization
  • 4. HARDWARE OPTIMIZATION •Put database to SSD • Put your database on SSD. • SSD drive provides much better random IO than traditional drives. • Random IO is critical for reading and writing data distributed through big database file - the majority of database operations require intensive parallel random IO.
  • 5. HARDWARE OPTIMIZATION •Use RAID 10 • If you use RAID1 or RAID5, consider RAID10 • RAID10 it is 15-25% faster.
  • 6. HARDWARE OPTIMIZATION •Use BBU • If you are using RAID controller, check that it has Backup Battery Unit (BBU) installed and operational – some vendors do not provide BBU by default. • Without BBU, the controller disables the cache, and RAID works very slow, even slower than usual SATA drives. • Usually, you can check BBU status in the RAID configuration tool.
  • 7. HARDWARE OPTIMIZATION •Set write cache to write-back • If you are using RAID controller with installed BBU (and server with UPS), check that its cache is set to write-back (not write-through). • «Write-back» enables write cache of the controller.
  • 8. HARDWARE OPTIMIZATION •Enable read cache • If you use RAID controller check that it has enabled read cache
  • 9. HARDWARE OPTIMIZATION •Check disk subsystem • Check your drives for bad blocks and other hardware problems (including overheating). • Hardware problems can significantly decrease IO performance and lead to database corruptions.
  • 10. FIREBIRD CONF OPTIMIZATION Firebird 2.5 •Use SuperClassic or Classic in Firebird • If you use Firebird 2.5 SuperServer with many connections, try to use SuperClassic or Classic, they can scale better by using all cores of CPU.
  • 11. FIREBIRD OPTIMIZATION Firebird 3.x •Use SuperServer 3.0 • If you use Classic or SuperClassic in 2.5, consider migration to Firebird 3.0 SuperServer • Now it can use multiple cores and combine it with the advantages of the shared cache.
  • 12. FIREBIRD CONF OPTIMIZATION •Increase page buffers cache • Increase the size of page buffers cache (parameter DefaultDBCachePages) from the default values. • For 2.5 SuperServer we recommend 10000 pages, • For 3.0 SuperServer – 50000 pages • For Classic and SuperClassic – from 256 to 2048 pages. • However, don't set page buffers cache value too high – cache synchronization has its cost, and the idea to put all database into RAM by tuning this value will not work.
  • 14. FIREBIRD CONF OPTIMIZATION •Increase memory size for sort operations • Increase the value of TempCacheLimit parameter in firebird.conf • It specifies the size of the cache of the temporary space for sorting. • Default values are too low • 8Mb for Classic and 64Mb for SuperServer • Use at least • 64Mb for Classic • 1Gb for SuperServer and SuperClassic.
  • 15. FIREBIRD CONF OPTIMIZATION •Set Forced Writes Off – ATTENTION!!! • If you have intensive insert or update activity • You can check it with HQbird MonLogger, • If you have UPS and replication installed to protect from hardware failures, consider to set Forced Writes settings to OFF, it can increase speed of write operations up to 3 times.
  • 16. FIREBIRD CONF OPTIMIZATION •Increase number of hash slots for Classic/SuperClassic • Increase the value of LockHashSlots parameter for Classic and SuperClassic from the default 1009 to some big prime number (30011, for example) • It will decrease queues in the internal locking mechanism
  • 17. FIREBIRD CONF OPTIMIZATION Firebird 2.5 •Use CPU Affinity for Super Server •Set CPUAffinity parameter to the value equal to the number of databases in use: •SuperServer in 2.5 can use different CPU cores to process requests for the certain databases. • CpuAffinityMask = n The value is taken from a bit map in which each bit represents a CPU. Thus, to use only the first processor, the value is 1. To use both CPU 1 and CPU 2, the value is 3. To use CPU 2 and CPU 3, the value is 6.
  • 18. FIREBIRD CONF OPTIMIZATION •Use fast drive for temp space • Set the first part of TempDirectory parameter in firebird.conf to the fast disk – SSD or RAM drive. • It will decrease the time of big sortings – for example when the database is being restored. TempDirectories = c:temp;d:temp
  • 19. FIREBIRD CONF OPTIMIZATION •Store backups on another drive • Store database backups on the dedicated physical drive (RAID). • It will separate read and write IO during backup, and increase backup speed and decrease load for the main drive. • It is especially important when backups are taken while users are working with the database.
  • 21. PROGRAMMING OPTIMIZATION •Deactivate indices for bulk inserts • If you insert or update many records (more than 25% of the table), deactivate indices for the table where records are inserted and reactivate them after insert or update. • The index rebuild operation can be faster than many updates of the index.
  • 22. PROGRAMMING OPTIMIZATION •Use Global Temporary Tables for fast inserts • To speed up inserts and updates, use Global Temporary Tables for bulk inserts of the large recordsets, • and then transfer records into the permanent table. GTT TABLE Massive insert process
  • 23. PROGRAMMING OPTIMIZATION •Avoid unnecessary indices • Use fewer indices for tables with intensive inserts and updates. • Each index adds significant overhead for insert, update, delete, and garbage collection operations • There could be 3-4 additional page reads and writes when the single record is being inserted, updated, deleted, cleaned for each index.
  • 24. PROGRAMMING OPTIMIZATION •Replace UDFs with embedded functions calls • Replace UDF calls with embedded functions calls. • Many embedded functions were added in the recent versions of Firebird, which offer functionality previously available only in UDF libraries. • Replace such functions where possible, since embedded functions work up to 3 times faster than UDFs.
  • 25. PROGRAMMING OPTIMIZATION •Use read-only transactions for read operations • Use read-only transactions for operations which do not change record (i.e., SELECTs) with isolation mode = read committed. • Such transactions do not retain record versions from the garbage collection, and can run indefinitely • They do not affect database performance.
  • 26. PROGRAMMING OPTIMIZATION •Use short write transactions and get rid of ALL long-running • Use short writeable transactions (for operations INSERT,UPDATE, DELETE). • The shorter writeable transaction is, the better. • The short transactions retain proportionally less number of record versions from garbage collection than long-running. Unfortunately, even the single long-running transaction (from the development tool left open, for example) can screw the good effect of all other short writeable transaction. • That's why you need to monitor long-running transaction and fix the appropriate places in the source code.
  • 27. PROGRAMMING OPTIMIZATION •Avoid long record chains • Avoid situations when one record has many record versions • Firebird works much slower with long record chains. (to see how many record versions some tables has, and what is the longest record chain you can use HQbird IBAnalyst tool, tab Tables, sort on "Max Version"). • Use the combination of inserts and scheduled delete of old records instead of multiple updates of the same record.
  • 29. SQL OPTIMIZATION •Use PREPARE correctly • Use prepared statements to run SQL queries where only parameters are changed for example, make prepare before the loop of such queries. • Prepare can take significant time (especially for big tables), and preparing the query only once will greatly increase the overall performance.
  • 30. SQL OPTIMIZATION •Don't COMMIT too often during bulk insert/update operation • In the case of bulk INSERT/UPDATE/DELETE operation, don't commit the transaction after each change • It can happen if you are using auto commit option in your database driver • Commit transactions at least after 1000 operations or more. • Each transaction commit runs several read/write IO operations against the database, that's why often commits decrease database performance.
  • 31. SQL OPTIMIZATION •"Turn off" indices if you are using IN with many constants • If you are using construction WHERE fieldX IN (Constant1, Constant2,… ConstantN) and there is an index on fieldX, Firebird will use an index as many times as many constants are in the IN list. Disable index search by turning fieldX into expression +0: WHERE fieldX+0 IN (Constant1, Constant2,… ConstantN), or, for strings, use fieldX||''
  • 32. SQL OPTIMIZATION •Replace IN with JOIN • Avoid using queries with nested WHERE IN(SELECT... WHERE IN (SELECT.. WHERE IN() )) • It can confuse Firebird optimizer. • Transform nested INs into joins.
  • 33. SQL OPTIMIZATION •Use LEFT JOIN in the correct way • If you are using LEFT OUTER joins, explicitly put tables in the join from the smallest one to the largest one.
  • 34. SQL OPTIMIZATION •Limit fetch of SELECT queries • Always try to limit the large output for SELECT queries with FIRST… SKIP or ROWS clauses. • If the query is not designed specifically as a report (which requires all records to be printed/exported), usually it is enough to show top 10-100 records. • Fetch only necessary records.
  • 35. SQL OPTIMIZATION •Specify less number of columns in SELECT with ORDER BY/GROUP BY • Reduce the number of columns and their summary width in queries with ORDER BY/GROUP BY both in SELECT part (i.e., fields to be shown) and in the ORDER BY clause. • Firebird merges columns from SELECT and ORDER BY/GROUP BY clauses and sorts them in memory (or, if memory is not enough, on the disk). • A long VARCHAR in SELECT, the size of the sort files can be really large (many gigabytes).
  • 36. SQL OPTIMIZATION •Use derived tables to optimize SELECT with ORDER BY/GROUP BY • Another way to optimize SQL query with sorting is to use derived tables to avoid unnecessary sort operations. SELECT T.FIELD_KEY, T.FIELD1, T.FIELD2, ... T.FIELD_N FROM (SELECT FIELD_KEY FROM T ORDER BY FIELD2) T2 JOIN T ON T.FIELD_KEY = T2.FIELD_KEY SELECT FIELD_KEY, FIELD1, FIELD2, ... FIELD_N FROM T ORDER BY FIELD2
  • 37. SQL OPTIMIZATION •Store short strings in VARCHAR, large in BLOBs • To store short character data, use VARCHARs, • To store long texts, use BLOBs. Varchars are faster for the small pieces of data because they are stored in the record, and the whole record is read during the same IO cycle, and if record size is less than 2/3 of the database page size, the whole record is stored on the same database page. BLOBs are stored outside of the record, and require the additional round of IO to read it, and they show the advantage with reading and writing long strings.
  • 38. SQL OPTIMIZATION •Exclude BLOB columns from the large SELECTs • Exclude BLOB columns from the large SELECTs. • Use a kind of late binding with sub-selects to selectively show information from BLOBs (for example, show the content of the document).
  • 39. SQL OPTIMIZATION •Use BIGINT for primary and unique keys • Use BIGINT type for auto-incremented primary and unique keys and for identifiers of all types. • Operations with BIGINT are the fastest • BIGINT has enough capacity to store almost all data ranges.
  • 40. SQL OPTIMIZATION •Don't use VARCHARs for keys • Don't use VARCHAR for identifiers unless it is really necessary • Operations with them are far less effective than with integer columns. • Especially avoid GUIDs, as identifier due to the random distribution of GUID values INSERT/UPDATE operations with Primary/Unique Keys GUIDs can be 20 times slower than with integers.
  • 41. SQL OPTIMIZATION •Recalculate indices statistics • Recalculate indices statistics regularly. • Update indices statistics for the tables with frequent or massive changes with command SET STATISTICS • It allows Firebird optimizer to choose better SQL plans. • HQbird Firebird DataGuard can perform such recalculation of indices statistics automatically according to the desired schedule (usually once a week).
  • 42. SQL OPTIMIZATION •Use connection pool • If database connections to Firebird database are short use connection pool typical for web-app in PHP use function ibase_pconnect instead of ibase_connect
  • 43. SQL OPTIMIZATION Firebird 3.0 •Use LINGER option • Database connections are short • LINGER option to keep cache active during the specified amount of time • It will keep frequently used pages in the cache even if there will be no other connections. • For example, ALTER DATABASE SET LINGER TO 60 will keep the cache for 60 seconds after the end of the last connection.
  • 44. SQL OPTIMIZATION Firebird 3.0 •Use HASH JOINs • Case the of joining big and small tables, HASH JOIN could be much faster than normal join which uses «nested loop» with index. • To make Firebird optimizer to use HASH join, use +0 in the join condition: T1 JOIN T2 ON T1.FIELD1+0 = T2.FIELD2+0
  • 45. SQL OPTIMIZATION Firebird 3.0 •Mark appropriate PSQL functions as DETERMINISTIC • Mark your PSQL functions which do not have parameters and return constant values with keyword DETERMINISTIC. • The deterministic functions are calculated and cached in the scope of the current query.
  • 46. SQL OPTIMIZATION Firebird 3.0 •Use analytical (window) functions • If you are running SELECT with simultaneous output of some column and aggregated function for it, use window (analytical) functions • it is faster than the subquery or 2 queries SELECT id, department, salary, salary / (select sum(salary) from employee) percentage FROM employee SELECT id, department, salary, salary / sum(salary) OVER () percentage FROM employee
  • 47. SQL OPTIMIZATION •Use switch -se for gbak • Use switch –se to increase gbak backup and/or restore speed up to 20% gbak -b -g -se service_mgr c:dbdata.fdb e:backupdata.fbk
  • 48. SQL OPTIMIZATION •WHERE CURRENT OF • The fastest way to process records fetched by the cursor in PSQL is the clause where current of <> It is faster than where rb$db_key = :v_db_key and much faster than search with a primary or unique key.
  • 49. SQL OPTIMIZATION •Avoid often queries to monitoring tables • Don't run queries to Firebird monitoring tables (MON$) too often such queries consume significant resources and can greatly decrease the performance of the main business logic. Recommend running MON$ queries not often than once per minute.
  • 50. SQL OPTIMIZATION •Use NO_AUTO_UNDO option for bulk inserts/updates • If you are running many DML (Update/Insert/Delete) commands in the frames of the same transaction, Firebird merges undo-log of each command with undo-log of the transaction. • To speed up bulk DML operations start the transaction with «NO AUTO UNDO» option, in order to do not merge undo-logs of each command with the transaction's undo- log.
  • 51. SQL OPTIMIZATION Firebird 3.0 •Do not use SRP authentication in if you don't need it • Does not use SRP users authentication if you don't really need it • Connect with SRP authentication is established slower than the regular connection.
  • 52. Thanks… Fabio Codebue Firebird Foundation Committe Member [email protected] www.p-soft.biz Firebird Optimization www.ibsurgeon.it