[Reserved] MySQL database interview questions

 First, for the relational database index is a very important concept, please answer a few questions about indexes:

a), what is the purpose of the index?
  1. Specific information quickly access data in the table to improve the retrieval speed

  2. Create a unique index to ensure the uniqueness of each row of data in a database table.

  3. The connection between tables and table acceleration

  4. When using packet data retrieval and sorting clause, can significantly reduce the query time grouping and ordering 

b), any negative impact on the index is a database system?

Negative effects:
create indexes and index maintenance takes time, this time with the increase in the amount of data increases; the index needs to take up physical space, not just the data tables need to occupy space, each index also need to take up physical space; when the table add, delete, change, when the index should be dynamic maintenance, thus reducing the speed of data maintenance.

c), the principle of indexing the data table what?
  1. In the index on the field to narrow your search of the most frequently used.

  2. In the index, the need to sort frequently used fields

d), under what circumstances should not be indexed?
  1. For the columns in the query rarely involved in repeat or more of the value of the column, not indexed.

  2. For some special data types, not indexed, such as a text field (text) and so on.

Second, the differences outlined in MyISAM and InnoDB MySQL database

The most important features distinguish it from other databases is its plug-in table storage engine. Remember: storage engine is based on the table, not the database.

InnoDB and MyISAM difference:

InnoDB storage engine: Application (Online Transaction Processing, online transaction processing) OLTP-oriented aspects of the main, is the first full support for ACID transaction storage engine (BDB first transactional storage engine has stopped development).

Features:

  • Row lock design, support for foreign keys;

  • Oracle supports the consistency of style similar to the non-locking read (ie: read operation does not generate default lock);

  • InnoDB the table data in a logical space, InnoDB managed by itself. From MySQL4.1 version, each InnoDB storage engine can be stored separately in Table ibd to a separate file;

  • InnoDB by using MVCC (multi-version concurrency control: do not block read write, write and will not clog read) to achieve high concurrency, and achieve the four kinds of standard SQL isolation level (the default is REPEATABLE level);

  • InnoDB also provides a cushioning insert (insert buffer), the secondary write (double write), adaptive hash index (adaptive hash index), pre-read (read ahead) and the availability of high-performance functions;

  • InnoDB using data aggregation (clustered) way to store the table, each subject is stored are sequentially primary key storage (if not explicitly specify the primary key in the construction table, InnoDB will generate a 6-byte for each row ROWID, and as the primary key);

  • InnoDB tables have three hidden fields: In addition to 6-byte DB_ROW_ID mentioned above, there are 6 bytes DB_TX_ID (transaction ID), and 7 bytes DB_ROLL_PTR (address pointing to the corresponding rollback). This can be seen by innodb monitor;

MyISAM storage engine:  is the official MySQL storage engine, the main application for OLAP (Online Analytical Processing, online analytical processing) area.

Features:

  • It does not support transactions, to support table and full-text indexing. Operation speed;

  • MYD MyISAM storage engine tables and a composition MYI, MYD for storing data files, index files used to store MYI. MySQL database cache only its index files, cache data file to the operating system itself to complete;
    MySQL5.0 version began, MyISAM default 256T supports single-table data;

Third, the external connection MySQL explained, the difference between self-connected connector

Let me talk about what is the cross-connect:  cross-connect also known as Cartesian product, it means without any conditions, directly to all records and all records of a table to another table in eleven matches.

En  is the only cross-connect conditions, screened matching records based on some conditions do not meet the conditions of the record does not appear in the result set, that is, the connecting line only connects the match.

An outer connector  which is not only the result set of lines that meet the connection conditions, but also includes all data rows from the left table, right table or two tables,

Three cases are sequentially called left outer join, right outer join, and full outer join.

Left outer join, also known as left connection, left the table the primary table, all records will be left of the table appear in the result set, for those records in the right table does not match, still have to show that those field values ​​corresponding to the right NULL to fill.

Right outer join, also known as the right connection, the right table the primary table, all records in the right table in the result set. Left and right connections are interchangeable, MySQL currently does not support full outer joins.

Guess you like

Origin www.cnblogs.com/smallwangmusk/p/11355323.html