技術情報

MySQL Storage Engines

Lets talk about the MySQL storage engines today.

A storage engine is a software module that uses a database management system to create, read, and update data in a database. There are two types of storage engines in MySQL: transactional and non-transactional.

For MySQL 5.5 and later, the default storage engine is InnoDB. The default storage engine for MySQL prior to version 5.5 was MyISAM. Choosing the right storage engine is an important strategic decision that will affect future development. In this tutorial, we will use MyISAM, InnoDB, Memory, and CSV storage engines. If you are new to MySQL and are studying the MySQL database management system, then this is not a big concern. If you are planning a production database, things get more complicated.

MySQL supported storage engines:

  • InnoDB
  • MyISAM
  • Memory
  • CSV
  • Merge
  • Archive
  • etc.

Today I will talk about the two main engines of MySQL. InnoDB & MyISAM.

InnoDB

InnoDB tables are fully transaction and ACID compliant. They are also optimal for performance. The InnoDB table supports foreign key, commit, rollback, and forward operations. The size of an InnoDB table can be up to 64TB.

Like MyISAM, InnoDB tables are portable between different platforms and operating systems. MySQL also checks and repairs InnoDB tables, if necessary, at startup.

MyISAM

MyISAM extends the old ISAM storage engine. MyISAM tables are optimized for compression and speed. MyISAM tables are also portable across platforms and operating systems.

The size of the MyISAM table can be up to 256TB, which is huge. Also, MyISAM tables can be compressed into read-only tables to save space. At startup, MySQL checks MyISAM tables for corruption and even repairs them in case of errors. MyISAM tables are not transaction safe.

Before MySQL version 5.5, MyISAM was the default storage engine when you create a table without specifying the storage engine explicitly. Since version 5.5, MySQL uses InnoDB as the default storage engine.

By Yuuma



[Laravel] Passportを使用したBearer token認証[1]

PHPのLaravelフレームワークのPassportを使用したBearer token認証の方法について紹介いたします。今回はPassport実装テスト用のプロジェクトを準備するところまでを説明します。

続きを読む

Singleton Design Pattern

Singleton is one of the creational design pattern that allows you to ensure that a class has only one instance, while providing a global access point to this instance.

Make the single instance object class responsible for creation, initialization, access, and execution. Declare the instance as a member of private static data. Provides a public static member function that encapsulates all initialization code and provides access to the instance.

The client calls the access function (using the class name and the scope resolution operator) whenever a reference to the single instance is required.

The singleton should be considered only if the following three criteria are met:

Single instance ownership cannot reasonably be assigned
Lazy initialization is desirable
Global access is not provided otherwise

Lets take a look at code samples

PHP code sample

<?php

/**
 * Singleton class
 */
class LogSingleton {
    /**
     * I kept this attribute and constructor as private so that other sub class can't instantiate
     * it can also be protected if you want to allow sub classes to be instantiated
     */
    private static $intance = null;

    private function __construct() {
    }

    /**
     * I will assign the singleton instance if $instance is null.
     * otherwise will return directly.
     */
    public static function log() {
      if (self::$intance == null) {
         self::$intance = new LogSingleton();
      }
      return self::$intance;
    }

    //can also declare other public functions below.
    public function debugLog()
    {
      return "debug log";
    }
  }

//client code
$client = LogSingleton::log(); // this is the singleton instance.
var_dump($client->debugLog());

C# sample code

using System;

namespace HelloWorld
{
    class LogSingleton
    {
        /**
         * I kept this attributes as private so that other sub class can't instantiate
         * it can also be protected if you want to allow sub classes to be instantiated
         */
        private static LogSingleton instance;

        /**
         * for the first use for this class, s_lock will have a object.
         * This will later use along with lock function to protect from multi thread base.
         */
        private static readonly object s_lock = new object();

        public static LogSingleton log()
        {
            if (instance == null)
            {
                /**
                 * The client who has s_lock will proceed this condition.
                 */
                lock (s_lock)
                {
                    /**
                     * I will assign the singleton instance if instance is null.
                     * otherwise will return directly.
                     */
                    if (instance == null)
                    {
                        instance = new LogSingleton();
                    }
                }
            }
            return instance;
        }

        //can also declare other public functions below.
        public string debugLog()
        {
            return "debug log";
        }

        //client code
        class Program
        {
            static void Main(string[] args)
            {
                var client = LogSingleton.log(); // this is the singleton instance.
                Console.WriteLine(client.debugLog());

            }
        }
    }

}

By Yuuma



[Laravel] sessionの共有について

過去記事「[Laravel] 設定ファイル「.env」の切り替えについて」にて、URLのパス指定により、複数の「.env」設定ファイルの切り替えをおこなう方法を紹介いたしました。
今回は上記過去記事の補足説明となります。

続きを読む

Abstract Factory Design Pattern

Abstract Factory defines an interface to create all the different products, but leaves the actual creation of the product to specific factory classes. Each type of factory corresponds to a certain variety of product.

The client code calls the methods of creating a factory object instead of creating products directly with a call to the constructor (new operator). Since a factory corresponds to a single product variant, all of its products will be compatible.

The client code works with factories and products only through their abstract interfaces. This allows the client code to work with any product variant, created by the factory object.

C# code sample

using System;

namespace HelloWorld
{
    /**
 * Define the Factory interface first.
 */
    abstract class TvSetFactory
    {
        public abstract Tv createTv();
        public abstract CdPlayer createCdPlayer();
    }

    /**
     * Then I will create related factory classes and implements the interface
     * Panasonic  Factory & SamsaungFactory in this scenario.
     */
    class PanasonicFactory : TvSetFactory
    {
        public override Tv createTv()
        {
            return new PanasonicTv();
        }

        public override CdPlayer createCdPlayer()
        {
            return new PanasonicCdPlayer();
        }
    }

    class SamsaungFactory : TvSetFactory
    {
        public override Tv createTv()
        {
            return new SamsaungTv();
        }

        public override CdPlayer createCdPlayer()
        {
            return new SamsaungCdPlayer();
        }

    }

    /**
     * Now lets build family of object classes.
     * Tv & CdPlayer in this scenario.
     */
    abstract class Tv
    {
        public abstract string getTv();
    }

    /**
     * These classes have to be implemented by their relative factory.
     */
    class PanasonicTv : Tv
    {
        public override string getTv()
        {
            return "PanasonicTv";
        }
    }

    class SamsaungTv : Tv
    {
        public override string getTv()
        {
            return "SamsaungTv";
        }
    }

    abstract class CdPlayer
    {
        public abstract string getCdPlayer();
    }

    class PanasonicCdPlayer : CdPlayer
    {
        public override string getCdPlayer()
        {
            return "PanasonicCdPlayer";
        }
    }

    class SamsaungCdPlayer : CdPlayer
    {
        public override string getCdPlayer()
        {
            return "SamsaungCdPlayer";
        }
    }


    // client code
    /**
     * Now you can call the specific factory to return family of objects without knowing their own detail implementations.
     * if you want to get samsaung products, you just need to change the Factory class to samsaung factory.
     */

    class Program
    {
        static void Main(string[] args)
        {
            var tv = new PanasonicFactory();
            Console.WriteLine(tv.createTv().getTv());

            var cdPlayer = new PanasonicFactory();
            Console.WriteLine(cdPlayer.createCdPlayer().getCdPlayer());

        }
    }

}

PHP code sample

<?php

/**
 * Define the Factory interface first.
 */
abstract class TvSetFactory
{
    abstract function createTv();
    abstract function createCdPlayer();
}

/**
 * Then I will create related factory classes and extends the interface
 * Panasonic  Factory & SamsaungFactory in this scenario.
 */
class PanasonicFactory extends TvSetFactory
{
    public function createTv()
    {
        return new PanasonicTv;
    }

    public function createCdPlayer()
    {
        return new PanasonicCdPlayer();
    }
}

class SamsaungFactory extends TvSetFactory
{
    public function createTv()
    {
        return new SamsaungTv;
    }

    public function createCdPlayer()
    {
        return new SamsaungCdPlayer();
    }

}

/**
 * Now lets build family of object classes.
 * Tv & CdPlayer in this scenario.
 */
abstract class Tv
{
    abstract function getTv();
}

/**
 * These classes have to be implemented by their relative factory.
 */
class PanasonicTv extends Tv
{
    public function getTv()
    {
        return "PanasonicTv";
    }
}

class SamsaungTv extends Tv
{
    public function getTv(): string
    {
        return "SamsaungTv";
    }
}

abstract class CdPlayer
{
    abstract function getCdPlayer();
}

class PanasonicCdPlayer extends CdPlayer
{
    public function getCdPlayer()
    {
        return "PanasonicCdPlayer";
    }
}

class SamsaungCdPlayer extends CdPlayer
{
  public function getCdPlayer()
  {
      return "SamsaungCdPlayer";
  }
}


// client code
function test($tvSetFactory)
{
    $tv = $tvSetFactory->createTv();
    echo('TV model is'.$tv->getTv());

    $cdPlayer = $tvSetFactory->createCdPlayer();
    echo('CD Player model is'.$cdPlayer->getCdPlayer());
}

/**
 * Now you can call the specific factory to return family of objects without knowing their own detail implementations.
 * if you want to get samsaung products, you just need to change the Factory class to samsaung factory.
 */
$tvSetFactory = new PanasonicFactory;
test($tvSetFactory);

By Yuuma




アプリ関連ニュース

お問い合わせはこちら

お問い合わせ・ご相談はお電話、またはお問い合わせフォームよりお受け付けいたしております。

tel. 06-6454-8833(平日 10:00~17:00)

お問い合わせフォーム