Answer the question
In order to leave comments, you need to log in
How to create MySQL indexes in Laravel?
Hello!
I create a table of tags
public function up()
{
Schema::create('tags', function (Blueprint $table) {
$table->increments('tag_id');
$table->integer('c_id');
$table->string('tag_name');
$table->text('tag_description')->nullable();
$table->string('tag_color')->default('#ffffff');
$table->index(['c_id', 'tag_id']);
});
}
EXPLAIN SELECT * FROM tags WHERE c_id=1
Answer the question
In order to leave comments, you need to log in
if you need to have data sorted by c_id specify in the selection `order by c_id`
the presence of indexes in itself does not determine the sort order in the selection.
data is entered and stored without any sorting. if you write without deletions, then the data will lie in the natural order of writing, if with deletions, no one knows what will happen here
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question