Client Validations

   

When a client (rather than the server) performs a constraint check, it's usually called a "validation" instead of a constraint. Validations may be inappropriate for business rules but are reasonable for verifying that input is formatted correctly and contains meaningful values.

Validations are redundantthe server will do them anyway. But that doesn't make validations a waste of time, because the client and server are on separate processors. By using validations, you aren't relying on the client; you're only helping throughput by ensuring that ridiculous transactions won't go across the network to the server.

Considering that bad data is less common than good data, is this filtering worthwhile? Absolutely, because a failed process takes longer than a successful one. Here's an example. In Oracle, constraint checking takes place during row processing, and constraints are checked a second time at end of statement if there are any interim violations. So a violated check gets processed twice as often as an unviolated check. Add on the fact that Oracle, if a statement fails at the end, has to roll back any changes made during the statement by restoring the original "before image" copy. So failures can cost more than successes.

Clients can check constraints that relate to a single instance of a rowfor example, a check digit, a range, an absence, or a serial number. You must be warier of using clients to check whether a user has authorization, whether a withdrawal amount is too large, or the like, as these are all examples of business rules. For reasons we'll discuss elsewhere (see Chapter 16, " Clients and Servers"), it is rare nowadays to process many business rules on the client computer.

The Bottom Line: Client Validations

Having a client machine validate data rather than sending it to the server to be checked saves time by ensuring that ridiculous transactions won't go across the network to waste time on the server.

Clients can check constraints that relate to a single instance of a rowfor example, a check digit, a range, an absence, or a serial number.

Clients shouldn't check constraints that relate to business rulesfor example, whether a withdrawal amount is too large or a book has been catalogued.

   


SQL Performance Tuning
SQL Performance Tuning
ISBN: 0201791692
EAN: 2147483647
Year: 2005
Pages: 125

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net