Index and ORM framework

day44

review

1. What is the index ????

Search guide is a special data structure (B + tree)

2. Why do you need an index:

In order to speed up the search,

Principle: to reduce the number of IO by narrow your search

3. Impact of the index brings

Slower writing speed, if modified each modification will lead to rebuild the index field indexing structure

Disk usage is high

Not be able to accelerate, depends on the correct use of the sql index

4. How to use the correct reference to yesterday's summary

1. Try using a small footprint field as an index, a single table field not too much, not to store large tables of data, video, audio

2.and statement contains at least a field with index

3. Avoid using or statement, in order to speed up queries with words only if all the fields have indexes

4. Do not make the left operand arithmetic operation, to ensure that the righthand side is a fixed value

5. fuzzy query, not in front of the percent sign

6. Create a joint index, the most distinguished high on the left low of the right to put the query statement must contain an index field leftmost

7. It should be based on an index of high distinction field

8. try to ensure that the query is covered in the field, which field do not need a field which he sent another inquiry

 

Query plan can clearly show mysql operation to be performed, you can check out the sentence unreasonable place,

Slow query optimization, you can set a maximum execution time, if a statement execution time exceeds this maximum, this will automatically record a statement

 

 

 

 

 

ORM framework

ORM object-relational mapping, refers to the relationship between objects and databases

Why do Mapping? Sql statement written to avoid duplication

ORM can help us generate sql statements, execution, and get the results, in turn objects

object -> databases -> object

 

Hand line and ORM framework

The reason for writing is to achieve a better understanding of the principles of the box

We automatically generate those sql statement?

Create table statement

CRUD

 

Correspondence between the project data in the database

A project corresponds to a database

A class corresponding to a table

An object record

A field corresponding to an attribute

 

We want to achieve the purpose of:

When creating a class in a project automatically generates the table according to the type of information

Metaclasses to control the process of creating the class,

 

When we create an object and automatically generates a record based on the information of the object when you save

 

Object storage method to increase

When we want to modify the properties of a particular object, automatically generate a modified statement

Object provides a method to update

When you want to delete, delete the automatically generated record statement

Object provides a method to delete

When we need to get a certain type of data, automatically generating queries, and query results into objects

It provides a method for obtaining various types of objects

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/zrx19960128/p/11226180.html