tips for success: common mistakes in application development with firebird and how to avoid them

22
Tips for success Common mistakes in application development with Firebird and how to avoid them Pavel Císař IBPhoenix Firebird Conference 201

Upload: mind-the-firebird

Post on 17-Jun-2015

1.257 views

Category:

Technology


1 download

DESCRIPTION

There are many ways how application developers using Firebird could paint themselves in the corner. Beside well-known design and development errors, there are also subtle mistakes that could have dire consequences.This talk will guide you through twisted maze of design and development decisions, pointing out the traps, hidden horrors and dead-ends, and strategies how to avoid them.

TRANSCRIPT

Page 1: Tips for success: Common mistakes in application development with Firebird and how to avoid them

Tips for success

Common mistakes in application development with Firebird and how to avoid them

Pavel CísařIBPhoenix

Firebird Conference 2011

Page 2: Tips for success: Common mistakes in application development with Firebird and how to avoid them

Agenda

Recipes for disaster Mistakes in database design Wrong approaches to handle data

Page 3: Tips for success: Common mistakes in application development with Firebird and how to avoid them

Recipes for disaster

“Agile Knowledge Management” Wrong assumptions Unjustified trust to SW, HW, tools etc. “Thinking only up to the API” Preferring the way of least resistance No prototyping / No testing

Page 4: Tips for success: Common mistakes in application development with Firebird and how to avoid them

Solution

Think, don't just copy! If it walks as duck, squeaks as duck, it could

be a beaver in disguise! Don't trust strangers! ...especially those who offer you candy! You don't know until you verify it, so what

you're waiting for?

Page 5: Tips for success: Common mistakes in application development with Firebird and how to avoid them

Database Design

Artificial vs. Natural primary keys VARCHAR vs. BLOB Character sets Security

Page 6: Tips for success: Common mistakes in application development with Firebird and how to avoid them

Artificial vs. Natural keys

Artificial keys are always better (at the end) ...but there's hidden bloody price... ...the JOIN HELL

Users want to see anything else but keys Users use anything but keys for search You have to join tables to get in important

columns even it wouldn't be necessary You have to add more indices

Page 7: Tips for success: Common mistakes in application development with Firebird and how to avoid them

Solution

Use natural keys for most used “leaf” tables Cache the lookup tables in application

Full set for small ones MRU for big ones

Page 8: Tips for success: Common mistakes in application development with Firebird and how to avoid them

VARCHAR & BLOB – The Wrong

People decide by feel, not reason Focus on values, not how they're used Oversize just to be safe

Page 9: Tips for success: Common mistakes in application development with Firebird and how to avoid them

VARCHAR vs. BLOB - Solution

There is a great guide from Ivan Přenosilhttp://www.volny.cz/iprenosil/interbase/ip_ib_strings.htm

Quick tips: Anything longer than 150 characters is good candidate

for BLOB

BLOBs are bad news for search and server-side processing

Long VARCHARs are bad news for sorts

You can combine several long VARCHARs into single BLOB or refactor them out to 1:1 table

More than one BLOB per table is bad idea(Refactor BLOBs out to 1:1 table)

Page 10: Tips for success: Common mistakes in application development with Firebird and how to avoid them

Golden Rule of Database design

Get as much rows on single page as you can

BIGINT x INTEGER x SMALLINT

DATE x TIMESTAMP Non-empty BLOBs

are rows too! Pages smaller than

8K are pointless

Page 11: Tips for success: Common mistakes in application development with Firebird and how to avoid them

Character sets

Not that big problem today,But still some developers are careless

or blindly default to UTF-8

Page 12: Tips for success: Common mistakes in application development with Firebird and how to avoid them

Character sets - Solution

Always use one! Consider conversions!

What is native data type/encoding for strings your application uses?

Minimize number and complexity of conversions: Database <-> Application <-> Input/Output

Page 13: Tips for success: Common mistakes in application development with Firebird and how to avoid them

Security – The problem

EitherNO security at all

orExtreme security measures

Page 14: Tips for success: Common mistakes in application development with Firebird and how to avoid them

Security - Solution

Use as little from SQL security features as you can

Use remote server with restricted access Your application is exclusive gateway to the

database Use OWNER account (block SYSDBA if you

want) Implement fine-grained security in your

application

Page 15: Tips for success: Common mistakes in application development with Firebird and how to avoid them

Handling data – The wrong

“When I did this in ISQL, Flamerobin, my other app etc., it worked just fine, so what's wrong now?”

“It worked just fine on my development machine, so why it fails in production?”

“Damn, it doesn't scale as I expected...”

Page 16: Tips for success: Common mistakes in application development with Firebird and how to avoid them

Handling data 101

Get intimate with your connectivity library! Always manage your transactions manually! Always mind the MGA! Never fetch more data than you actually need! One size doesn't fit all:

Interactive vs. Machine processing Native vs. Web applications Embedded vs. Department vs. Corporate

Page 17: Tips for success: Common mistakes in application development with Firebird and how to avoid them

Know your connectivity

Identify higher and lower level access paths Learn the steps the access paths use

Path complexity Data conversions Storage requirements Algorithm efficiency Points of failure

Page 18: Tips for success: Common mistakes in application development with Firebird and how to avoid them

Transactions

Interactive All data read in single transaction

READ_ONLY READ_COMMITTED Writes in separate R/W transaction

Machine processing R/W in single SNAPSHOT or

READ_COMMITTED No UNDO log

Long running “monitoring” transactions READ_ONLY READ_COMMITTED

Page 19: Tips for success: Common mistakes in application development with Firebird and how to avoid them

MGA Implications

Long running transactions block GC Inserts never block other users, update and

delete may block Changes create garbage Correlating inserts with update/delete is VERY

bad idea Mass update/delete burdens you with GC

Page 20: Tips for success: Common mistakes in application development with Firebird and how to avoid them

Minimizing data transfers

Interactive Less rows Less columns, fetch the rest on demand Cache lookups on client

Machine processing Do as much on the server as you can

Page 21: Tips for success: Common mistakes in application development with Firebird and how to avoid them

Beware the “One code to rule them all”

Except the simplest cases, there is direct proportionality between universality and direct cost

Universal code that doesn't have an option to cop-out on special case to user code is recipe for disaster

Page 22: Tips for success: Common mistakes in application development with Firebird and how to avoid them

Questions?

Pavel Císař[email protected]

IBPhoenixwww.ibphoenix.com