MySQL indexes, views, stored procedures,

First, the concept of index
indexes in the database and directory similar books

  • In a book, without having to read the entire book, you can use the directory to quickly find the information
  • Contents of the book is a list of words, which shows the page number that contains each word of
    database indexes
  • In the database, index the database program without having to scan the entire table, you can find the required data in which
  • The index is a database table or a collection worth several columns, as well as physical identification logic pointer list of these pages worth of data
    indexing advantages: You can quickly find the data
    Disadvantages: take up hard disk resources
    Second, the index role
  • After setting the appropriate index, fast database using a variety of positioning technology, can greatly accelerate the rate of inquiry
  • Especially when large table or query involves multiple tables, queries can use the index to speed up to a thousand times
  • IO read and write the database can reduce the cost, and the index can also reduce the cost of sorting the database
  • The only guarantees data table data by creating a unique index
  • You can speed up the connection between the table and the table
  • When using grouping and sorting, grouping and sorting can greatly reduce the time
    Third, the classification index
    the ordinary index
  • This is the most basic index types, and it does not limit the uniqueness of such
    unique index
  • This index and the previous "general index" is basically the same, but with one difference: all values ​​of the indexed column can only occur once, that must be unique
  • Unique index allowed to be null, but only once empty
    primary key
  • Primary key is a unique index, but it must be designated as the "PRIMARY KEY"
    full-text index
  • MySQL version 3.23.23 from the start to support full-text indexing and full-text search. In MySQL, the full-text index of the index type FULLTEXT, full-text index can be created on columns of type VARCHAR or TEXT
    single index and multi-column index
  • Indexes can be created on a separate index, the index can be created in multiple columns on the
    Fourth, create an index based on the principle of
  • Primary key, foreign key must have an index
  • The amount of data of more than 300 rows of the table should be indexed
  • TABLE often connected to the other tables in the connection field (foreign key) should be indexed
  • Often appear in the Where clause field, especially in the field of large tables should be indexed
  • Index should be built on a highly selective field
  • Index should be built on a small field, even for large text fields long field, not to build index
  • For large text fields and even long field full-text indexed, fulltext
  • Uniqueness field is not too bad for indexing
  • Too frequently updated fields unsuitable for creating an index
    V. index creation method
  • According to business needs, after selecting a suitable index can be used to create an index CREATE INDEX
  • CREATE INDEX plus the index keys can create various types of indexes
    practical operation of the process
    MySQL indexes, views, stored procedures,
    MySQL indexes, views, stored procedures,
    MySQL indexes, views, stored procedures,
    1. Create a plain index
    MySQL indexes, views, stored procedures,
    MySQL indexes, views, stored procedures,
    Delete index
    MySQL indexes, views, stored procedures,
    2. Create a unique index
    MySQL indexes, views, stored procedures,
    to delete the index
    MySQL indexes, views, stored procedures,
    "alter table" to create a unique index
    MySQL indexes, views, stored procedures,
    Another way is when you create a table, on the definition of the index.
    MySQL indexes, views, stored procedures,
    MySQL indexes, views, stored procedures,
    MySQL indexes, views, stored procedures,
    Create a table hobby
    MySQL indexes, views, stored procedures,
    to hobby table to add data
    MySQL indexes, views, stored procedures,
    to two tables associated with
    MySQL indexes, views, stored procedures,
    MySQL indexes, views, stored procedures,
    this is a typical multi-table queries connected to
    avoid redundant code may alias for the table
    MySQL indexes, views, stored procedures,
    view Overview
    is a virtual table, view data does not exist, just real table mapping data. Using screening conditions, grouping, sorting, and so produce a result set, stored in memory, and make persistent storage. (Only save maps)
    view will take up less resources, equivalent to a soft connection, shortcuts
    real data in the table changes, the view will change accordingly ensue.
    create view 视图名称 as 查询语句(select id,name,age) from 表名 where(条件) id=1 or id=5;

    The role of view: according to different users, create different views. Check under the authority of different views; enhance security; sql convenient operation.
    Practical operation
    to create a view
    MySQL indexes, views, stored procedures,
    to see the view
    MySQL indexes, views, stored procedures,
    stored procedure outlined
    stored procedure: stored procedures used for software development direction
    prevent code from being intercepted during network transmission, made security guarantees
    original state: the code needs to be embedded sql statement: by connecting the drive (java is jdbc) ---- the sql statement as a parameter passed to the execution mysql database.
    Stored procedures are written in the database, not the program.
    Program by calling a stored procedure name to trigger operation (function similar to the shell), the
    advantages: the amount of code optimization, reducing the amount of code,
    transmission security, sql statement hidden
    network optimization.

Guess you like

Origin blog.51cto.com/14557905/2465076