实际上我有这张表:
ClassBookHistoric
-----------------
Id (Primary Key),
Class_Id (Unique key, foreign key of table Class),
BookUnit_Id (Unique key, foreign key of table BookUnits)
Book_Id
Status
我需要进行查询来搜索如下数据:SELECT WHERE Class_Id =(参数)、Book_Id =(参数)和 Status = 1(事件)
我正在研究索引,我认为有必要使用我将用于搜索数据的列(Class_Id、Book_Id 和 Status
)创建索引,以提高性能。有一种方法可以为一组列创建索引:(Class_Id、Book_Id、Status
)?如果可能的话,我如何在node.js/adonis中创建一组索引?
最佳答案
Adonis.js 使用 knex.js
来定义列类型和其他修饰符,如 docs 中所示。 。
因此,作为基于您的架构的示例(仅用于演示而不能完全工作):
'use strict'
const Schema = use('Schema')
class ClassBookHistoric extends Schema {
up () {
this.create('class_books', (table) => {
table.increments()
table.integer('class_id').notNullable().unique()
table.integer('book_unit_Id').notNullable().unique()
table.index(['class_id','book_unit_Id'], 'class_book_index');
table.timestamps()
})
}
down () {
this.drop('class_books')
}
}
module.exports = UsersSchema
关于node.js - 我如何在node.js (adonis) 中定义表的索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58542243/