目次
まずはストア一覧ページを書く
ホームページ PHPフレームワーク Laravel Laravelのモデル関連付けプリロードの詳しい説明

Laravelのモデル関連付けプリロードの詳しい説明

Apr 08, 2021 pm 04:10 PM
laravel

以下は、laravel のチュートリアルコラムで、Laravel のモデル関連付けプリロードを紹介するものです。

Laravelのモデル関連付けプリロードの詳しい説明

Laravel Learning Notes Model Association Preloading

説明: この記事では主に Laravel Eloquent の遅延プリロード (Eager Loading) について説明します。 、遅延プリロードを使用して MySQL クエリの数を減らします。同時に、作成者は開発プロセス中にいくつかのスクリーンショットとコードを貼り付けて、読み取り効率を向上させます。

注: 現在、4 つのテーブルがあります: マーチャント テーブル マーチャント、マーチャント電話 テーブル電話、マーチャント所有ショップ ショップ テーブル、およびショップ テーブル製品の製品。

[
    'merchants_phones' => 'one-to-one',
    'merchants_shops'  => 'one-to-many',
    'shops_products'   => 'one-to-many',
]
ログイン後にコピー

各店舗を一覧表示するページを作成する必要があります 各店舗ブロックには、タイトルなどの店舗情報、名前や電話番号などの店舗加盟店情報、所有する店舗情報が含まれます紹介や価格などの製品情報。プリロードの有無でどのような違いが生じるかを確認してください。

開発環境:Laravel5.1 MAMP PHP7 MySQL5.5

まずはストア一覧ページを書く

1. 開発を最初にインストールする 3 -ピース プラグイン セット (詳細については、「Laravel Learning Notes: SeederFilling Data Tips」を参照してください)
何はともあれ、最初に 3 ピースの開発プラグイン セットをインストールしてください:

composer require barryvdh/laravel-debugbar --dev
composer require barryvdh/laravel-ide-helper --dev
composer require mpociot/laravel-test-factory-helper --dev

//config/app.php
/**
 *Develop Plugin
 */        
Barryvdh\Debugbar\ServiceProvider::class,
Mpociot\LaravelTestFactoryHelper\TestFactoryHelperServiceProvider::class,
Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class,
ログイン後にコピー

2. テーブル フィールド、テーブルの関連付け、およびテスト データ フィラー Seeder
を記述し、順番に命令を入力します:

php artisan make:model Merchant -m
php artisan make:model Phone -m
php artisan make:model Shop -m
php artisan make:model Product -m
ログイン後にコピー

テーブル フィールドとテーブルの関連付けを記述します:

class CreateMerchantsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('merchants', function (Blueprint $table) {
            $table->increments('id');
            $table->string('username')->unique();
            $table->string('email')->unique();
            $table->string('first_name');
            $table->string('last_name');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('merchants');
    }
}

class CreatePhonesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('phones', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('number')->unsigned();
            $table->integer('merchant_id')->unsigned();
            $table->timestamps();
            $table->foreign('merchant_id')
                ->references('id')
                ->on('merchants')
                ->onUpdate('cascade')
                ->onDelete('cascade');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('phones', function($table){
            $table->dropForeign('merchant_id'); // Drop foreign key 'user_id' from 'posts' table
        });
        Schema::drop('phones');
    }
}

class CreateShopsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('shops', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->string('slug')->unique();
            $table->string('site');
            $table->integer('merchant_id')->unsigned();
            $table->timestamps();
            $table->foreign('merchant_id')
                ->references('id')
                ->on('merchants')
                ->onUpdate('cascade')
                ->onDelete('cascade');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('shops', function($table){
            $table->dropForeign('merchant_id'); // Drop foreign key 'user_id' from 'posts' table
        });
        Schema::drop('shops');
    }
}

class CreateProductsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('products', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->text('short_desc');
            $table->text('long_desc');
            $table->double('price');
            $table->integer('shop_id')->unsigned();
            $table->timestamps();
            $table->foreign('shop_id')
                ->references('id')
                ->on('shops')
                ->onUpdate('cascade')
                ->onDelete('cascade');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('products', function($table){
            $table->dropForeign('shop_id'); // Drop foreign key 'user_id' from 'posts' table
        });
        Schema::drop('products');
    }
}

/**
 * App\Merchant
 *
 * @property integer $id
 * @property string $username
 * @property string $email
 * @property string $first_name
 * @property string $last_name
 * @property \Carbon\Carbon $created_at
 * @property \Carbon\Carbon $updated_at
 * @property-read \App\Phone $phone
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Shop[] $shops
 * @method static \Illuminate\Database\Query\Builder|\App\Merchant whereId($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Merchant whereUsername($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Merchant whereEmail($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Merchant whereFirstName($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Merchant whereLastName($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Merchant whereCreatedAt($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Merchant whereUpdatedAt($value)
 * @mixin \Eloquent
 */
class Merchant extends Model
{
    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function phone()
    {
        return $this->hasOne(Phone::class, 'merchant_id');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function shops()
    {
        return $this->hasMany(Shop::class, 'merchant_id');
    }
}

/**
 * App\Phone
 *
 * @property integer $id
 * @property integer $number
 * @property integer $merchant_id
 * @property \Carbon\Carbon $created_at
 * @property \Carbon\Carbon $updated_at
 * @property-read \App\Merchant $merchant
 * @method static \Illuminate\Database\Query\Builder|\App\Phone whereId($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Phone whereNumber($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Phone whereMerchantId($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Phone whereCreatedAt($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Phone whereUpdatedAt($value)
 * @mixin \Eloquent
 */
class Phone extends Model
{
    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function merchant()
    {
        return $this->belongsTo(Merchant::class, 'merchant_id');
    }
}

/**
 * App\Product
 *
 * @property integer $id
 * @property string $name
 * @property string $short_desc
 * @property string $long_desc
 * @property float $price
 * @property integer $shop_id
 * @property \Carbon\Carbon $created_at
 * @property \Carbon\Carbon $updated_at
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Shop[] $shop
 * @method static \Illuminate\Database\Query\Builder|\App\Product whereId($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Product whereName($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Product whereShortDesc($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Product whereLongDesc($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Product wherePrice($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Product whereShopId($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Product whereCreatedAt($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Product whereUpdatedAt($value)
 * @mixin \Eloquent
 */
class Product extends Model
{
    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function shop()
    {
        return $this->belongsTo(Shop::class, 'shop_id');
    }
}

/**
 * App\Shop
 *
 * @property integer $id
 * @property string $name
 * @property string $slug
 * @property string $site
 * @property integer $merchant_id
 * @property \Carbon\Carbon $created_at
 * @property \Carbon\Carbon $updated_at
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Merchant[] $merchant
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Product[] $products
 * @method static \Illuminate\Database\Query\Builder|\App\Shop whereId($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Shop whereName($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Shop whereSlug($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Shop whereSite($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Shop whereMerchantId($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Shop whereCreatedAt($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Shop whereUpdatedAt($value)
 * @mixin \Eloquent
 */
class Shop extends Model
{
    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function merchant()
    {
        return $this->belongsTo(Merchant::class, 'merchant_id');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function products()
    {
        return $this->hasMany(Product::class, 'shop_id');
    }
}
ログイン後にコピー

忘れないでください 3 つの入力命令セットを開発するには:

php artisan ide-helper:generate
php artisan ide-helper:models
php artisan test-factory-helper:generate
ログイン後にコピー

テーブル間の関係は次の図に示すとおりです:

Laravelのモデル関連付けプリロードの詳しい説明

次に、Seeder を作成します。Laravel の学習ノートを参照してください。Seeder にデータを入力するためのヒント:

php artisan make:seeder MerchantTableSeeder
php artisan make:seeder PhoneTableSeeder
php artisan make:seeder ShopTableSeeder
php artisan make:seeder ProductTableSeeder
class MerchantTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $faker = Faker\Factory::create();
        $datas = [];
        foreach (range(1, 20) as $key => $value) {
            $datas[] = [
                'username'   =>  $faker->userName ,
                'email'      =>  $faker->safeEmail ,
                'first_name' =>  $faker->firstName ,
                'last_name'  =>  $faker->lastName ,
                'created_at' => \Carbon\Carbon::now()->toDateTimeString(),
                'updated_at' => \Carbon\Carbon::now()->toDateTimeString()
            ];
        }

        DB::table('merchants')->insert($datas);
    }
}

class PhoneTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $faker        = Faker\Factory::create();
        $merchant_ids = \App\Merchant::lists('id')->toArray();
        $datas        = [];
        foreach (range(1, 20) as $key => $value) {
            $datas[]  = [
                'number'      => $faker->randomNumber() ,
                'merchant_id' => $faker->randomElement($merchant_ids) ,
                'created_at'  => \Carbon\Carbon::now()->toDateTimeString(),
                'updated_at'  => \Carbon\Carbon::now()->toDateTimeString()
            ];
        }

        DB::table('phones')->insert($datas);
    }
}

class ShopTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $faker        = Faker\Factory::create();
        $merchant_ids = \App\Merchant::lists('id')->toArray();
        $datas        = [];
        foreach (range(1, 40) as $key => $value) {
            $datas[]  = [
                'name'         =>  $faker->name ,
                'slug'         =>  $faker->slug ,
                'site'         =>  $faker->word ,
                'merchant_id'  =>  $faker->randomElement($merchant_ids) ,
                'created_at'   => \Carbon\Carbon::now()->toDateTimeString(),
                'updated_at'   => \Carbon\Carbon::now()->toDateTimeString()
            ];
        }

        DB::table('shops')->insert($datas);
    }
}

class ProductTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $faker    = Faker\Factory::create();
        $shop_ids = \App\Shop::lists('id')->toArray();
        $datas    = [];
        foreach (range(1, 30) as $key => $value) {
            $datas[] = [
                'name'              =>  $faker->name ,
                'short_desc'        =>  $faker->text ,
                'long_desc'         =>  $faker->text ,
                'price'             =>  $faker->randomFloat() ,
                'shop_id'           =>  $faker->randomElement($shop_ids) ,
                'created_at'        =>  \Carbon\Carbon::now()->toDateTimeString() ,
                'updated_at'        =>  \Carbon\Carbon::now()->toDateTimeString()
            ];
        }

        DB::table('products')->insert($datas);
    }
}

php artisan db:seed
ログイン後にコピー

3. 単純な View ビューを作成します
(1) リポジトリ パターンを使用してコードを整理します##

//app/Repository
namespace App\Repository;
interface ShopRepositoryInterface
{
    public function all();
}
//app/Repository/Eloquent
namespace App\Repository\Eloquent;

use App\Repository\ShopRepositoryInterface;
use App\Shop;

class ShopRepository implements ShopRepositoryInterface
{
    /**
     * @var Shop
     */
    public $shop;
    public function __construct(Shop $shop)
    {
        $this->shop = $shop;
    }

    public function all()
    {
        // TODO: Implement all() method.
        $shops = $this->shop->all();
        return $shops;
    }
}
//app/provider/ShopRepositoryServiceProvider
//php artisan make:provider ShopRepositoryServiceProvider
/**
     * Register the application services.
     *
     * @return void
     */
    public function register()
    {
        $this->app->bind(ShopRepositoryInterface::class, ShopRepository::class);
    }
    
//app/Http/Controllers/ShopController.php
class ShopController extends Controller
{
    /**
     * @var ShopRepositoryInterface
     */
    public $shop;

    /**
     * ShopController constructor.
     * @param ShopRepositoryInterface $shopRepositoryInterface
     */
    public function __construct(ShopRepositoryInterface $shopRepositoryInterface)
    {
        $this->shop = $shopRepositoryInterface;
    }

    public function all()
    {
        $shops = $this->shop->all();
        return view('shop.index', compact('shops'));
    }
}

//视图
//resources/views/shop/layout.blade.php


    <meta>
    <meta>
    <meta>
    <!-- 上述3个meta标签*必须*放在最前面,任何其他内容都*必须*跟随其后! -->
    <title>Bootstrap Template</title>
    <!-- 新 Bootstrap 核心 CSS 文件 -->
    <link>
    <style>
        html,body{
            width: 100%;
            height: 100%;
        }
        *{
            margin: 0;
            border: 0;
        }
    </style>


<p>
    </p><p>
        </p><p>

            @yield('content')

        </p>
    


<!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
<script></script>
<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script></script>
<script>

</script>



//resources/views/shop/index.blade.php
@extends('shop.layout')

@section('content')
    
ログイン後にコピー
            @foreach($shops as $shop)             
  •                 

    Store:{{$shop->name}}

                    Member:{{$shop->merchant->first_name.' '.$shop->merchant->last_name}}                 {{--这里数组取电话号码--}}                 Phone:{{$shop->merchant->phone['number']}}                 
                          @foreach($shop->products as $product)                         
    •                             

      Name:{{$product->name}}

                                  

      Desc:{{$product->short_desc}}

                                  

      Price:{{$product->price}}

      {{--                            {!! Debugbar::info('products:'.$product->id) !!}--}}                         
    •                     @endforeach                 
                
  •         @endforeach     
@endsection //路由 Route::get('/eagerload', 'ShopController@all');

(2) デバッグバー プログラム実行データを表示
Laravelのモデル関連付けプリロードの詳しい説明 #121 個のクエリが実行され、38.89 ミリ秒かかり、効率が非常に低いことがわかります。各クエリを注意深く観察してください。1 つのステートメントでは、これが最初にショップ テーブルをスキャンし、次に、商品テーブルの検索も同様で、クエリが多く、N 1 検索の問題です。

クエリのプリロード

(1) ネストされたプリロード

Eloquent は、属性を通じて関連データにアクセスする場合、遅延読み込み
になります。関連データは、プロパティを通じてアクセスするときにロードされます。上位層モデルを検索するときに関連データをプリロードすることで、N 1 問題を回避できます。 また、プリロードの使用は非常に簡単です。 変更する必要があるのは 1 行だけです:

//app/Repository/Eloquent/ShopRepository
    public function all()
    {
        // TODO: Implement all() method.
//        $shops = $this->shop->all();
        //通过`点`语法嵌套预加载,多种关联就写对应的关联方法
        //Shop这个Model里关联方法是Merchant()和Products(),Merchant Model里关联方法是Phone()
        $shops = $this->shop->with(['merchant.phone', 'products'])->get();
        return $shops;
    }
ログイン後にコピー

他のコードを変更する必要はありません。デバッグバーのクエリを確認してください:


Laravelのモデル関連付けプリロードの詳しい説明# #動作しています! !!

見つかった: クエリは 4 つだけで、所要時間は 3.58 ミリ秒で、効率が大幅に向上しました。元の N 1 クエリは where..in..

クエリに変換され、効率が大幅に向上しました。 EXPLAIN を使用すると、SQL ステートメントの実行計画を表示できます。

(2) プリロードの条件制限

製品の事前並べ替えなど、プリロードに条件付き制限を課すこともできます。コードの変更は簡単です。 <div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">//app/Repository/Eloquent/ShopRepository public function all()     {         // TODO: Implement all() method. //        $shops = $this-&gt;shop-&gt;all(); //        $shops = $this-&gt;shop-&gt;with(['merchant.phone', 'products'])-&gt;get();         $shops = $this-&gt;shop-&gt;with(['members.phone', 'products'=&gt;function($query){ //            $query-&gt;orderBy('price', 'desc');             $query-&gt;orderBy('price', 'asc');         }])-&gt;get();         return $shops;     }</pre><div class="contentsignin">ログイン後にコピー</div></div>制限条件を追加することは、商品のプリロード時に SQL ステートメントにソートを追加することと同等です。もうスクリーンショットは必要ありません。

要約: 関連モデルのプリロードは確かに興味深い機能であり、効率が大幅に向上します。最近ランダムに調べているんですが、何か面白いことがあったらシェアしますね。

以上がLaravelのモデル関連付けプリロードの詳しい説明の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

Video Face Swap

Video Face Swap

完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

ホットツール

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

SublimeText3 中国語版

SublimeText3 中国語版

中国語版、とても使いやすい

ゼンドスタジオ 13.0.1

ゼンドスタジオ 13.0.1

強力な PHP 統合開発環境

ドリームウィーバー CS6

ドリームウィーバー CS6

ビジュアル Web 開発ツール

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)

Laravelで電子メールの送信が失敗したときに返品コードを取得する方法は? Laravelで電子メールの送信が失敗したときに返品コードを取得する方法は? Apr 01, 2025 pm 02:45 PM

Laravelの電子メールの送信が失敗したときに戻りコードを取得する方法。 Laravelを使用してアプリケーションを開発する場合、検証コードを送信する必要がある状況に遭遇することがよくあります。そして実際には...

Laravelスケジュールタスクは実行されません:スケジュール:実行コマンドの後にタスクが実行されていない場合はどうすればよいですか? Laravelスケジュールタスクは実行されません:スケジュール:実行コマンドの後にタスクが実行されていない場合はどうすればよいですか? Mar 31, 2025 pm 11:24 PM

LaravelスケジュールタスクRAN RANSPONSIVEトラブルシューティングRALAVELのスケジュールタスクスケジューリングを使用すると、多くの開発者がこの問題に遭遇します。スケジュール:実行...

Laravelでは、検証コードが電子メールで送信できない状況に対処する方法は? Laravelでは、検証コードが電子メールで送信できない状況に対処する方法は? Mar 31, 2025 pm 11:48 PM

Laravelの電子メールの検証コードの送信の障害を処理する方法は、Laravelを使用することです...

DCAT管理者にデータを追加するためにクリックのカスタムテーブル関数を実装する方法は? DCAT管理者にデータを追加するためにクリックのカスタムテーブル関数を実装する方法は? Apr 01, 2025 am 07:09 AM

DCATを使用するときにDCATADMIN(Laravel-Admin)にデータを追加するためにカスタムクリックのテーブル関数を実装する方法...

Laravel Redis接続共有:選択方法が他の接続に影響するのはなぜですか? Laravel Redis接続共有:選択方法が他の接続に影響するのはなぜですか? Apr 01, 2025 am 07:45 AM

Laravel FrameworkでRedis接続の共有の影響とLaravelフレームワークとRedisを使用する際のメソッドを選択すると、開発者は問題に遭遇する可能性があります。

Laravel Multi-Tenant Extension Stancl/Tenancy:テナントデータベース接続のホストアドレスをカスタマイズする方法は? Laravel Multi-Tenant Extension Stancl/Tenancy:テナントデータベース接続のホストアドレスをカスタマイズする方法は? Apr 01, 2025 am 09:09 AM

Laravel Multi-Tenant拡張機能パッケージStancl/Tenancyのカスタムテナントデータベース接続Laravel Multi-Tenant ExtensionパッケージStancl/Tenancyを使用したマルチテナントアプリケーションを構築する際の...

バングラ部分モデル検索のlaravelEloquent orm) バングラ部分モデル検索のlaravelEloquent orm) Apr 08, 2025 pm 02:06 PM

LaravelEloquentモデルの検索:データベースデータを簡単に取得するEloquentormは、データベースを操作するための簡潔で理解しやすい方法を提供します。この記事では、さまざまな雄弁なモデル検索手法を詳細に紹介して、データベースからのデータを効率的に取得するのに役立ちます。 1.すべてのレコードを取得します。 ALL()メソッドを使用して、データベーステーブルですべてのレコードを取得します:useapp \ models \ post; $ post = post :: all();これにより、コレクションが返されます。 Foreach Loopまたはその他の収集方法を使用してデータにアクセスできます。

Laravelの地理空間:インタラクティブマップと大量のデータの最適化 Laravelの地理空間:インタラクティブマップと大量のデータの最適化 Apr 08, 2025 pm 12:24 PM

700万のレコードを効率的に処理し、地理空間技術を使用したインタラクティブマップを作成します。この記事では、LaravelとMySQLを使用して700万を超えるレコードを効率的に処理し、それらをインタラクティブなマップの視覚化に変換する方法について説明します。最初の課題プロジェクトの要件:MySQLデータベースに700万のレコードを使用して貴重な洞察を抽出します。多くの人は最初に言語をプログラミングすることを検討しますが、データベース自体を無視します。ニーズを満たすことができますか?データ移行または構造調​​整は必要ですか? MySQLはこのような大きなデータ負荷に耐えることができますか?予備分析:キーフィルターとプロパティを特定する必要があります。分析後、ソリューションに関連している属性はわずかであることがわかりました。フィルターの実現可能性を確認し、検索を最適化するためにいくつかの制限を設定しました。都市に基づくマップ検索

See all articles