Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.

Database theory and modeling

155 Aufrufe

Veröffentlicht am

A crash course on basic database modeling, choosing the right database, optimization, and refactoring

Veröffentlicht in: Internet
  • Als Erste(r) kommentieren

  • Gehören Sie zu den Ersten, denen das gefällt!

Database theory and modeling

  1. 1. DATABASE THEORY AND MODELING A C R A S H C O U R S E D B A H O W TO
  2. 2. WHAT IS A DBA? DEVELOPMENT • Capacity Planning • Database Design • Database Implementation • Migration OPERATIONS • Installation • Configuration • Monitoring • Security and Access Management • Troubleshooting • Backup and Recovery
  3. 3. DATABASE THEORY THE STUDY OF DATABASES AND DATA MANAGEMENT SYSTEMS • Finite Model Theory • Database Design Theory • Dependency Theory • Concurrency Control • Deductive Databases • Temporal and Spatial Databases • Uncertain Data • Query Languages and Logic
  4. 4. DATA MODELING T U R N I N G B U S I N E S S R E Q U I R E M E N T S I N TO D ATA R O A D M A P S
  5. 5. REASONS FOR MODELING DATA WHAT? • Provide a definition of our data • Provide a format for our data WHY? • Compatibility of data • Lower cost to build, operate, and maintain systems
  6. 6. THREE KINDS OF DATA MODEL INSTANCES • Conceptual Data Model • Logical (External) Data Model • Physical Data Model
  7. 7. CONCEPTUAL MODEL • Entities that comprise your data • Creating data objects • Identifying any relationships between objects • "Business Requirements"
  8. 8. PROJECT SCOPE MY BUSINESS REQUIREMENTS • I have a lot of video games • I want a simple way to be able to find my video games by keywords • And keep track of what system they are for • And keep track of when I last played them and when someone else played them • And keep track of if I beat them, and my kids too
  9. 9. CONCEPTUAL MODEL Game • Name • System Keywords • Categories • Type Player • Date • Completed
  10. 10. LOGICAL MODEL – FLAT MODEL Game Title System Liz Last Play Pat Last Play Liz Complete Pat Complete Keywords FFX PS2 2016-05-01 2016-06-04 Yes No fantasy, jrpg Chrono Trigger PS1 2014-07-05 Yes No jrpg Forza 4 Xbox360 2017-03-02 No No racing
  11. 11. HIERARCHICAL MODEL Games Xbox360 Forza4 PS1 Chrono Trigger PS2 Final Fantasy X
  12. 12. RELATIONAL MODEL • I have a system • I have a game • I have a player • Each game has one system, each system can have many games • Games can have many players, each player can have additional information
  13. 13. DATA STORAGE C H O O S I N G D ATA B A S E S O F T WA R E
  14. 14. RELATIONAL DATABASES • Relate (Link) different bits of data to each other • Very reliable places to store data • MUST be ACID
  15. 15. ACID COMPLIANCE • Atomicity • Consistency • Isolation • Durability
  16. 16. DOCUMENT DATABASES • Schemaless • Good Performance • Speedy and Distributed • Consistency model is BASE • Graph Databases are Document Databases with relationships added for traversal
  17. 17. BASE • Basic Availability • Soft State • Eventually Consistent
  18. 18. DATA WAREHOUSES • A place to aggregate and store data for reporting and analysis • ETL – Extract – Transform – Load • Data Mart (single subject area) • OLAP (Online analytical Processing) • OLTP (Online transaction Processing)
  19. 19. SCALING DATABASES • Horizontal (Distributed) • Vertical • Read Replicas • Multi-Master • Partioning (Sharding)
  20. 20. CAP THEOREM Consistency Availability Fault Tolerance
  21. 21. CHOOSE… WISELY • Politics will factor into this! • You don't have to pick just one • Choose the right solution for the right problem • With so much available in cloud services and the ease of using containers, spinning up lightweight places for redis to use in addition to your Postgresql server is not more expensive!
  22. 22. NORMALIZATION O R G A N I Z I N G I N TO TA B L E S A N D C O L U M N S
  23. 23. NO MORE ANOMALIES • Update Anomaly • Insertion Anomaly • Deletion Anomaly • Fidelity Anomaly
  24. 24. NO DUPLICATED DATA MINIMIZE REDESIGN ON EXTENSION • Store all data in only one place • What happens if I add an additional family member I want to track in my application • The normalized version makes this simple
  25. 25. FIRST NORMAL FORM 1NF • Has a Primary Key – can be a COMPOUND key • Has only atomic values • Has no repeated columns
  26. 26. SECOND NORMAL FORM 2NF • Table is 1NF AND • All non-key columns are PK dependent
  27. 27. THIRD NORMAL FORM 3NF • 2NF PLUS • No Transitively dependent attributes
  28. 28. BUT WAIT – THERE'S MORE! • 7 more to be exact • They're not really that useful in most situations • You can learn about them from Wikipedia!
  29. 29. DENORMALIZATION • Wait – didn't you just say to normalize things? • Usually has one purpose, increased performance, and should be use sparingly • Doesn't have to be "full" denormalization – Storing count totals of many elements in a relationship – star schema "fact-dimension" models – prebuilt summarizations
  30. 30. RELATIONSHIPSC A R D I N A L I T Y B E T W E E N A L L T H E T H I N G S
  31. 31. TYPES OF RELATIONS • One to One • One to Many • Many to Many
  32. 32. TYPES OF KEYS • Natural Key • Alternate Key • GUID (UUID)
  33. 33. OPTIMIZATION M A K E I T G O FA S T. . E R
  34. 34. PICK TWO? Speed Small Size Correct Data
  35. 35. PHYSICS MATTERS • Make sure you have enough hardware • Tune your I/O – Block and Stripe size allocation for RAID configuration – Transaction logs in the right spot – Frequently joined tables on separate discs • Tune your network protocols • Adjust cache sizes
  36. 36. UPDATE ALL THE THINGS • Update your operating system • Update your db software • Update your communications protocols
  37. 37. TUNE YOUR SYSTEMS • Check your vendor for configuration tuning • Perform your recommended maintenance tasks
  38. 38. PROFILE YOUR CODE • Check for slow queries • Check the execution plan on the queries • Add Indexes to speed up joins • Rewrite or alter queries to make them perform faster • Create Views for a query that are indexed separately – This is best for common joins • Move routines for data manipulation into stored procedures • Create cached or denormalized versions of really slow queries
  39. 39. REFACTORING DATA M O V I N G S T U F F A R O U N D S U C K S D O I T A N Y WAY
  40. 40. REFERENTIAL INTEGRITY REFACTORING • Add constraints • Remove constraints • Add Hard Delete • Add Soft Delete • Add Trigger for Calculated Column • Add Trigger for History • Add Indexes
  41. 41. DATA QUALITY REFACTORING • Add lookup table • Apply Standard codes • Apply Standard Type • Add a column constraint • Introduce common format
  42. 42. STRUCTURAL REFACTORING • Add a new element • Delete an existing element • Merge elements • Change association types • Split elements
  43. 43. ARCHITECTURE REFACTORING • Replace a method with a view • Add a calculation method • Encapsulate a table with a view • Add a mirror table • Add a read only table
  44. 44. LEARNING MORE • Free University Courses – Databases are one thing colleges get RIGHT – MIT, Stanford, and others have great database theory classes – Warning, many use python – it won't kill you • Books – http://web.cecs.pdx.edu/~maier/TheoryBook/TRD.html - The Theory of Relational Databases – https://www.amazon.com/Database-Design-Relational-Theory-Normal/dp/1449328016 - Database Design and Relational Theory – http://databaserefactoring.com/ Database refactoring
  45. 45. CONTACT • auroraeosrose@gmail.com • @auroraeosrose • http://emsmith.net • http://github.com/auroraeosros e • Freenode • #phpwomen • #phpmentoring • #php-gtk

×