What is Impedance Mismatch?

Relational impedance mismatch is a set of technical difficulties appearing because objects or class definitions must be mapped to database tables defined by relational schema.

Concretely, initial versions of SQL were not computationally complete (they did not have any programming constructs like declarations or conditional statements) but nowadays you can embed SQL in high-level programming languages (Java, C, Python and so on).

And here comes the impedance mismatch. SQL is a declarative language while C (or whatever high-level programming language you chose to embed your SQL queries on) is a procedural language, leading to a mixing of approaches and requiring a huge amount of unnecessary effort.

For instance, SQL has the Date type and handles rows of data at a time while high-level programming languages might use different models to represent data (i.e might not have the Date type) and can handle only one row of data at a time.

We might consider extending SQL with procedural constructs (SQL/PSM = Persistent Stored Modules) to avoid impedance mismatching and to treat a table as a flat file that can be accessed one row at a time.


Quoted from hacked.com

Imagine you have a low current flashlight that normally uses AAA batteries. Don't try this at home, but suppose you could attach your car battery to the flashlight. The low current flashlight will pitifully output a fraction of the light energy that the high current battery is capable of producing. Likewise, if you attached the AAA batteries to Batman's spotlight, you'll also get low output. However, match the AAA batteries to the flashlight and they will run with maximum efficiency.

So taking this discussion back to software engineering, if you imagine the flow of data to be analogous to a current, then the impedance of a relational data model is not matched with the impedance of an object hierarchy. Therefore, the data will not flow with maximum efficiency, a result of the impedance mismatch.


Mismatches between two paradigms like the Object-Oriented world and Relational world are called Impedance Mismatch.

There are 5 Mismatches that are there...

1) Granularity:- The number of classes and tables are sometimes different. (in one table we are storing multiple class object data.)

2) Subtype:- Object-oriented world has an Inheritance relationship but the Relational database world doesn't support inheritance.

3) Association:- Object-oriented world has Association relationship but the Relational database world doesn't support Association.

4) Identity:- Identity of an object in an Object-oriented world and the identity of a record in the Relational database world are different.

5) Data navigation:- Object data can navigate through their object-reference but the table data can't navigate.

If any framework solves this Mismatch completely then that framework is called a perfect ORM framework.

Tags:

Database

Sql