Saturday, October 13, 2012

Normalizing Your Database: Third Normal Form (3NF)

Normalizing Your Database: Third Normal Form (3NF):


There are two basic requirements for a database to be in third normal form:
  • Already meet the requirements of both 1NF and 2NF
  • Remove columns that are not fully dependent upon the primary key.
Imagine that we have a table of widget orders that contains the following attributes:
  • Order Number
  • Customer Number
  • Unit Price
  • Quantity
  • Total
Remember, our first requirement is that the table must satisfy the requirements of 1NF and 2NF. Are there any duplicative columns? No. Do we have a primary key? Yes, the order number. Therefore, we satisfy the requirements of 1NF. Are there any subsets of data that apply to multiple rows? No, so we also satisfy the requirements of 2NF.
Now, are all of the columns fully dependent upon the primary key? The customer number varies with the order number and it doesn't appear to depend upon any of the other fields. What about the unit price? This field could be dependent upon the customer number in a situation where we charged each customer a set price. However, looking at the data above, it appears we sometimes charge the same customer different prices. Therefore, the unit price is fully dependent upon the order number. The quantity of items also varies from order to order, so we're OK there.
What about the total? It looks like we might be in trouble here. The total can be derived by multiplying the unit price by the quantity, therefore it's not fully dependent upon the primary key. We must remove it from the table to comply with the third normal form. Perhaps we use the following attributes:
  • Order Number
  • Customer Number
  • Unit Price
  • Quantity
Now our table is in 3NF. But, you might ask, what about the total? This is a derived field and it's best not to store it in the database at all. We can simply compute it "on the fly" when performing database queries. For example, we might have previously used this query to retrieve order numbers and totals:
 SELECT OrderNumber, Total
 FROM WidgetOrders
 
We can now use the following query:
 SELECT OrderNumber, UnitPrice * Quantity AS Total
 FROM WidgetOrders
 
to achieve the same results without violating normalization rules.

Database Normalization: First, Second, and Third Normal Forms | Andrew Rollins

Database Normalization: First, Second, and Third Normal Forms | Andrew Rollins: "This is a complex way of saying that if a column isn’t intrinsically related to the entire primary key, then you should break out the primary key into different tables."

'via Blog this'

Reduce finalizer usage


IBM Debugging OutOfMemory Errors and Performance Problems


Reduce finalizer usage

Use the smallest number of finalizers possible, and ensure that they run as quickly as possible
Introduction
Finalization of an object occurs when the object is no longer in use, but before it is removed from the heap. Only the Garbage Collector can determine if an object is no longer in use and is eligable for collection. When the Garbage Collector runs, it finds the unreachable objects that have a finalizer method and adds them to the finalizer queue. Because methods cannot be run during the stop-the-world phase of garbage collection, the removal of objects with finalizers is delayed until the garbage collection cycle after the finalizer method has been run. Where possible, this removal occurs in the next garbage collection cycle and collection is delayed only by a single cycle. If this removal does not occur, a backlog of objects requiring finalization can build up.
Ensuring objects are finalized before the next garbage collection cycle
A single thread is responsible for running the finalizer method of all objects with a finalizer method, and therefore this activity occurs serially. To ensure that finalization occurs before the next garbage collection cycle, follow these guidelines:
Use finalizers only where necessary
By reducing the number of finalizers, all finalization is more likely to occur between garbage collection cycles. Where possible, do cleanup synchronously without the use of finalizers.
Ensure that finalizers complete quickly
Finalizers must run as quickly as possible and avoid taking locks or blocking on external resources or connections.

Use the smallest number of finalizers possible, and ensure that they run as quickly as possible

Friday, October 12, 2012

[concurrency-interest] LinkedBlockingQueue extract and memory "waste"


[concurrency-interest] LinkedBlockingQueue extract and memory "waste":

A (possible) performance bug in JDK with LinkedBlockingQueue implementation leading to a memory issue.
Nullifying head.next pointers while extracting from LinkedBlockingQueue helps resolve the issue.

The Concurrency-interest Archives - Doug Lea et al

The Concurrency-interest Archives:

Concurrency-interest -- Discussion list for JSR-166

This is a Java concurrency package discussion forum where experts including the author/s of the java platform concurrency features (Doug Lea et al.) contribute their ideas / explanations on various core /systems level concurrency related topics.