Views, Transactions, Indexes

--view

  • In layman's terms, a view is the result set returned after a SELECT statement is executed.
  • So when we create a view, the main work falls on creating this SQL query statement.

-- Features of the view

  • A view is a reference to several basic tables, a virtual table, the result of query execution,
  • No specific data is stored (if the basic table data changes, the view will also change);

-- The main role of the view

  • If the database has changed due to demand and other reasons, in order to ensure that the queried data is the same as before,
  • It needs to be modified in multiple places, which is very troublesome to maintain. At this time, using views can solve this problem.

--Notice

  • Views can only be searched--Summary of the role of views

  • 1 Improves reusability, like a function

  • 2 Refactoring the database without affecting the operation of the already written program

  • 3 Improve the security performance, can be used for different users

  • 4 Make the data clearer

-- The main problem solved by the view

  • The program operates on the database. Once the database changes, the program needs to be modified. At this time, if the view is used, this problem can be solved.

-- Transaction (ACID)

atomicity

A transaction must be regarded as an indivisible minimum unit of work. All operations in the entire transaction are either submitted successfully or all failed and rolled back. For a transaction, it is impossible to perform only a part of the operations, which is the transaction atomicity

consistency

The database always transitions from one consistent state to another consistent state. (In the previous example, consistency ensures that even if the system crashes between the execution of the third and fourth statements, there is no loss of $200 in the checking account, because the transaction does not end up committing, so the modifications made in the transaction are not will not be saved to the database.)

isolation

In general, changes made by one transaction are not visible to other transactions until they are finally committed. (In the previous example, when the third statement is executed and the fourth statement has not yet started, another account summary program starts to run, and it sees that the balance of the checking account has not been subtracted by 200. Dollar.)

Durability

Once a transaction commits, its modifications are permanently saved to the database. (At this point, even if the system crashes, the modified data will not be lost.)

-- Notice

  • innodb can use things

  • When using python to operate the database, things are enabled by default

  • However, when python adds, deletes and changes the database, it needs to commit manually.

  • 使用终端操作数据库(也就是mysql的客户端)的时候 也是默认开始事物的

  • 只是在回车确认操作的时候 终端会默认的commit 所以我们不需要commit

  • 事物最主要解决的问题

  • 某些事情需要一次性完成 中途不允许出现中断 例如银行取钱 事物可以解决这种问题

-- 索引

  • 注意
  • 要注意的是,建立太多的索引将会影响更新和插入的速度,因为它需要同样更新每个索引文件。
  • 对于一个经常需要更新和插入的表格,就没有必要为一个很少使用的where字句单独建立索引了,
  • 对于比较小的表,排序的开销不会很大,也没有必要建立另外的索引。
  • 建立索引会占用磁盘空间

-- 索引最主要解决的问题

  • 当数据非常庞大时,并且这些数据不需要经常修改,为了加快查询速度,我们会使用索引

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325473609&siteId=291194637