The InterBase and Firebird Developer Magazine, Issue 4, 2006
The InterBase and Firebird Developer Magazine, Issue 4, 2006
THE INTERBASE
& FIREBIRD
Contents
DEVELOPER Editor notes
MAGAZINE by Alexey Kovyazin
Money for nothing ................................................................. 4
Oldest Active
by Helen Borrie
RTFM — regarding those free manuals ........................................... 5
Credits Community
by Carlos Cantu
Alexey Kovyazin,
About Dolphins and Birds ......................................................... 6
Chief Editor
Cover Story
Dmitri Kuzmenko,
by Paul Ruizendaal
Editor
The story of Fyracle ................................................................ 8
Helen Borrie,
Development area
Editor
by Paul Ruizendaal
Lev Tashchilin, Common Table Expression in Fyracle ............................................ 12
Designer
Products Overview
Editorial Office IBSurgeon Products .............................................................. 17
IBase IBDeveloper, office 5, Development area
1-st Novokuznetsky lane, 10 by Paul Ruizendaal
zip: 115184 Morfik's WebOS: Innovating beyond LAMP ..................................... 18
Moscow, Russia by Vlad Horsun
Phone: +7495 6869763 Global Temporary Tables in Fyracle .............................................. 23
Fax: +7495 9531334
TestBed
Email: by Alexey Kovyazin
[email protected] TPC-C based tests results ........................................................ 26
www.ibdeveloper.com Bonus
by Alexey Kovyazin
© Copyright 2005-2006 by
IB Developer. All rights reserved.
Comprehensive Repairing Guide. Part 1 ........................................ 35
www.ibdeveloper.com
© Copyright 2005-2006, All right reserved www.ibdeveloper.com
EDITOR'S NOTE 2006 ISSUE 4
www.ibdeveloper.com
© Copyright 2005-2006, All right reserved www.ibdeveloper.com
2006 ISSUE 4 OLDEST ACTIVE
www.ibdeveloper.com
© Copyright 2005-2006, All right reserved www.ibdeveloper.com
COMMUNITY 2006 ISSUE 4
www.ibdeveloper.com
© Copyright 2005-2006, All right reserved www.ibdeveloper.com
THE STORY of FYRACLE 2006 ISSUE 4
www.ibdeveloper.com 10
© Copyright 2005-2006, All right reserved www.ibdeveloper.com
2006 ISSUE 4 THE STORY of FYRACLE
In discussions it came up that it would a reasonable cross-platform GUI admin and a 128-bit data type come to mind.
be so much nicer if the architectural tool and agreed to create a special Fyr- • On the infrastructure side, Fyracle
layering of Firebird would be restored. acle plug-in for it. Tim O’Reilly was nice needs to implement a few of the more
This would mean that Firebird’s SQL enough to allow me to include some of commonly used predefined packages, in-
compiler (module “dsql” in the source his manuals into the developer kit. Fyr- cluding integration with a web server.
tree) would move from the Y-valve com- acle 0.8.0 was born in November 2004
ponent to the core engine component. and has gone through 10 dot-releases • Last but not least, it would be nice to
This would enable the use of dynamic since. resurrect the clustering code that was
SQL in the core engine, whereas it cur- once written for VAX clusters and use it
Two of those release contained major
rently relies on preprocessing. I argued to allow using Firebird on a Linux clus-
functionality provided by other team
that if the way this was done provided ter.
members. Vlad Horsun had worked out
a clean API for pluggable SQL compil- Fyracle has been fun for the team that
how to add global temporary tables to
ers, I could swap in my oracle-mode created it. I hope that it has been fun
Firebird, but his code was too late to be
SQL compiler for clients connecting in for you, the reader and user as well.
included in the FB2 release. Vlad kindly
oracle-mode. agreed to back-port his code from FB2
Special thanks
Jim did implement such a structure to FB15 and from there it was included
in the Vulcan branch of Firebird. I had in Fyracle in May 2005. I would like to use this opportunity to
promised to look into cleaning up the thank everybody who helped making
Eugeney Putilin had been working on Fyracle a reality, by giving advice, con-
code in a specific core engine module creating stored procedures written in tributing code or simply moral support.
which I never found the time to do. Java for a long time, probably starting Special thanks go to, in alphabetical
As a result of this mal performance, as early as 2003. By 2005 he had fig- order:
Jim promised to string me up in the ured out the issues and gotten to work-
tree next to his house. Luckily, he in- Tiberiu Adorei
ing developer builds. Roman Rokytskyy
formed me last November that the wind had modified the Jaybird driver to also Paul Beach
had blown over the tree he had had in support usage inside the server, rather
mind. Arno Brinkman
than only from a client. Eugeney, Vlad
The “coming out party” for Fyracle was and Roman worked hard late sum- Carlos Guzman
the Firebird conference in Fulda in May mer 2005 and delivered working code
Ann Harrison
2004. Most of the summer little hap- early in the autumn. It was included
pened in further development of func- in Fyracle in October 2005. Soon after, Arek Heldt
tionality, as the initial goal had been Carlos Guzman added a plugin for dot- Vlad Horsun
reached. Towards the end of the sum- NET based languages and the CLR. This
mer, Marius Popa managed to get Fyra- plugin and the dotNet driver will be in- Holger Klemt
cle discussed on Slashdot and interest cluded in the next release of Fyracle. Pascal Legrand
slowly but surely started to rise. For one,
the “oracle-mode” thing was picked up Outlook Marek Mosiewicz
by Computer Associates (“CA”) as a What once started as a one-off project Eugeney Putilin
nice marketing gimmick for the open to see if it could be done has evolved Roman Rokytskyy
source release of Ingres. CA announced into a long-term project. Much has
the “million dollar challenge”, which been achieved, but much more remains Nikolay Samofatov
amongst other projects promised $600K to be done. Jim Starkey
for a working migration tool for oracle- • The PL/SQL supported by Fyracle is
based applications. After some thought Claudio Valderrama
roughly Oracle 8i with some 9i exten-
and a look at Ingres, I decided to stick sions. Some things are glaringly miss- Dmitry Yemanov
with Firebird and not take part in the ing and will be added soon, such as
competition. Also in that Summer, En- table functions and collections. Other
terpriseDB got started on oracle-mode features to be added are the object-
Postgres, although they did not come oriented features of PL/SQL that were
out of “stealth mode” until May of mostly added in 9i. The language en-
2005. hancements in version 10g are not all
So, motivated by competition, work that significant.
started to make Fyracle a real prod- • On the relational side, Firebird needs
uct. In order to create an easy to use to get some upgrades for future releas-
package, the Fyracle configuration was es of Fyracle. Things like statement and
cleaned up and a graphical installer for database level triggers, deferred trig-
both Windows and Linux was added. A gers, materialized views, 10-base floats
guy named Arek Heldt showed up with
11 www.ibdeveloper.com
© Copyright 2005-2006, All right reserved www.ibdeveloper.com
DEVELOPER AREA 2006 ISSUE 4
Expression name
This is a valid identifier for the common table expression. An expression name
must be different from the name of any other common table expression defined
in the same WITH <common table expression> clause, but expression name can be
the same as the name of a base table or view. Any reference to expression name in
the query uses the common table expression and not the base object.
Our
Column name expert
Specifies a column name in the common table expression. Duplicate names within
a single CTE definition are not allowed. The number of column names specified
must match the number of columns in the result set of the CTE query definition.
The list of column names is optional only if distinct names for all resulting col-
umns are supplied in the query definition.
Dmitri Kuzmenko is the chief expert
CTE query definition of “The InterBase and Firebird De-
Specifies a SELECT statement whose result set populates the common table expres- veloper Magazine” with 20 years of
sion. The SELECT statement for CTE query definition must meet the same require- InterBase and Firebird experience
ments as for creating a view, except a CTE cannot define another CTE
e-mail: [email protected]
Specifying more than one WITH clause in a CTE is not allowed. For example, if a
www.ibdeveloper.com 12
© Copyright 2005-2006, All right reserved www.ibdeveloper.com
2006 ISSUE 4 DEVELOPER AREA
CTE query definition contains a subquery, that subquery cannot contain a nested
WITH clause that defines another CTE. The recursive form of WITH must contain
exactly two query definitions, an anchor member and a recursive member, joined
together by a UNION ALL operator.
Setting up an example
To start, we will define and fill an employee table. The table has an employee ID,
which is the primary key, a manager ID, which links the employee to his manager,
and name and salary columns:
CREATE TABLE emp(empid INTEGER NOT NULL PRIMARY KEY,
name VARCHAR(10),
salary DECIMAL(9, 2),
mgrid INTEGER);
10 4
11 2
12 3
15 2
16 3
17 2
13 www.ibdeveloper.com
© Copyright 2005-2006, All right reserved www.ibdeveloper.com
DEVELOPER AREA 2006 ISSUE 4
And the following example shows the maximum number of employees reporting
to a single manager:
WITH DirReps (mgrid, dirreps) AS
(
SELECT mgrid, COUNT(*) AS dirreps
FROM emp
GROUP BY mgrid
)
SELECT MAX(dirreps) AS “Max. Number of Direct Reports”
FROM DirReps
WHERE dirreps>= 2 ;
Although common table expressions can be used as a hint to the optimiser about
how a subquery is used, and to make it explicit that a single subquery is used
at more than one place in a query, such optimisations are currently not imple-
mented.
A simple recursive query
A reasonable question to ask is: “Who works directly or indirectly for ‘Gaastra’?”
To answer the question of who works for ‘Gaastra,’ an Oracle developer might write
the following query:
SELECT name
FROM emp
START WITH name = ‘Gaastra’
CONNECT BY PRIOR empid = mgrid
START WITH denotes the seed of the recursion while CONNECT BY describes the re-
cursive step. That is how to get from step n to step (n + 1). Since it is important to
distinguigh between the nth and the (n + 1)th step during name resolution, PRIOR
is used to show that empid belongs to the nth step while mgrid belongs to step (n
+ 1)th. So with empid being 16 for step 1, mgrid must be 16 as well and hence step
2 produces ‘Scott,’ ‘King,’ and ‘Schindler.’ Their empids will now serve as PRIOR to
step 3, and so on and so forth.
The Oracle syntax is very concise. The SQL standard WITH syntax uses regular SQL
to describe the exact same relationships. As you will see, it is more verbose, but
equally straightforward:
WITH RECURSIVE n(empid, name) AS
(SELECT empid, name
FROM emp
WHERE name = ‘Gaastra’
UNION ALL
SELECT nplus1.empid, nplus1.name
FROM emp as nplus1, n
WHERE n.empid = nplus1.mgrid)
SELECT name FROM n;
What makes this CTE special is that it is referred to within its very own defintion.
This is what distinguishes a regular CTE from a recursive CTE. Here I named the
CTE n to correlate to the recursive steps. A recursive CTE consists of two parts
combined with a UNION ALL:
• The seed or step 1 of the recursion. This is what is described in Oracle using
START WITH. In a recursive CTE, it is simply any query providing a set of rows. In
this case we query the emp table and filter for ‘Gaastra.’ We select the name of
course and also the empid, because we need it for the recursive step.
• The recursive step going from n to (n + 1). Here we refer to step n (the CTE n)
www.ibdeveloper.com 14
© Copyright 2005-2006, All right reserved www.ibdeveloper.com
2006 ISSUE 4 DEVELOPER AREA
and join in step (n + 1) using the same predicate used in CONNECT BY. Instead of
PRIOR, regular correlation names are used to distinguish n from (n + 1).
It is noteworthy to look at the output of this query and realize that the recursive
process is a depth first recursion:
NAME
==========
Gaastra
Schindler
Korning
Beagle
King
Reilly
Smith
Boot
Scott
Before moving on to pseudo columns and more complex examples, I want to briefly
explain where the WHERE predicate of an Oracle recursion needs to be placed. We
will modify the example to return all employees, including their salaries, working
for ‘Gaastra’ who earn more than 40,000.
It is interesting to note how the WHERE clause preceded the recursive specifica-
tion. For a non-oracle developer, it might seem that the predicate belongs to the
set of rows being considered to begin with. This, however, is not correct. Instead,
the WHERE filters the final result and belongs at the end of the matching CTE
based query:
Gaastra 80000.00
Schindler 52000.00
Korning 42000.00
Beagle 41000.00
King 51000.00
Scott 53000.00
The SQL standard saw no need to add syntax for this feature because it can be
expressed using regular SQL:
WITH RECURSIVE n(lvl, empid, name) AS
(SELECT 1 lvl, empid, name
FROM emp
WHERE name = ‘Gaastra’
UNION ALL
SELECT n.lvl + 1, nplus1.empid, nplus1.name
FROM emp as nplus1, n
WHERE n.empid = nplus1.mgrid)
SELECT lvl, name FROM n;
All I have done here is to introduce a level column, which starts with 1 and incre-
ments by 1. Of course, any semantics is possible, but this one happens to provide
the same semantics as LEVEL.
Conclusion
In this article I provided generic mappings from the Oracle style CONNECT BY
recursive query syntax to Firebird’s standard compliant recursive common table
expressions using UNION ALL. While the Oracle syntax is less verbose because it
provides keywords for various common semantics, this also means that it is less
expressive since little new semantics can be added without changes to the DBMS.
www.ibdeveloper.com 16
© Copyright 2005-2006, All right reserved www.ibdeveloper.com
2006 ISSUE 4
IBSurgeon
Products
IBFirstAID
IBFirstAID is a tool that can be
used for automatically diagnosing
and repairing corrupted Firebird or
InterBase databases. It can fix up
to 80% of often corruptions.
Supports InterBase 5.x-7.x and
Firebird 1.x-2.x databases. IBSurgeon Pack
IBSurgeon Pack is a comprehensive set of
tools to repair InterBase and Firebird data-
bases and backups, undelete occasionally
deleted records and foresee database prob-
lems.
Buy IBSurgeon Pack
for EUR 399 and save 197 EUR!
IBUndelete
IBUndelete is a tool which can undelete occasionally deleted records
in InterBase or Firebird databases. It uses unique IBSurgeon core en-
gine for direct work with data inside database.
Supports InterBase 5.x-7.x and Firebird 1.x-2.x
IBBackupSurgeon
IBBackupSurgeon is a tool to read and save data
from corrupted Firebird or InterBase backup
files. With this tool you can browse a backup
file, select tables you need and then extract
them to a new or existing database.
Supports InterBase 5.x-7.x and Firebird 1.x-2.x
backups.
IBAnalyst
IBAnalyst is a tool that assists a user to analyze in detail Firebird or InterBase
database statistics and identify possible problems with database performance,
maintenance and how an application interacts with the database.
Supports InterBase 5.x-7.x and Firebird 1.x-2.x databases.
17 www.ibdeveloper.com
© Copyright 2005-2006, All right reserved www.ibdeveloper.com
DEVELOPER AREA 2006 ISSUE 4
MORFIK’s WebOS:
Innovating beyond LAMP
Last month saw the first public beta of a revolutionary new tool to develop web ap- By Paul Ruizendaal
plications. Several developers have commented that using WebOS for the first time [email protected]
gives that same sensation of excitement that they felt when they first worked with
Delphi 1.0 back in the early nineties. WebOS comes with a bundled Firebird database
server.
19 www.ibdeveloper.com
© Copyright 2005-2006, All right reserved www.ibdeveloper.com
DEVELOPER AREA 2006 ISSUE 4
However, market acceptance of JavaS- The process is a true compilation and tool for building large and complex ap-
cript for implementing large-scale ap- avoids boilerplates or code snippet li- plications.
plications faces the following practical braries. The source code written in the • Compiled code is, by definition, more
challenges: object-oriented, strongly typed lan- reliable and scalable than interpreted
guage of choice is first passed through
a) Syntax - JavaScript borrows its code. Although the output of the Mor-
a parser that includes a tokenizer and
syntax from C. While C/C++/C# and fik compiler is interpreted JavaScript,
syntax analyzer. The output of the pars-
Java programmers feel at home with the compilation process nevertheless
er is passed through a semantic map
case-sensitive short-hand syntax, the ensures rigorous type checking and
builder which builds a detailed seman-
large number of developers who have enforcement of referential integrity in
tic map of the entire application. This
mastered other languages such as Vi- producing reliable and scalable appli-
map conveys the full “meaning” of the
sual Basic and Delphi face a frustrating cations.
application logic. This semantic map is
transition.
then compiled into JavaScript code that • The AJAX engine created through
b) Semantic Design - JavaScript is a pro- is semantically identical to the original the Morfik process is an exact seman-
totype-based (instead of class-based) code written by the programmer and tic equivalent of the high level source
object-oriented language. This also conveys the exact same “meaning”. code which reflects the programmer’s
presents developers with the challenge intentions without imposing limita-
This process offers several advantages:
of adopting a whole new mindset. tions. Code-snippet libraries and pre-
• Mastering a programming language is fabricated component frameworks, by
c) Lack of rigor - JavaScript does not
a long and arduous process. Switching their very nature, limit the program-
provide the developer with a rigorous
to a new language requires much more mer’s ability to choose the appropriate
programming model. For example, it
than learning a new syntax. It requires level of abstraction.
does not support type declarations, nor
an idiomatic shift in the programmer’s
can functions receive their parameters Since the output of this process is nei-
thought processes. This skill takes time
by reference, to name a few. This limi- ther an executable in machine-code,
to acquire. By allowing developers to
tation is a disadvantage in large scale nor a one-to-one translation of source
program in the language they have al-
programming. code, nor a collection of predefined
ready mastered, Morfik not only encour- code snippets, WebOS AppsBuilder‘s
d) Interpreted - Interpreted languages ages the uptake of AJAX and improves process is referred to as JavaScript Syn-
do not offer the benefit of compilers in the quality of the output, but also re- thesis Technology (‘JST’):
rigorous enforcement of application in- duces the development cost of AJAX
tegrity at compile time. Small changes applications. Client-side handling of brows-
to an otherwise perfectly working pro- er requests
• The clean separation of the parser,
gram can cause unpredictable run-time
semantic analyzer and compiler al- Browsers are designed to work with
crashes. For example the most common
lows Morfik to compile from a variety servers using a stateless request-re-
error messages in existing web-page
of source languages into a variety of sponse model. Normally, the browser
scripts are “object expected” or “object
target languages. The only condition is and the server do not co-exist on the
does not support this property”.
that the source language is either ob- same hardware, and browsers need to
Morfik solves these problems with its ject-oriented (e.g. C++/C#/Java) or has stay connected to the web in order to
revolutionary JavaScript Synthesis been specifically modified to support maintain a dialog with the server. Of
Technology (‘JST’). Using WebOS Ap- object-oriented constructs. (See Ap- course, this is natural and the way of
psBuilder, programmers implement the pendix A for further details on) “multi- things on the web. However, to bring
business logic of their application in a language support in Morfik”. the web applications to the desktop
high-level object oriented language of and enable them to work after they are
• Strongly typed compiled languages
their choice (e.g. C++, C#, Java, Delphi). unplugged from the web, one must be
follow a rigorous programming model
WebOS AppsBuilder then compiles this able to handle the browser requests lo-
that has made compilers the preferred
code into a JavaScript AJAX engine. cally.
www.ibdeveloper.com 20
© Copyright 2005-2006, All right reserved www.ibdeveloper.com
2006 ISSUE 4 DEVELOPER AREA
One obvious solution is to install an WebOS AppsBuilder has an open and
HTTP server on the local host. This highly flexible architecture and can
will also fulfill the second part of the integrate local database engines or
objective, namely taking desktop ap- provide remote database connectivity
plications to the web. Many mature in a variety of ways. To provide a ma-
and stable examples of HTTP servers are ture, stable and well tested option that
freely available. Some are stand-alone can allow its applications run under
applications whilst others are small em- Windows, Linux and OS X, WebOS Ap-
bedded systems. Alternatively, the rel- psBuilder tightly integrates a Firebird
evant subset of HTTP server protocols server into its applications by default.
can be implemented within the appli- This is not an exclusive option and will
cation so it can natively communicate not limit the developer’s choice of oth-
with the browser and process browser er database engines.
requests.
Productivity
More importantly, the browser vendors
AJAX applications have created a lot
have recognized the benefits and pos-
of excitement but until professional
sibilities that local handling of browser
Integrated Development Environments
requests can offer, and they are plan-
become available, developers will find
ning to add this ability to the browser
it difficult to justify the effort – and
itself – effectively merging the HTTP
therefore the cost – associated with
server and the browser into a unified
AJAX programming.
system.
It is Morfik’s belief that designing an
WebOS AppsBuilder has an open and
IDE around code libraries and compo-
highly flexible architecture which can
nent frameworks is a repetition of past
support the local handling of browser
mistakes. Such tools make it decep-
requests in a variety of ways. To provide
tively easy for developers to get simple
a mature, stable and well tested option
applications up and running quickly
that can allow its applications to run
only to have them hit the wall as their
under Windows, Linux and OS X, WebOS
projects grow in size and scope.
AppsBuilder tightly integrates an em-
bedded open-source Apache server into To ensure reliability, scalability and
Morfik applications by default. This is maximum productivity, JavaScript Syn-
not an exclusive option and will not thesis Technology leverages the power
limit the developer’s choice of other of high level languages and the exist-
methods ing skills of programmers. WebOS Ap-
psBuilder is a world class system which
Database needs incorporates the features that are re-
Business applications are predomi- quired for a truly professional AJAX-
nantly data-driven and depend heav- based Integrated Development Envi-
ily on a relational database system. In ronment.
the corporate world, data is centralized
and database servers do not normally Multi language support in
co-exist with the client applications on WebOS
the same hardware. Consequently, the At the core of the WebOS AppsBuilder
client needs to stay connected to the Integrated Development Environment
network in order to maintain a dialog for AJAX lies the time-tested and prov-
with the server. en technique of using a strongly typed
To bring data-driven web applications object-oriented language and a com-
to the desktop and enable them to work piler, which strictly enforces referential
after they are unplugged from the net- integrity, high levels of modularity, re-
work requires a local database engine. factoring and polymorphism within the
This will not only fulfill the second part source code, to develop applications
of the objective, namely taking desktop that are reliable, scalable and easy to
applications to the web, but also will maintain.
facilitate the implementation of large The output of a compiler is invariably
scale distributed databases and distrib- in a language different from that of the
uted computing. source code – usually machine code but
21 www.ibdeveloper.com
© Copyright 2005-2006, All right reserved www.ibdeveloper.com
DEVELOPER AREA 2006 ISSUE 4
sometimes an intermediate language. A and Morfik Object Pascal (with more to highly modular architecture. There is a
good example of this is the Microsoft come) for the AJAX platform. Program- clean separation of the syntax parser,
compiler that takes the source code in mers choose their favorite syntax (or semantic analyzers and the target code
C#, VB.NET or J# and produces code in even mix and match a number of them) synthesizer. This enables WebOS Ap-
Microsoft Intermediate Language (MIL). to develop their application. This al- psBuilder to compile from a variety of
When examining a snippet of sample lows them to benefit from the rigorous source languages into a variety of target
code in Microsoft Developers Network software engineering techniques and languages. The only condition is that
(MSDN), one is usually given the option system design methodologies inherent the source language must be strongly
of seeing it in one of these languages. in the object-oriented programming typed and either object-oriented (e.g.
Yet if these code snippets are carefully paradigm. WebOS AppsBuilder then syn- C++/C#/Java) or has been specifically
compared, one realizes that semanti- thesizes the source code into semanti- modified to support object-oriented
cally all three languages are identical! cally equivalent JavaScript code and constructs.
Therefore, the MIL code generated is packages it into an AJAX application.
also the same. Free download
In this model, the synthesized JavaScript
The beta releases of Morfik's WebOS Ap-
To achieve this, in the case of Visual in WebOS AppsBuilder is the equivalent
psBuilder is a free download.
Basic, Microsoft had to take it to the of MIL in .NET. In addition, WebOS Apps-
next level, and developed the strongly Builder does not prevent extending the Please check http://www.morfik.com
typed object oriented VB.NET. Although JavaScript output by linking-in external to download your own evaluation copy
unpopular with some VB programmers hand written JavaScript code libraries. and get a feel for the future of web ap-
this move was nevertheless a technical However, such external code would not plication development.
necessity. benefit from the same rigorous checks Move over LAMP, WebOS is here!
as native WebOS AppsBuilder code.
Morfik has used this strategy in develop-
ing Morfik Basic, Morfik C#, Morfik Java WebOS AppsBuilder has a flexible and
www.ibdeveloper.com 22
© Copyright 2005-2006, All right reserved www.ibdeveloper.com
2006 ISSUE 4 DEVELOPER AREA
Global Temporary
Tables in Fyracle By Vlad Horsun, [email protected]
Implementation details
A GTT instance—a set of data rows created by and visible within the given con-
nection or transaction—is created when it is first referenced, usually at statement
prepare time. Each instance has its own private set of pages on which data and
indexes are stored. Data rows and indexes have the same physical storage lay-
out as permanent tables. When persistence ends (the connection detaches or the
transaction ends, depending on the scope) all pages of a GTT instance are released
immediately. Although this is similar to when you do DROP TABLE, of course the
metadata remains in the database.
The clearing of a GTT is much quicker than the ordinary row-by-row delete and its
associated garbage collection. Each data (index) page contains rows (keys) from
the same GTT instance, meaning the connection or transaction should read\write
fewer pages than they would if GTT instances were isolated by the service field.
With the “service field” design, in contrast, data pages would continue to contain
rows from old transactions and dead connections until it was garbage collected.
It can happen that the GTT design requires more space than the “service field” de-
sign. For example, 10 instances of a GTT, each with one row, would occupy 10 data
pages, while, under the “service field” design, only one page would be used, as long
as it could accommodate 10 rows. This difference doesn’t really become evident
except with a large number of small tables, so we can accept that as a reasonable
price for the benefits of speed and almost instant cleanup.
In Fyracle, the data pages of all of the GTT instances are placed in the database file.
In Firebird 2+, with better performance the objective, these pages will be placed in
separate files to allow temporary data to be written to another hard disk. This also
enables temporary files always to be opened with forced writes off, regardless of
the database setting. And—yes—there are plans to consider this mechanism for
implementing tablespaces. (No, I didn’t write this :)
There is no limit to the number of GTT instances active in the database. If you have
N transactions active simultaneously and each transaction has referenced some
GTT then you’ll have N instances of that GTT.
The InterBase implementation of GTT has one “featurebug”. If you have two trans-
actions in one connection and both transactions insert some rows into a GTT ON
COMMIT DELETE table and then one transaction commits, the data in the second
transaction’s GTT instance will disappear. Firebird’s implementation of GTT is free
of this problem.
Examples
— create usual (permanent) table :
CREATE TABLE PERSISTENT (
ID INT NOT NULL
);
— create temporary table with scope of transaction
CREATE GLOBAL TEMPORARY TABLE GTT_DELETE (
ID INT
) ON COMMIT DELETE ROWS;
www.ibdeveloper.com 24
© Copyright 2005-2006, All right reserved www.ibdeveloper.com
2006 ISSUE 4 DEVELOPER AREA
CREATE GLOBAL TEMPORARY TABLE GTT_PRESERVE (
ID INT
CHECK (EXISTS(SELECT * FROM PERSISTENT))
) ON COMMIT PRESERVE ROWS;
This operation is not defined for system tables.
unsuccessful metadata update.
global temporary table “GTT_PRESERVE” of type on commit
preserve rows cannot depend on persistent table “PERSIS-
TENT”.
ID
============
5
ID
============
5
COMMIT;
SELECT * FROM GTT_DELETE;
— no rows
ID
============
5
— our one row still here
start another isql session:
SELECT * FROM GTT_PRESERVE;
— no rows, as expected
25 www.ibdeveloper.com
© Copyright 2005-2006, All right reserved www.ibdeveloper.com
TESTBED 2006 ISSUE 4
– someone should be the winner. But I database with sample data, and 3) the
have to disappoint you – it wasn’t the tpcc.exe module to run user processes
case for our tests and there is no abso- simultaneously in order to simulate the
lute winner. OLTP workload.
While the test results indicated certain All source code for these tools is open
trends that were fairly dependent on and can be downloaded from http://ibdeveloper.com/tests/tpc-c/ , so you can
settings and hardware configurations, compile and check its workings.
it did not bring a single overlord into How the test is conducted
the light. For the impatient amongst
the readers I can say that InterBase 1) Database creation. The test database is always created from scratch using SQL
7.5.1 showed the best results in most scripts. We used page size 4096 for all databases. 4096 was chosen because our
but not all of the high-end configura- previous tests1 did not show significant difference between a 4 Kb and an 8 Kb
tions, with some stability issues. page size, and because 4096 is the default page size for the modern server versions
of InterBase and Firebird.
Let’s proceed to the test results.
2) Populating the database. The module load_ib.exe populates the test database
Test team with sample values. Look below in the “How to configure tests” section to see how
First of all, I need to express my sincere to set the database size.
gratitude to Alexey Karyakin and Vlad 3) Index creation. All indices are created after data are loaded into the database,
Horsun who created and adapted the not just to speed up data loading but also to avoid spoiling the selectivity of indi-
TPC-C based test toolkit for public us- ces and thus forestall optimizer mistakes.
age.
4) Testing. Testing is performed by tpcc.exe module which runs N simultaneous
Then I’d like to thank people who threads with user queries to simulate real-world OLTP- activity. Please notice that
helped to perform tests on different all actions are done by stored procedures, so the client (tpcc.exe) consumes very
hardware and software configurations: little CPU and RAM resources. Tpcc.exe is run on the same host as the database
Vadim Dokukin (www.niklaus.ru), An- server. It can be run remotely, but it requires very wide bandwidth: during the
ton Glazunov, Sergey Chernyak, Eugeny course of testing our attempt with a regular 100Mbps network produced a lot net-
Putilin and Sergey Mereutsa. work errors (10054), so I suppose a gigabit network is called for.
Special thanks to Thomas Pfister (www. 5) Database checking. After the test is complete, the “gfix –v –full” command line
nevrona.com) and Daniel Magin (www. tool is run to check database state after intensive work and ensure it is correct.
better-office.com) for great help in
6) Database statistics. Then we run “gstat –r” to gather database statistics with
carrying out tests on special configura-
record versions.
tions.
Test duration (testing only, without loading, checking and statistics time) is usu-
Test technique ally three hours – 0.5 hours for startup and a 2.5-hour period of measurement.
I anticipate a lot of questions related Where we increased times we note it specifically.
to the execution of the tests, so please
All test results are written to appropriate logs into “Log” folder.
read this part carefully to avoid a lot of
them. Raw results
We used a TPC-C based toolkit to carry Test logs can be downloaded from http://ibdeveloper.com/tests/tpc-c/
out our tests. In essence this test simu-
lates a database warehousing system How to run tests
with W warehouses and T terminals (i.e. It might seem a difficult thing to get these tests set up to run but that’s not the
users) working simultaneously with case at all. Thanks to a useful toolkit, all you need to do to run the test is change
these warehouses, mostly inserting and the location of the appropriate server version in the setup_VERNN files, set the
updating records. desired database size and user count in prepare.cmd and then launch RUN.CMD.
All tests were carried out on Windows How to configure the test
platform. I am first to agree that it is
Let’s consider a simple example of configuring the test. Assume that you have In-
a major omission but we’ve had insuffi-
terBase 7.5 installed in folder “C:\InterBase751”, so you need to change the first
cient time and resources so far to adapt
line in configuration file “setup_ib751.cmd”
the tests for Linux.
1
Probably we will publish their results in the next issue
www.ibdeveloper.com 26
© Copyright 2005-2006, All right reserved www.ibdeveloper.com
2006 ISSUE 4 TESTBED
SET IB=C:\interbase751\bin
SET NAME=IB751 Expert's note
SET DATABASE=%~dp0%NAME%_tpcc.fdb
SET ISC_USER=SYSDBA
SET ISC_PASSWORD=masterkey
SET PATH_SAVE=%PATH%
Yaffil
SET PATH=%IB%;%PATH% Yaffil is a Russian clone of Firebird
SET BUFFERS = 99999 1.0. It was made in the middle of
%IB%\instreg install %IB%\.. instance gds_db 2001 to check where optimizations
%IB%\instsvc install %IB%\.. instance gds_db can be done, and how it will affect
net start IBS_gds_db server performance. Since Yaffil was
Please note that database buffers are set in setup_VERNN too. made only for Windows, there were
a lot of windows-related optimiza-
Then you need to select the desired database size and user count. It involves
tions. The whole list of optimizations
changing two lines in the prepare.cmd file.
is very long – new memory manager,
Database size is set by –W variable (W means warehouses) at the database creation faster inserts, disk i/o, additional
step. Each warehouse adds ~30Mb to database, so –W50 means to create 4.5Gb configuration parameters, optimizer
database: fixes, query scheduler, garbage col-
bin\load_ib -W50 -D\\.\%DATABASE% > log\%NAME%_load.log lection, compatibility with previous
User count and number of actually used terminals are set up at the testing step: InterBase versions (5.x and lower),
and more. Also some little parts of
bin\tpcc -W50 -T50 -Dlocalhost:%DATABASE% -r30 –R180 -i30 > Firebird 1.0 code were rewritten in
log\%name%_tpcc.log pure assembler.
Please note that we always set W= T. It’s done to avoid annoying lock conflict
errors in the logs. In fact, lock conflicts are perfectly normal in real-world OLTP Thus, some users that moved from
systems, but we’re trying to avoid exceptions for the testing because they pollute InterBase 4.x and 5.x to Yaffil, got
the test logs and make them difficult to analyse. not only better compatibility with
legacy databases than InterBase
Once all the locations in the setup_VERNN.cmd files are set up, the test – RUN.CMD 6.0 and Firebird had, but from 2 to
– is ready to launch. 6 times speedup of common server
Test participants performance. Optimization of the
internal server scheduler still allows
Which InterBase and Firebird versions were tested? We tested the following server Yaffil SuperServer to have less pro-
versions: cessor load (from 5 to 40 percent)
Server version Notes than Firebird SuperServer on some
applications (with short and long-
InterBase 7.5.1 All configurations running queries being executed si-
Firebird 1.5 SuperServer Omitted in some configurations multaneously).
due to the lack of time
Yaffil was the pioneer in reconstruct-
Firebird 1.5 Classic All configurations ing Classic for Windows functional-
Firebird 2 Release Omitted in some configurations ity, because Borland nearly dumped
Candidate 1 SuperServer due to the lack of time Classic architecture before version
Firebird 2 Release All configurations 6.0, and the published source code
Candidate 1 Classic for InterBase Classic for Windows was
broken. Yaffil successfully revived
Yaffil Classic Omitted in some configurations Classic architecture for Windows
due to the lack of time (with services api support), having
Yaffil SuperServer Omitted in some configurations high stability on ~40 gigabytes da-
due to the lack of time tabases nearly year before Firebird
Classic for Windows was released.
Because a lot of people are interested in the Vulcan results, we tried to run the
public pre-alpha Vulcan of Vulcan. Unfortunately it was too unstable to run and
crashed every time, so we had to omit it. We still hope there will be an alpha ver- Our expert
sion before too long that will be stable enough to sustain our test. Dmitri Kuzmenko
Test results Dmitri Kuzmenko is the chief expert
We ran the tests many times in different software and hardware configurations and of “The InterBase and Firebird De-
received a lot of raw results that are not yet fully processed. Space in this issue veloper Magazine” with 20 years of
of magazine is limited too, so we decided to publish a special issue of “The Inter- InterBase and Firebird experience
Base and Firebird Developer Magazine” devoted solely to test results analysis and e-mail: [email protected]
27 www.ibdeveloper.com
© Copyright 2005-2006, All right reserved www.ibdeveloper.com
TESTBED 2006 ISSUE 4
performance optimization.
Here we will highlight the main trends and commonalities in the results to illus-
trate the general picture.
Configuration 1
Hardware configuration:
Hardware:
2xCPU 3.0Ghz, 2GB RAM,
2x36Gb Ultra SCSI 320 in RAID1+0 with 128 RAM,
Windows 2003.
50 users, Forced Writes off
This was the most balanced hardware configuration – a very good disk system is
combined with good CPUs and a lot of RAM. The database size for 50 users is 4.5Gb
would not fit into RAM, so disk performance was high in importance.
We set Forced writes off to get maximum performance. It’s the default mode in
InterBase 7.5.1. For Firebird, in addition to setting Forced Writes off, we set the
parameters MaxUnflushedWrites and MaxUnflushedWriteTime were to -1 in fire-
bird.conf to disable flushing.
So, InterBase 7.5.1 is winner here, with Firebird 2 Classic Release Candidate 1
showing its enhanced capability, compared to 1.5.3, to work with disks.
Firebird 1.5.3 and Yaffil 1.0 SuperServer versions showed lower performance be-
cause, in this test, dual CPUs played an important role – fast disks and a lot of RAM
being able to keep the CPUs busy.
100 users, Forced Writes On
After that, simulated a heavily loaded system. We increased the workload and ran
the test with 100 users and 100 terminals, so the database became 9.5Gb. We also
set Forced Writes on and increased test time to 6 hours.
www.ibdeveloper.com 28
© Copyright 2005-2006, All right reserved www.ibdeveloper.com
2006 ISSUE 4 TESTBED
We launched only 3 servers to compare the maximum workload of InterBase SMP
and the Firebird 1.5.3 and Firebird 2 Release Candidate 1 Classic architectures.
Firebird 1.5.3 SuperServer, Firebird 2 Release Candidate 1 SuperServer and also
Tips
Yaffil were omitted because of time constraints. Below are results:
Do you know how
Server tpmC Buffers many transactions
FFirebird 2 Release 479.95 2048 your application starts
Candidate 1 Classic
every day?
Firebird 1.5.3. Classic 88.43 2048
You can check it by running gstat
InterBase 7.5.1 754.76 1000000
–h db.gdb every day, but IBAna-
Below is the results graph. As you can see, Firebird 1.5.3 showed the lowest perfor- lyst will show daily average transac-
mance, and InterBase 7.5.1 is the winner here. tions count on the fly.
System with 50-70 users usually
starts about 50-500 thousands
transactions per day.
Is it much, or not?
It depends on how you have written
your application, i.e. how you man-
age transactions within application.
There may be not many transactions
per day, but if these transactions are
long, they can cause lot of record
versions in database, and perfor-
mance may degrade (as usual).
On the other side, even 1-5 million
short transactions per day may not
load server much.
But there are some circumstances which are rather important to mention. The
activity of InterBase 7.5.1 was rather unstable and performance tended to degrade
– please see graph below.
First, InterBase 7.5.1 had a lot of deadlocks. As I commented earlier, it’s rather normal, but InterBase didn’t exhibit them in
the test with the lower user count. More importantly, Firebird 2 Release Candidate 1 and Firebird 1.5.3 exhibited no deadlocks
at all, even with 100 users.
The second point is InterBase’s tendency to decrease in performance, with no obvious explanation. This test cycle (all three
servers) required more than 24 hours to complete, which is why we repeated it only twice. We got the same results (+- 1%)
on the repeat runs. It would be interesting to run InterBase alone for 2-3 days and see what happens.
29 www.ibdeveloper.com
© Copyright 2005-2006, All right reserved www.ibdeveloper.com
TESTBED 2006 ISSUE 4
The third instability we saw with InterBase was that InterBase, three times, went
to zero performance for 30-60 seconds – just stopped to answer to client requests.
The yellow vertical lines on the graph were where these trouble spots occurred.
I’m guessing that, as a result of these stops, database checking (gfix -v -full) indi-
cated 1 record error:
Summary of validation errors
Number of record level errors : 1
Configuration 2
by Daniel Magin, [email protected]
Hardware: Pentium 3.0, HT ON, 2Gb/1Gb, SATA 300Gb
Many of our customers run InterBase on standard workgroup servers so I was in-
terested to analyse the results of testing the different server versions on a host
machine that was specifically not a high-speed system with multiple CPUs. My
base test platform was a simple machine with a Pentium 4 3.0 GHz processor with
Hyperthreading and 2 Gb RAM on an Asus P4P800-E mainboard. The hard drive
was a 300 Gb Maxtor SATA2 V300FO with a 16 Mb Cache but it was running on the
mainboard’s SATA1 interface.
On the only existing partition C (90GB) I installed a new Windows 2003 Server
Enterprise Edition. All tests ran on this single partition. Though there’s no ques-
tion that results could be sped up by spending more money on SCSI-RAID and more
RAM, the focus of my interest for this test was how this fairly ordinary configura-
tion would respond.
I used the latest official version of each of the different database engines. I start-
ed out by playing around quite intensively with some settings to find the best
configuration for each one for speed. I settled on the following buffer settings:
www.ibdeveloper.com 30
© Copyright 2005-2006, All right reserved www.ibdeveloper.com
2006 ISSUE 4 TESTBED
News line
Devrace
has acquired
Metadataforge
Devrace has recently acquired Meta-
dataforge company (SQLHammer
project) and will immediately start
selling the product.
The CEO of Devrace Serg Vostrikov,
says: “We are very happy to have
signed the contract with Dmitry
Kovalenko, the author of SQLHam-
mer. SQL Hammer is a simple, fast
and elegant IDE for database devel-
opment and invaluable tool for real
InterBase, current Version 7.5.1, was the winner in my TPC-C based test, except administrators. When developing
it came last in loading the datascript. I don’t know why. Most significant is the SQL Hammer Dmitry was concentrat-
extremely good speed InterBase delivers if it can find 2 Gb of RAM. ed on improving the performance of
With only 1Gb of RAM, InterBase 7.5.1 and Firebird 2 Release Candidate 1 Classic access to databases, and so far judg-
delivered similar speeds, and Firebird 1.5.3 SuperServer became the leader: ing by recent tests these attempts
are very successful. I am sure soon
Server tpmC Loadingtime Transactions Set Buffers we will prove InterBase/Firebird da-
Firebird 1.5.3 159.18 1475.36 54900 2048 tabase developers that SQL Hammer
Classic is worth buying!”
Firebird 1.5.3 443.11 825.65 152889 9900 Sophisticated internal SQLHammer
SuperServer architecture is based on plug-in
Firebird 2 202.88 951.53 69977 2048 modules which extend IDE func-
Classic tionality. For example centralized
Firebird 2 400.46 940.68 138213 6400 SQL Editor is used in most database
SuperServer objects and editors, whereas it is
InterBase 341.47 1151.56 117820 6400 physically present only in a single
7.5.1 module. Such a module architecture
Yaffil Classic 377.3 776.18 130212 2048 provides developers with additional
advantages:
Yaffil 359.09 783.26 121807 9900
SuperServer • saving computer resources,
• an ability to use only necessary
functions and deactivate the other
tools,
• full support of all Borland Inter-
Base/Firebird versions, as we use
different access means for each
server,
• better support of client develop-
ment tools, in particular, SQLHam-
mer has SQLMonitor for FIBPlus and
SQLMonitor for IBX,
• more convenient updates: devel-
So if you use InterBase, having the full 2 Gb of RAM available will be rewarding. opers get an update of a certain
Yaffil—which is based on Firebird 1.0 but has a better memory manager—also module or of the product core in-
showed itself very good at handling the bigger memory. If you use open source stead of full package at once.
versions and you have at least 2 Gb RAM, Yaffil would be worth a try if you need
more speed. www.devrace.com
31 www.ibdeveloper.com
© Copyright 2005-2006, All right reserved www.ibdeveloper.com
TESTBED 2006 ISSUE 4
Hyperthreading
The next point for analysis was hyperthreading. Does HT really speed up the sys-
tem? Which versions actually work with HT?
I decided to increase the work for the server by changing the terminal/warehouse
setting to 50.
Bigger DataBase + More Thread Connections:=more work for the server :-)
The following results are just for comparing the differences between having HT
enabled and having it disabled. With a high-speed hard disk system such as SCSI,
you could vastly expand the Delta because the CPUs would not be kept waiting for
read/write operations.
www.ibdeveloper.com 32
© Copyright 2005-2006, All right reserved www.ibdeveloper.com
2006 ISSUE 4 TESTBED
Configuration 3
Hardware: Fujitsu-Siemens 200TX S2, 1xXeon 3.2Ghz 64EM-T, HT OFF, 2Gb RAM, Expert's note
6x36Gb UltraSCSI320, RAID 1+0, Windows 2003 64 bit Edition
30 users, Forced Writes off 64-bit
This test was interesting because of the abnormal speed of Yaffil Classic Server 64-bit processors now are nearly
– it was more than twice as fast as InterBase 7.5. We believe the reason for it everywhere, from desktop to server.
is Windows-optimized code in Yaffil (as you probably know, Yaffil is for Windows What benefit could be gained from
platform only) and its spinlock-based lock manager. Critical low-level operations these processors?
are implemented in Yaffil in Assembler. Yaffil’s memory manager also differs from The initial win is for gamers, espe-
both the InterBase and Firebird memory managers. cially those who already have AMD 64
64-bit based CPUs and OS are coming soon, so it may be useful for InterBase and processors in their systems. The next
Firebird engineers to take a look at the Yaffil implementation. comes when 64-bit operating sys-
tems come into currency. Windows
Server Performance, Tpmc Buffers XP Professional and Windows 2003
Firebird 1.5.3 Classic 252.170 2048 Server 64-bit editions are available
Firebird 1.5.3 497.010 9000 already but the big problem for both
SuperServer is drivers and software.
Firebird 2 Release 448.33 9000 Before installing these operating
Candidate 1 SuperServer systems you need to be sure that sta-
ble drivers exist for your hardware. If
Firebird 2 Release 440.400 2048
you will use only 32-bit programs,
Candidate 1 Classic
performance will be the same as for
InterBase 7.5.1 863.760 100000 the 32-bit operating system (except
Yaffil Server 1.0 Classic 2,038.160 2048 strange Yaffil results in tpc-c test),
and could be worse (especially in
games, up to -40%).
For now, it doesn’t make a lot of
sense to install 64-bit operating sys-
tem unless you have a specific need
to do so and the software and driver
support to make it work. Neverthess,
be prepared to install it in the not-
too-far-distant future.
Yaffil 1.0 SuperServer was omitted due to a service startup problem that we didn’t
notice until it was too late to fix it. The hardware was no longer available to repeat
the test. Our
Servers results overview expert
InterBase 7.5.1
Currently it’s the most powerful server for the most powerful SMP hardware con-
figurations. It has some problems with stability and is sensitive to the amount of
installed RAM. And we should not forget about TPC-R results which showed that
InterBase 7.5.1 required a lot of query optimizations in real-world applications.
But, if SQL developers are optimizing queries effectively, the two tests indicate Dmitri Kuzmenko is the chief expert
there is a performance advantage for InterBase from investing in multi-CPU com- of “The InterBase and Firebird De-
puters with fast disk systems. veloper Magazine” with 20 years of
InterBase and Firebird experience
Firebird 1.5.3
e-mail: [email protected]
It’s an old horse, but it’s not too bad! For single CPU computers SuperServer does
33 www.ibdeveloper.com
© Copyright 2005-2006, All right reserved www.ibdeveloper.com
TESTBED 2006 ISSUE 4
quite well. On a 64-bit computer with Yaffil 1.0
Windows 2003 it does even better than And about our dark horse. I suppose many of our readers first got to know of the
Firebird 2 Release Candidate 1. Firebird Yaffil project in this article. Firebird 2 incorporated quite a lot of Yaffil’s function-
1.5.3 looks good for small to medium ality (mostly System Defined Functions and some improvements), but there are
size databases and user bases. And we still many interesting things, especially in speed issues and heavy-load user man-
should not overlook its very high sta- agement. Yaffil 1.0 is rather common in Russia – it is used for quick replacement
bility. for old InterBase 4.x and InterBase 5.x databases due its special backward capa-
Firebird 2 Release Candidate 1 bilities and high speed. With single backup and restore and without any changes
in application code users get faster and more stable databases. Of course, Yaffil
It’s not good to test beta versions, be-
isn’t in line for new development, but there are a lot of ideas inside it to explore.
cause they change so quickly. For ex-
ample, Firebird 2 Release Candidate 2 Summary
is available already and we’ll certainly
I think many readers (especially fans of Firebird or InterBase) will be dissatisfied
test it and publish the results in the
with this article…. It’s not possible to determine an absolute leader and too many
next issue. But we have to admit that, things depend on hardware, operatng system and configuration parameters that
for a beta, Release Candidate 1 is doing we haven’t specified here.
very well. Its performance is only 30-
40% lower than InterBase 7.5.1 run- It was a real discovery for us that performance of modern InterBase and Firebird
ning on powerful SMP configurations versions can vary so much. As we discovered, performance is not a simple thing.
with a lot of RAM installed (2Gb+). On It’s hard to describe all the testing we did in a single article. We’ll be having a
more modest hardware configurations special issue of our magazine devoted exclusively to the results and their inter-
it is even better, and also demonstrated pretation. It will cover configuration aspects like playing with firebird.conf and
very good stability. The forthcoming IBCONFIG parameters, the impact of new settings like GROUP COMMIT on perfor-
release of Firebird 2 looks likely to be mance, comparing tables of results for different settings, detailed explanation of
more than a match for InterBase. We the interdependencies between elements of hardware configuration.
intend to pay a lot of attention to its We hope that some readers will be able to repeat the tests using our toolkit and
evolution. send us the results for publication.
www.ibdeveloper.com 34
© Copyright 2005-2006, All right reserved www.ibdeveloper.com
2006 ISSUE 4
www.ibdeveloper.com
© Copyright 2005-2006, All right reserved www.ibdeveloper.com