8. SQL: Databases done right.
Circa 1970.
SELECT UPPER(Name) SELECT UPPER(Name) SELECT TOP 10 UPPER $ SET SOURCEFORMAT “FREE”
FROM Customer FROM (c1.Name) IDENTIFICATION DIVISION.
WHERE Name LIKE'A%' ( FROM Customer c1 Display Prompt.
ORDER BY Name SELECT *, WHERE c1.Name LIKE 'A%' DISPLAY “I <3 SQL!”.
RN = row_number() AND c1.ID NOT IN STOP RUN.
OVER (ORDER BY (
Name) SELECT TOP 20 c2.ID
FROM Customer FROM Customer c2
WHERE Name LIKE WHERE c2.Name LIKE 'A%‘
'A%' ORDER BY c2.Name
) A ) ORDER BY c1.Name
WHERE RN BETWEEN 21 AND
30
ORDER BY Name
var names = db.Customers
.Where(c => c.Name.StartsWith(“A”))
.OrderBy(c => c.Name)
Or how about… .Select(c => c.Name.ToUpper())
.Skip(20)
.Take(10);
9. SQL: Because objects and relational
databases go together like
peanut butter and tuna fish
10. SQL + OO =
Peanut butter + Tuna.
The object-relational impedance mismatch:
•Polymorphism doesn’t exist in the relational world
•Encapsulation creates fragile database models
•Inheritance results in inefficient relational queries
•Leaky abstraction
11. SQL + OO =
…but you can mask the tuna only so long…
12. SQL + OO =
var today= DateTime.Now;
context.TheBaseTypes
.Where(b => b.DateCreated == today)
.ToList();
“Expressing this query in LINQ to Entities is short and sweet. But
don’t be fooled. It’s a hefty request. You’re asking EF and your DB
query each table that maps to the derived entities and join each
one to the BaseTypes table.
In my environment, this creates a 3,200 line SQL query, which can
take Entity Framework some time to build and the database some
time to execute.”
-Julie Lerman, MSDN Magazine, August 2012
13. ORM: The Vietnam of
Computer Science
“ORM is the Vietnam of Computer Science.
It represents a quagmire which starts well,
gets more complicated as time passes, and
before long entraps its users in a
commitment that has no clear demarcation
point, no clear win conditions, and no clear
exit strategy.”
-Ted Neward
14. SQL:
The Hammer for every
nail
“The first to present his case seems right,
till another comes forward
and questions him.”
15. NoSQL:
A modern alternative to relational
databases
Don’t use T-SQL
Typically schema-free
Built for distributed scalability
Relax ACID guarantees
16. NoSQL:
A modern alternative to relational
databases
Trippy things like…
Cheap, fast reads
Horizontal scalability
Flexible, schema-free models
18. NoSQL has problems,
too.
Painful query models
Immature tooling
Complex APIs
Poor language support
19. RavenDB
“I’ve consulted on NHibernate and other
ORMs for over a decade. I’ve seen the same
problems repeated over and over.
I wanted to fix that.
So I created RavenDB.”
-Ayende
20. RavenDB
Get out of the RDBMS/ORM mess
Fix shortcomings of NoSQL
Evolve data storage
“I intentionally designed RavenDB and its .NET
API to deal with problems and frustrations in the
NHibernate / RDMBS model.”
-Ayende
27. RavenDB
Reads should be *fast*. Index fast.
Lock-free, non-ACID reads
“Better stale data quickly than live data slowly.”
Every read is a query against an index. Yes!
Indexes should be created
Consistency: all nodes see the same data at the same timeAvailability: a guarantee that every request receives a response about whether it was successful or failedPartition tolerance: the system continues to operate despite arbitrary message loss or failure of part of the system
The object-relational impedance mismatch is a set of conceptual and technical difficulties that are often encountered when a relational database management system (RDBMS) is being used by a program written in an object-oriented programming language or style; particularly when objects or class definitions are mapped in a straightforward way to database tables or relational schemata.
BASE: Basically available, soft state, eventually consistent