Database Miscellaneous

  1. In addition to the primary key column of the database table, when you need to ensure that the data inserted by a single column value or a multi-column combined value is the only parameter, it is best to add 唯一索引it to ensure the uniqueness of the data
  2. Use 联表查询in when used order byto pay attention if the fields are not sorted index, the execution time of this statement will likely time out, can be used as a sort Sort by key or add an index column, etc.
  3. limit 1 Can be used to optimize conditional query results to determine that there is only one SQL, so that when the query finds a data match, it will not continue to execute
  4. 自定义排序Function, order by field(value,str1,str2,str3,str4,strn), where the parameters after value are customized, and the number of parameters is not limited. The meaning is to sort the obtained data according to the order of str1, str2, str3, str4, etc.
  5. When writing sql general fragments in the xml file of mybatis, if the columns to be searched are spliced ​​by fragments, it is best to write them on the same line, otherwise the query may time out.
    E.g:<include refid="baseQueryColumn" />,(不要换行)s.name, s.age, c.grade, cr.item_name
  6. If the loss of 15% of the original jdbc insertion is not achieved, it means that such insertion is inefficient. However, based on the development experience, the system has few batch operations, and a simple method can be used. If you want to use better efficiency, please use jdbc transaction batch operation method, and mybitis transaction batch operation method. Try to use mybitis instead of jdbc. The reason is that mybitits simplifies operations and has little performance impact. After testing, 9G data can be completed in half a time on the server version. It is also within 1 hour locally, but it takes 6-7 hours to use foreach. The reason is that 1. The database needs to be compiled, and a large number of splicing does not use pre-compilation time, 2 .Batch submission 1000-10000 one submission(网上看到,待求证!!!)

Guess you like

Origin blog.csdn.net/weixin_45879810/article/details/112941079