-
Notifications
You must be signed in to change notification settings - Fork 595
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(database): add single column indexes for performance optimization
- Add individual indexes for v2_user table (t, online_count, created_at) - Add individual indexes for v2_order table (created_at, status, total_amount, commission fields) - Add individual indexes for v2_stat_server table (server_id, record_at, u, d) - Add individual indexes for v2_stat_user table (u, d) - Add individual indexes for v2_commission_log table (created_at, get_amount) - Add individual indexes for v2_ticket table (status, created_at) This change improves query flexibility and maintainability by using single column indexes instead of composite indexes. Each field can now be queried independently with optimal performance.
- Loading branch information
xboard
committed
Jan 15, 2025
1 parent
01b1141
commit 4cdf5f6
Showing
1 changed file
with
93 additions
and
0 deletions.
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
database/migrations/2025_01_15_000002_add_stat_performance_indexes.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration { | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::table('v2_user', function (Blueprint $table) { | ||
$table->index('t'); | ||
$table->index('online_count'); | ||
$table->index('created_at'); | ||
}); | ||
|
||
Schema::table('v2_order', function (Blueprint $table) { | ||
$table->index('created_at'); | ||
$table->index('status'); | ||
$table->index('total_amount'); | ||
$table->index('commission_status'); | ||
$table->index('invite_user_id'); | ||
$table->index('commission_balance'); | ||
}); | ||
|
||
Schema::table('v2_stat_server', function (Blueprint $table) { | ||
$table->index('server_id'); | ||
$table->index('record_at'); | ||
$table->index('u'); | ||
$table->index('d'); | ||
}); | ||
|
||
Schema::table('v2_stat_user', function (Blueprint $table) { | ||
$table->index('u'); | ||
$table->index('d'); | ||
}); | ||
|
||
Schema::table('v2_commission_log', function (Blueprint $table) { | ||
$table->index('created_at'); | ||
$table->index('get_amount'); | ||
}); | ||
|
||
Schema::table('v2_ticket', function (Blueprint $table) { | ||
$table->index('status'); | ||
$table->index('created_at'); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::table('v2_user', function (Blueprint $table) { | ||
$table->dropIndex(['t']); | ||
$table->dropIndex(['online_count']); | ||
$table->dropIndex(['created_at']); | ||
}); | ||
|
||
Schema::table('v2_order', function (Blueprint $table) { | ||
$table->dropIndex(['created_at']); | ||
$table->dropIndex(['status']); | ||
$table->dropIndex(['total_amount']); | ||
$table->dropIndex(['commission_status']); | ||
$table->dropIndex(['invite_user_id']); | ||
$table->dropIndex(['commission_balance']); | ||
}); | ||
|
||
Schema::table('v2_stat_server', function (Blueprint $table) { | ||
$table->dropIndex(['server_id']); | ||
$table->dropIndex(['record_at']); | ||
$table->dropIndex(['u']); | ||
$table->dropIndex(['d']); | ||
}); | ||
|
||
Schema::table('v2_stat_user', function (Blueprint $table) { | ||
$table->dropIndex(['u']); | ||
$table->dropIndex(['d']); | ||
}); | ||
|
||
Schema::table('v2_commission_log', function (Blueprint $table) { | ||
$table->dropIndex(['created_at']); | ||
$table->dropIndex(['get_amount']); | ||
}); | ||
|
||
Schema::table('v2_ticket', function (Blueprint $table) { | ||
$table->dropIndex(['status']); | ||
$table->dropIndex(['created_at']); | ||
}); | ||
} | ||
}; |