SlideShare ist ein Scribd-Unternehmen logo
1 von 33
know more about MySQL open source database




                 Salaria Software Services   1
ļ‚— Storage engines
ļ‚— Schema
ļ‚— Normalization
ļ‚— Data types
ļ‚— Indexes
ļ‚— Know more about your SQL queries - Using EXPLAIN
ļ‚— Character set and Collation
ļ‚— Resources



                        Salaria Software Services    2
ļ‚— Generics are inefficient
ā€¢ If you have chosen MySQL, take advantage of its
   strengths
ā€¢ Having an understanding of the database helps you
   develop better-performing applications
  ļƒ¼ better to design a well-performing database-driven
    application from the start
  ļƒ¼ than try to fix a slow one after the fact!




                           Salaria Software Services     3
ļ‚— MySQL supports several
 storage engines that act
 as handlers for different
 table types
  ļƒ¼ No other database
    vendor offers this
    capability




                         Salaria Software Services   4
ļ‚— Dynamically add and remove storage engines.
ļ‚— Change the storage engine on a table with
   ā€œALTER TABLE <table> ENGINE=InnoDB;ā€




                        Salaria Software Services   5
ļ‚— Concurrency: some have more granular locks than
  others
  ļƒ¼ right locking can improve performance.
ā€¢ Storage: how the data is stored on disk
  ļƒ¼ page size for tables, indexes, format used
ā€¢ Indexes: b-trees, hash
ā€¢ Memory usage
  ļƒ¼ caching strategy
ā€¢ Transactions:
  ļƒ¼ not every application table needs transactions

                           Salaria Software Services   6
ā€œAs a developer, what do I need to know
   about storage engines, without being a
              MySQL expert?ā€
ā€¢ Keep in mind the following questions:
  ļƒ¼ What type of data will you be storing?
  ļƒ¼ Is the data constantly changing?
  ļƒ¼ Is the data mostly logs (INSERTs)?
  ļƒ¼ requirements for reports?
  ļƒ¼ need for transaction control?


                         Salaria Software Services   7
ļ‚— Default MySQL engine
ā€¢ high-speed Query and Insert capability
  ļƒ¼ insert uses shared read lock
  ļƒ¼ updates, deletes use table-level locking, slower
ā€¢ full-text indexing
  ļƒ¼ Good for text search
ā€¢ Non-transactional, No foreign key support
ā€¢ good choice for :
  ļƒ¼ read-only or read-mostly application tables that don't
    require transactions
  ļƒ¼ Web, data warehousing, logging, auditing

                           Salaria Software Services         8
ļ‚— Transaction-safe and ACID
  (atomicity, consistency, isolation, durability) compliant
  ļƒ¼ crash recovery, foreign key constraints
ā€¢ good query performance, depending on indexes
ā€¢ row-level locking, Multi Version Concurrency Control
   (MVCC)
  ļƒ¼ allows fewer row locks by keeping data snapshots
     ā€“ Depending on the isolation level, no locking for SELECT
     ā€“ high concurrency possible
ā€¢ uses more disk space and memory than ISAM
ā€¢ Good for Online transaction processing (OLTP)
  ļƒ¼ Lots of users: eBay, Google, Yahoo!, Facebook, etc.


                              Salaria Software Services          9
ļ‚— Entirely in-memory engine
  ļƒ¼ stores all data in RAM for extremely fast access
  ļƒ¼ Updated Data is not persisted
     ā€“ table loaded on restart
ā€¢ Hash index used by default
ā€¢ Good for
  ļƒ¼ Summary and transient data
  ļƒ¼ "lookup" tables,
  ļƒ¼ calculated table counts,
  ļƒ¼ for caching, temporary tables


                          Salaria Software Services    10
ļ‚— Incredible insert speeds
ā€¢ Great compression rates (zlib)?
  ļƒ¼ Typically 6-8x smaller than MyISAM
ā€¢ No UPDATEs
ā€¢ Ideal for storing and retrieving large amounts of
   historical data
  ļƒ¼ audit data, log files,Web traffic records
  ļƒ¼ Data that can never be updated




                          Salaria Software Services   11
ļ‚— You can use multiple
  storage engines in a
  single application
  ļƒ¼ A storage engine for the
    same table on a slave can
    be different than that of
    the master
ā€¢ Choose storage engine
   that's best for your
   applications requirements
  ļƒ¼ can greatly improve
    performance

                           Salaria Software Services   12
ļ‚— Creating a table with a specified engine
  ļƒ¼ CREATE TABLE t1 (...)
    ENGINE=InnoDB;
ā€¢ Changing existing tables
  ļƒ¼ ALTER TABLE t1 ENGINE=MyISAM;
ā€¢ Finding all your available engines
  ļƒ¼ SHOW STORAGE ENGINES;




                         Salaria Software Services   13
Basic foundation of performance
ā€¢ Normalization
ā€¢ Data Types
  ļƒ¼ Smaller, smaller, smaller
     - Smaller tables use less disk, less memory, can give better
        performance
ā€¢ Indexing
  ļƒ¼ Speeds up retrieval




                             Salaria Software Services              14
ļ‚— Eliminate redundant data:
  ļƒ¼ Don't store the same data in more than one table
  ļƒ¼ Only store related data in a table
  ļƒ¼ reduces database size and errors




                          Salaria Software Services    15
ļ‚— updates are usually faster.
  ļƒ¼ there's less data to change.
ā€¢ tables are usually smaller, use less memory, which
   can give better performance.
ā€¢ better performance for distinct or group by queries




                          Salaria Software Services     16
ļ‚— However Normalized database causes joins for queries
ā€¢ excessively normalized database:
  ļƒ¼ queries take more time to complete, as data has to be
    retrieved from more tables.
ā€¢ Normalized better for writes OLTP
ā€¢ De-normalized better for reads , reporting
ā€¢ Real World Mixture:
  ļƒ¼ normalized schema
  ļƒ¼ Cache selected columns in memory table



                         Salaria Software Services          17
Smaller => less disk => less memory => better
 performance

ļ‚— Use the smallest data type possible
ā€¢ The smaller your data types, The more index (and data)
  can fit into a block of memory, the faster your queries
  will be.
  ļƒ¼ Period.
  ļƒ¼ Especially for indexed fields



                          Salaria Software Services         18
ļ‚— MySQL has 9 numeric data types
   ļƒ¼ Compared to Oracle's 1
ā€¢ Integer:
   ļƒ¼ TINYINT , SMALLINT, MEDIUMINT, INT, BIGINT
   ļƒ¼ Require 8, 16, 24, 32, and 64 bits of space.
ā€¢ Use UNSIGNED when you don't need negative numbers ā€“ one more level of data
   integrity
ā€¢ BIGINT is not needed for AUTO_INCREMENT
   ļƒ¼ INT UNSIGNED stores 4.3 billion values!
   ļƒ¼ Summation of values... yes, use BIGINT
ļ‚— Floating Point: FLOAT, DOUBLE
   ļƒ¼ Approximate calculations
ā€¢ Fixed Point: DECIMAL
   ļƒ¼ Always use DECIMAL for monetary/currency fields, never use FLOAT or
      DOUBLE!
ā€¢ Other: BIT
   ļƒ¼ Store 0,1 values

                                  Salaria Software Services                    19
ļ‚— VARCHAR(n) variable length
  ļƒ¼ uses only space it needs
     ā€“ Can save disk space = better performance
  ļƒ¼ Use :
    ā€“ Max column length > avg
    ā€“ when updates rare (updates fragment)
ā€¢ CHAR(n) fixed length
  ļƒ¼ Use:
     ā€“ short strings, Mostly same length, or changed frequently




                            Salaria Software Services             20
ļ‚— Always define columns as NOT NULL
     ā€“ unless there is a good reason not to
  ļƒ¼ Can save a byte per column
  ļƒ¼ nullable columns make indexes, index statistics, and
    value comparisons more complicated.
ā€¢ Use the same data types for columns that will be
  compared in JOINs
  ļƒ¼ Otherwise converted for comparison
ā€¢ Use BLOBs very sparingly
  ļƒ¼ Use the filesystem for what it was intended


                          Salaria Software Services        21
ā€œThe more records you can fit into a single page of
  memory/disk, the faster your seeks and scans will be.ā€
ā€¢ Use appropriate data types
ā€¢ Keep primary keys small
ā€¢ Use TEXT sparingly
  ļƒ¼ Consider separate tables
ā€¢ Use BLOBs very sparingly
  ļƒ¼ Use the filesystem for what it was intended




                         Salaria Software Services         22
ļ‚— Indexes Speed up Queries,
  ļƒ¼ SELECT...WHERE name = 'carol'
  ļƒ¼ only if there is good selectivity:
     ā€“ % of distinct values in a column
ā€¢ But... each index will slow down INSERT, UPDATE, and
  DELETE operations




                            Salaria Software Services    23
ļ‚— Always have an index on join conditions
ā€¢ Look to add indexes on columns used in WHERE and
  GROUP BY expressions
ā€¢ PRIMARY KEY, UNIQUE , and Foreign key Constraint
  columns are automatically indexed.
  ļƒ¼ other columns can be indexed (CREATE INDEX..)




                       Salaria Software Services     24
ļ‚— use the MySQL slow query log and use Explain
ā€¢ Append EXPLAIN to your SELECT statement
  ļƒ¼ shows how the MySQL optimizer has chosen to execute
    the query
ā€¢ You Want to make your queries access less data:
  ļƒ¼ are queries accessing too many rows or columns?
     ā€“ select only the columns that you need
ā€¢ Use to see where you should add indexes
  ļƒ¼ Consider adding an index for slow queries or cause a lot
    of load.
     ā€“ ensures that missing indexes are picked up early in the
       development process

                            Salaria Software Services            25
ļ‚— Find and fix problem SQL:
ā€¢ how long a query took
ā€¢ how the optimizer handled it
  ļƒ¼ Drill downs, results of EXPLAIN statements
ā€¢ Historical and real-time analysis
  ļƒ¼ query execution counts, run time


  ā€œIts not just slow running queries that are a problem,
  Sometimes its SQL that executes a lot that kills your
                          systemā€

                         Salaria Software Services         26
ļ‚— Just append EXPLAIN to
   your SELECT statement
ā€¢ Provides the execution plan
   chosen by the MySQL
   optimizer for a specific
   SELECT statement
  ļƒ¼ Shows how the MySQL
    optimizer executes the
    query
ā€¢ Use to see where you should
  add indexes
  ļƒ¼ ensures that missing
    indexes are picked up early
    in the development
    process
                             Salaria Software Services   27
ļ‚— A character set is a set of symbols and encodings.
ļ‚— A collation is a set of rules for comparing characters in a
  character set.
ļ‚— MySQL can do these things for you:
  ļƒ¼ Store strings using a variety of character sets
  ļƒ¼ Compare strings using a variety of collations
  ļƒ¼ Mix strings with different character sets or collations in the
    same server, the same database, or even the same table
  ļƒ¼ Allow specification of character set and collation at any level
      - Mysql > SET NAMES 'utf8';
      - Mysql > SHOW CHARACTER SET


                             Salaria Software Services                28
ļ‚— Two different character sets cannot have the same
  collation.
ļ‚— Each character set has one collation that is the default
  collation. For example, the default collation for latin1 is
  latin1_swedish_ci. The output for ā€œSHOW CHARACTER
  SETā€ indicates which collation is the default for each
  displayed character set.
ļ‚— There is a convention for collation names: They start with
  the name of the character set with which they are
  associated, they usually include a language name, and they
  end with _ci (case insensitive), _cs (case sensitive), or _bin
  (binary).

                           Salaria Software Services               29
ļ‚— <meta http-equiv="Content-Type" content="text/html;
  charset=utf-8" />
ļ‚— <?php mysql_query('SET NAMES utf8'); ?>
ļ‚— CREATE DATABASE mydatabase DEFAULT CHARACTER
  SET utf8 COLLATE utf8_general_ci;
ļ‚— CREATE TABLE mytable (
    mydata VARCHAR(128) NOT NULL
  ) ENGINE=MyISAM DEFAULT CHARACTER SET utf8
  COLLATE utf8_general_ci;



                        Salaria Software Services       30
ļ‚— MySQL Forge and the Forge Wiki
http://forge.mysql.com/
ļ‚— Planet MySQL
 http://planetmysql.org/
ļ‚— MySQL DevZone
http://dev.mysql.com/
ļ‚— High Performance MySQL book




                      Salaria Software Services   31
?

Salaria Software Services   32
Mahesh Salaria
  mahesh@salaria.net
Salaria Software Services
 http://salariasoft.com
      Salaria Software Services   33

Weitere Ƥhnliche Inhalte

Was ist angesagt?

SQL Explore 2012: P&T Part 2
SQL Explore 2012: P&T Part 2SQL Explore 2012: P&T Part 2
SQL Explore 2012: P&T Part 2
sqlserver.co.il
Ā 

Was ist angesagt? (20)

SQL Server 2016 Editions
SQL Server 2016 Editions SQL Server 2016 Editions
SQL Server 2016 Editions
Ā 
Optimization SQL Server for Dynamics AX 2012 R3
Optimization SQL Server for Dynamics AX 2012 R3Optimization SQL Server for Dynamics AX 2012 R3
Optimization SQL Server for Dynamics AX 2012 R3
Ā 
SQL Server 2016 novelties
SQL Server 2016 noveltiesSQL Server 2016 novelties
SQL Server 2016 novelties
Ā 
SQL Server 2016 BI updates
SQL Server 2016 BI updatesSQL Server 2016 BI updates
SQL Server 2016 BI updates
Ā 
SQL Server 2016 New Features and Enhancements
SQL Server 2016 New Features and EnhancementsSQL Server 2016 New Features and Enhancements
SQL Server 2016 New Features and Enhancements
Ā 
Star schema my sql
Star schema   my sqlStar schema   my sql
Star schema my sql
Ā 
Sql 2016 - What's New
Sql 2016 - What's NewSql 2016 - What's New
Sql 2016 - What's New
Ā 
Everything you need to know about SQL Server 2016
Everything you need to know about SQL Server 2016Everything you need to know about SQL Server 2016
Everything you need to know about SQL Server 2016
Ā 
Real Time Operational Analytics with Microsoft Sql Server 2016 [Liviu Ieran]
Real Time Operational Analytics with Microsoft Sql Server 2016 [Liviu Ieran]Real Time Operational Analytics with Microsoft Sql Server 2016 [Liviu Ieran]
Real Time Operational Analytics with Microsoft Sql Server 2016 [Liviu Ieran]
Ā 
SQL server 2016 New Features
SQL server 2016 New FeaturesSQL server 2016 New Features
SQL server 2016 New Features
Ā 
Student projects with open source CSQL
Student projects with open source CSQLStudent projects with open source CSQL
Student projects with open source CSQL
Ā 
Exploring sql server 2016
Exploring sql server 2016Exploring sql server 2016
Exploring sql server 2016
Ā 
Scalable relational database with SQL Azure
Scalable relational database with SQL AzureScalable relational database with SQL Azure
Scalable relational database with SQL Azure
Ā 
Redshift deep dive
Redshift deep diveRedshift deep dive
Redshift deep dive
Ā 
Monitorando performance no Azure SQL Database
Monitorando performance no Azure SQL DatabaseMonitorando performance no Azure SQL Database
Monitorando performance no Azure SQL Database
Ā 
Introduction to Azure Data Lake
Introduction to Azure Data LakeIntroduction to Azure Data Lake
Introduction to Azure Data Lake
Ā 
SQL Explore 2012: P&T Part 2
SQL Explore 2012: P&T Part 2SQL Explore 2012: P&T Part 2
SQL Explore 2012: P&T Part 2
Ā 
Sql server 2016 new features
Sql server 2016 new featuresSql server 2016 new features
Sql server 2016 new features
Ā 
Exploring T-SQL Anti-Patterns
Exploring T-SQL Anti-Patterns Exploring T-SQL Anti-Patterns
Exploring T-SQL Anti-Patterns
Ā 
Using extended events for troubleshooting sql server
Using extended events for troubleshooting sql serverUsing extended events for troubleshooting sql server
Using extended events for troubleshooting sql server
Ā 

Andere mochten auch (7)

Test Driven Development and Automation
Test Driven Development and AutomationTest Driven Development and Automation
Test Driven Development and Automation
Ā 
Drupal8 render pipeline
Drupal8 render pipelineDrupal8 render pipeline
Drupal8 render pipeline
Ā 
Test Driven Development with PHP
Test Driven Development with PHPTest Driven Development with PHP
Test Driven Development with PHP
Ā 
TDD in PHP - Memphis PHP 2011-08-25
TDD in PHP - Memphis PHP 2011-08-25TDD in PHP - Memphis PHP 2011-08-25
TDD in PHP - Memphis PHP 2011-08-25
Ā 
Hackathon @Kayako
Hackathon @KayakoHackathon @Kayako
Hackathon @Kayako
Ā 
Clean code and Coding Standards
Clean code and Coding StandardsClean code and Coding Standards
Clean code and Coding Standards
Ā 
Hype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerHype vs. Reality: The AI Explainer
Hype vs. Reality: The AI Explainer
Ā 

Ƅhnlich wie MySQL: Know more about open Source Database

Handling Massive Writes
Handling Massive WritesHandling Massive Writes
Handling Massive Writes
Liran Zelkha
Ā 

Ƅhnlich wie MySQL: Know more about open Source Database (20)

Mysql For Developers
Mysql For DevelopersMysql For Developers
Mysql For Developers
Ā 
25 snowflake
25 snowflake25 snowflake
25 snowflake
Ā 
Azure data platform overview
Azure data platform overviewAzure data platform overview
Azure data platform overview
Ā 
Building better SQL Server Databases
Building better SQL Server DatabasesBuilding better SQL Server Databases
Building better SQL Server Databases
Ā 
Technical Introduction to PostgreSQL and PPAS
Technical Introduction to PostgreSQL and PPASTechnical Introduction to PostgreSQL and PPAS
Technical Introduction to PostgreSQL and PPAS
Ā 
Powering GIS Application with PostgreSQL and Postgres Plus
Powering GIS Application with PostgreSQL and Postgres Plus Powering GIS Application with PostgreSQL and Postgres Plus
Powering GIS Application with PostgreSQL and Postgres Plus
Ā 
MySQL :What's New #GIDS16
MySQL :What's New #GIDS16MySQL :What's New #GIDS16
MySQL :What's New #GIDS16
Ā 
Database storage engines
Database storage enginesDatabase storage engines
Database storage engines
Ā 
Nosql data models
Nosql data modelsNosql data models
Nosql data models
Ā 
(ISM303) Migrating Your Enterprise Data Warehouse To Amazon Redshift
(ISM303) Migrating Your Enterprise Data Warehouse To Amazon Redshift(ISM303) Migrating Your Enterprise Data Warehouse To Amazon Redshift
(ISM303) Migrating Your Enterprise Data Warehouse To Amazon Redshift
Ā 
Deep Dive on Amazon Redshift
Deep Dive on Amazon RedshiftDeep Dive on Amazon Redshift
Deep Dive on Amazon Redshift
Ā 
Deep Dive on Amazon Redshift
Deep Dive on Amazon RedshiftDeep Dive on Amazon Redshift
Deep Dive on Amazon Redshift
Ā 
Query Optimization in SQL Server
Query Optimization in SQL ServerQuery Optimization in SQL Server
Query Optimization in SQL Server
Ā 
AWS Webcast - Backup & Restore for ElastiCache/Redis: Getting Started & Best ...
AWS Webcast - Backup & Restore for ElastiCache/Redis: Getting Started & Best ...AWS Webcast - Backup & Restore for ElastiCache/Redis: Getting Started & Best ...
AWS Webcast - Backup & Restore for ElastiCache/Redis: Getting Started & Best ...
Ā 
Handling Massive Writes
Handling Massive WritesHandling Massive Writes
Handling Massive Writes
Ā 
(BDT401) Amazon Redshift Deep Dive: Tuning and Best Practices
(BDT401) Amazon Redshift Deep Dive: Tuning and Best Practices(BDT401) Amazon Redshift Deep Dive: Tuning and Best Practices
(BDT401) Amazon Redshift Deep Dive: Tuning and Best Practices
Ā 
amazon database
amazon databaseamazon database
amazon database
Ā 
MySQL Performance Tuning at COSCUP 2014
MySQL Performance Tuning at COSCUP 2014MySQL Performance Tuning at COSCUP 2014
MySQL Performance Tuning at COSCUP 2014
Ā 
Oracle Database in-Memory Overivew
Oracle Database in-Memory OverivewOracle Database in-Memory Overivew
Oracle Database in-Memory Overivew
Ā 
Best Practices ā€“ Extreme Performance with Data Warehousing on Oracle Databa...
Best Practices ā€“  Extreme Performance with Data Warehousing  on Oracle Databa...Best Practices ā€“  Extreme Performance with Data Warehousing  on Oracle Databa...
Best Practices ā€“ Extreme Performance with Data Warehousing on Oracle Databa...
Ā 

KĆ¼rzlich hochgeladen

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(ā˜Žļø+971_581248768%)**%*]'#abortion pills for sale in dubai@
Ā 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
Ā 

KĆ¼rzlich hochgeladen (20)

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
Ā 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
Ā 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Ā 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
Ā 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
Ā 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Ā 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
Ā 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
Ā 
šŸ¬ The future of MySQL is Postgres šŸ˜
šŸ¬  The future of MySQL is Postgres   šŸ˜šŸ¬  The future of MySQL is Postgres   šŸ˜
šŸ¬ The future of MySQL is Postgres šŸ˜
Ā 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
Ā 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
Ā 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
Ā 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
Ā 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
Ā 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
Ā 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Ā 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
Ā 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
Ā 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
Ā 
Scaling API-first ā€“ The story of a global engineering organization
Scaling API-first ā€“ The story of a global engineering organizationScaling API-first ā€“ The story of a global engineering organization
Scaling API-first ā€“ The story of a global engineering organization
Ā 

MySQL: Know more about open Source Database

  • 1. know more about MySQL open source database Salaria Software Services 1
  • 2. ļ‚— Storage engines ļ‚— Schema ļ‚— Normalization ļ‚— Data types ļ‚— Indexes ļ‚— Know more about your SQL queries - Using EXPLAIN ļ‚— Character set and Collation ļ‚— Resources Salaria Software Services 2
  • 3. ļ‚— Generics are inefficient ā€¢ If you have chosen MySQL, take advantage of its strengths ā€¢ Having an understanding of the database helps you develop better-performing applications ļƒ¼ better to design a well-performing database-driven application from the start ļƒ¼ than try to fix a slow one after the fact! Salaria Software Services 3
  • 4. ļ‚— MySQL supports several storage engines that act as handlers for different table types ļƒ¼ No other database vendor offers this capability Salaria Software Services 4
  • 5. ļ‚— Dynamically add and remove storage engines. ļ‚— Change the storage engine on a table with ā€œALTER TABLE <table> ENGINE=InnoDB;ā€ Salaria Software Services 5
  • 6. ļ‚— Concurrency: some have more granular locks than others ļƒ¼ right locking can improve performance. ā€¢ Storage: how the data is stored on disk ļƒ¼ page size for tables, indexes, format used ā€¢ Indexes: b-trees, hash ā€¢ Memory usage ļƒ¼ caching strategy ā€¢ Transactions: ļƒ¼ not every application table needs transactions Salaria Software Services 6
  • 7. ā€œAs a developer, what do I need to know about storage engines, without being a MySQL expert?ā€ ā€¢ Keep in mind the following questions: ļƒ¼ What type of data will you be storing? ļƒ¼ Is the data constantly changing? ļƒ¼ Is the data mostly logs (INSERTs)? ļƒ¼ requirements for reports? ļƒ¼ need for transaction control? Salaria Software Services 7
  • 8. ļ‚— Default MySQL engine ā€¢ high-speed Query and Insert capability ļƒ¼ insert uses shared read lock ļƒ¼ updates, deletes use table-level locking, slower ā€¢ full-text indexing ļƒ¼ Good for text search ā€¢ Non-transactional, No foreign key support ā€¢ good choice for : ļƒ¼ read-only or read-mostly application tables that don't require transactions ļƒ¼ Web, data warehousing, logging, auditing Salaria Software Services 8
  • 9. ļ‚— Transaction-safe and ACID (atomicity, consistency, isolation, durability) compliant ļƒ¼ crash recovery, foreign key constraints ā€¢ good query performance, depending on indexes ā€¢ row-level locking, Multi Version Concurrency Control (MVCC) ļƒ¼ allows fewer row locks by keeping data snapshots ā€“ Depending on the isolation level, no locking for SELECT ā€“ high concurrency possible ā€¢ uses more disk space and memory than ISAM ā€¢ Good for Online transaction processing (OLTP) ļƒ¼ Lots of users: eBay, Google, Yahoo!, Facebook, etc. Salaria Software Services 9
  • 10. ļ‚— Entirely in-memory engine ļƒ¼ stores all data in RAM for extremely fast access ļƒ¼ Updated Data is not persisted ā€“ table loaded on restart ā€¢ Hash index used by default ā€¢ Good for ļƒ¼ Summary and transient data ļƒ¼ "lookup" tables, ļƒ¼ calculated table counts, ļƒ¼ for caching, temporary tables Salaria Software Services 10
  • 11. ļ‚— Incredible insert speeds ā€¢ Great compression rates (zlib)? ļƒ¼ Typically 6-8x smaller than MyISAM ā€¢ No UPDATEs ā€¢ Ideal for storing and retrieving large amounts of historical data ļƒ¼ audit data, log files,Web traffic records ļƒ¼ Data that can never be updated Salaria Software Services 11
  • 12. ļ‚— You can use multiple storage engines in a single application ļƒ¼ A storage engine for the same table on a slave can be different than that of the master ā€¢ Choose storage engine that's best for your applications requirements ļƒ¼ can greatly improve performance Salaria Software Services 12
  • 13. ļ‚— Creating a table with a specified engine ļƒ¼ CREATE TABLE t1 (...) ENGINE=InnoDB; ā€¢ Changing existing tables ļƒ¼ ALTER TABLE t1 ENGINE=MyISAM; ā€¢ Finding all your available engines ļƒ¼ SHOW STORAGE ENGINES; Salaria Software Services 13
  • 14. Basic foundation of performance ā€¢ Normalization ā€¢ Data Types ļƒ¼ Smaller, smaller, smaller - Smaller tables use less disk, less memory, can give better performance ā€¢ Indexing ļƒ¼ Speeds up retrieval Salaria Software Services 14
  • 15. ļ‚— Eliminate redundant data: ļƒ¼ Don't store the same data in more than one table ļƒ¼ Only store related data in a table ļƒ¼ reduces database size and errors Salaria Software Services 15
  • 16. ļ‚— updates are usually faster. ļƒ¼ there's less data to change. ā€¢ tables are usually smaller, use less memory, which can give better performance. ā€¢ better performance for distinct or group by queries Salaria Software Services 16
  • 17. ļ‚— However Normalized database causes joins for queries ā€¢ excessively normalized database: ļƒ¼ queries take more time to complete, as data has to be retrieved from more tables. ā€¢ Normalized better for writes OLTP ā€¢ De-normalized better for reads , reporting ā€¢ Real World Mixture: ļƒ¼ normalized schema ļƒ¼ Cache selected columns in memory table Salaria Software Services 17
  • 18. Smaller => less disk => less memory => better performance ļ‚— Use the smallest data type possible ā€¢ The smaller your data types, The more index (and data) can fit into a block of memory, the faster your queries will be. ļƒ¼ Period. ļƒ¼ Especially for indexed fields Salaria Software Services 18
  • 19. ļ‚— MySQL has 9 numeric data types ļƒ¼ Compared to Oracle's 1 ā€¢ Integer: ļƒ¼ TINYINT , SMALLINT, MEDIUMINT, INT, BIGINT ļƒ¼ Require 8, 16, 24, 32, and 64 bits of space. ā€¢ Use UNSIGNED when you don't need negative numbers ā€“ one more level of data integrity ā€¢ BIGINT is not needed for AUTO_INCREMENT ļƒ¼ INT UNSIGNED stores 4.3 billion values! ļƒ¼ Summation of values... yes, use BIGINT ļ‚— Floating Point: FLOAT, DOUBLE ļƒ¼ Approximate calculations ā€¢ Fixed Point: DECIMAL ļƒ¼ Always use DECIMAL for monetary/currency fields, never use FLOAT or DOUBLE! ā€¢ Other: BIT ļƒ¼ Store 0,1 values Salaria Software Services 19
  • 20. ļ‚— VARCHAR(n) variable length ļƒ¼ uses only space it needs ā€“ Can save disk space = better performance ļƒ¼ Use : ā€“ Max column length > avg ā€“ when updates rare (updates fragment) ā€¢ CHAR(n) fixed length ļƒ¼ Use: ā€“ short strings, Mostly same length, or changed frequently Salaria Software Services 20
  • 21. ļ‚— Always define columns as NOT NULL ā€“ unless there is a good reason not to ļƒ¼ Can save a byte per column ļƒ¼ nullable columns make indexes, index statistics, and value comparisons more complicated. ā€¢ Use the same data types for columns that will be compared in JOINs ļƒ¼ Otherwise converted for comparison ā€¢ Use BLOBs very sparingly ļƒ¼ Use the filesystem for what it was intended Salaria Software Services 21
  • 22. ā€œThe more records you can fit into a single page of memory/disk, the faster your seeks and scans will be.ā€ ā€¢ Use appropriate data types ā€¢ Keep primary keys small ā€¢ Use TEXT sparingly ļƒ¼ Consider separate tables ā€¢ Use BLOBs very sparingly ļƒ¼ Use the filesystem for what it was intended Salaria Software Services 22
  • 23. ļ‚— Indexes Speed up Queries, ļƒ¼ SELECT...WHERE name = 'carol' ļƒ¼ only if there is good selectivity: ā€“ % of distinct values in a column ā€¢ But... each index will slow down INSERT, UPDATE, and DELETE operations Salaria Software Services 23
  • 24. ļ‚— Always have an index on join conditions ā€¢ Look to add indexes on columns used in WHERE and GROUP BY expressions ā€¢ PRIMARY KEY, UNIQUE , and Foreign key Constraint columns are automatically indexed. ļƒ¼ other columns can be indexed (CREATE INDEX..) Salaria Software Services 24
  • 25. ļ‚— use the MySQL slow query log and use Explain ā€¢ Append EXPLAIN to your SELECT statement ļƒ¼ shows how the MySQL optimizer has chosen to execute the query ā€¢ You Want to make your queries access less data: ļƒ¼ are queries accessing too many rows or columns? ā€“ select only the columns that you need ā€¢ Use to see where you should add indexes ļƒ¼ Consider adding an index for slow queries or cause a lot of load. ā€“ ensures that missing indexes are picked up early in the development process Salaria Software Services 25
  • 26. ļ‚— Find and fix problem SQL: ā€¢ how long a query took ā€¢ how the optimizer handled it ļƒ¼ Drill downs, results of EXPLAIN statements ā€¢ Historical and real-time analysis ļƒ¼ query execution counts, run time ā€œIts not just slow running queries that are a problem, Sometimes its SQL that executes a lot that kills your systemā€ Salaria Software Services 26
  • 27. ļ‚— Just append EXPLAIN to your SELECT statement ā€¢ Provides the execution plan chosen by the MySQL optimizer for a specific SELECT statement ļƒ¼ Shows how the MySQL optimizer executes the query ā€¢ Use to see where you should add indexes ļƒ¼ ensures that missing indexes are picked up early in the development process Salaria Software Services 27
  • 28. ļ‚— A character set is a set of symbols and encodings. ļ‚— A collation is a set of rules for comparing characters in a character set. ļ‚— MySQL can do these things for you: ļƒ¼ Store strings using a variety of character sets ļƒ¼ Compare strings using a variety of collations ļƒ¼ Mix strings with different character sets or collations in the same server, the same database, or even the same table ļƒ¼ Allow specification of character set and collation at any level - Mysql > SET NAMES 'utf8'; - Mysql > SHOW CHARACTER SET Salaria Software Services 28
  • 29. ļ‚— Two different character sets cannot have the same collation. ļ‚— Each character set has one collation that is the default collation. For example, the default collation for latin1 is latin1_swedish_ci. The output for ā€œSHOW CHARACTER SETā€ indicates which collation is the default for each displayed character set. ļ‚— There is a convention for collation names: They start with the name of the character set with which they are associated, they usually include a language name, and they end with _ci (case insensitive), _cs (case sensitive), or _bin (binary). Salaria Software Services 29
  • 30. ļ‚— <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> ļ‚— <?php mysql_query('SET NAMES utf8'); ?> ļ‚— CREATE DATABASE mydatabase DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; ļ‚— CREATE TABLE mytable ( mydata VARCHAR(128) NOT NULL ) ENGINE=MyISAM DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; Salaria Software Services 30
  • 31. ļ‚— MySQL Forge and the Forge Wiki http://forge.mysql.com/ ļ‚— Planet MySQL http://planetmysql.org/ ļ‚— MySQL DevZone http://dev.mysql.com/ ļ‚— High Performance MySQL book Salaria Software Services 31
  • 33. Mahesh Salaria mahesh@salaria.net Salaria Software Services http://salariasoft.com Salaria Software Services 33