名古屋ではたらくWEB屋のブログ

名古屋を拠点にWEBシステム開発(受託)を行っております!!
お仕事承ります。

PHP,MySQL,EC-CUBE,WordPress


テーマ:

※EC-CUBE 2.4.4の高速化のチューニングも今日で最終回です。(早っ!)

 最新のEC-CUBE 2.11.xでは、60倍速くなっているらしいいので、新規開発では関係ない記事ですが、

 既に、2.4.xで開発されたサイトも山ほどあると思います。

 なので、この記事の賞味期限もしばらく(1年ぐらい?)は有効だと思います。

 ちなみに、2.4.xから2.11.xにバージョンアップするのはかなり大変みたいです。(ほぼ、作り直し) 


※では、本題です。

 今回は、データベースviewによるチューニング。
 PostgreSQLのviewをサブクエリに置き換えている所(これが超重たい)を削除して、そのままMySQL(5.x)のviewを使う様に変更します。


1.viewもどきを修正する。(オーバーライドします)
 /data/class_extends/db_extends/dbfactory/SC_DB_DBFactory_MYSQL_Ex.php

class SC_DB_DBFactory_MYSQL_Ex extends SC_DB_DBFactory_MYSQL {
    function viewToSubQuery() {
        return array(
            "vw_cross_class"              => "vw_cross_class",
            "vw_cross_products_class"     => "vw_cross_products_class",
            "vw_products_nonclass"        => "vw_products_nonclass",
            "vw_products_allclass"        => "vw_products_allclass",
            "vw_products_allclass_detail" => "vw_products_allclass_detail",
            "vw_product_class"            => "vw_product_class",
            "vw_category_count"           => "vw_category_count",
        );
    }
}

2.ビューの追加(MySQL 5.0以上)

-- --------------------------------------------------------
--
-- ビュー用の構造 `vw_T2`
--

CREATE VIEW `vw_T2` AS select `dtb_products_class`.`product_id` AS `product_id_sub`,
`dtb_products_class`.`product_code` AS `product_code`,
`dtb_products_class`.`price01` AS `price01`,
`dtb_products_class`.`price02` AS `price02`,
`dtb_products_class`.`stock` AS `stock`,
`dtb_products_class`.`stock_unlimited` AS `stock_unlimited`,
`dtb_products_class`.`classcategory_id1` AS `classcategory_id1`,
`dtb_products_class`.`classcategory_id2` AS `classcategory_id2` from `dtb_products_class` where ((`dtb_products_class`.`classcategory_id1` = 0) and (`dtb_products_class`.`classcategory_id2` = 0));

-- --------------------------------------------------------

--
-- ビュー用の構造 `vw_T4`
--

CREATE VIEW `vw_T4` AS select `dtb_products_class`.`product_id` AS `product_id`,
min(`dtb_products_class`.`product_code`) AS `product_code_min`,
max(`dtb_products_class`.`product_code`) AS `product_code_max`,
min(`dtb_products_class`.`price01`) AS `price01_min`,
max(`dtb_products_class`.`price01`) AS `price01_max`,
min(`dtb_products_class`.`price02`) AS `price02_min`,
max(`dtb_products_class`.`price02`) AS `price02_max`,
min(`dtb_products_class`.`stock`) AS `stock_min`,
max(`dtb_products_class`.`stock`) AS `stock_max`,
min(`dtb_products_class`.`stock_unlimited`) AS `stock_unlimited_min`,
max(`dtb_products_class`.`stock_unlimited`) AS `stock_unlimited_max`,
count(0) AS `class_count` from `dtb_products_class` group by `dtb_products_class`.`product_id`;

-- --------------------------------------------------------

--
-- ビュー用の構造 `vw_T5`
--

CREATE VIEW `vw_T5` AS select `t1`.`product_class_id` AS `product_class_id`,
`t1`.`product_id` AS `product_id_sub`,
`t1`.`classcategory_id1` AS `classcategory_id1`,
`t1`.`classcategory_id2` AS `classcategory_id2`,
`t2`.`rank` AS `rank1`,
`t4`.`rank` AS `rank2`,
`t2`.`class_id` AS `class_id1`,
`t4`.`class_id` AS `class_id2`,
`t1`.`stock` AS `stock`,
`t1`.`price01` AS `price01`,
`t1`.`price02` AS `price02`,
`t1`.`stock_unlimited` AS `stock_unlimited`,
`t1`.`product_code` AS `product_code` from ((`dtb_products_class` `t1` left join `dtb_classcategory` `t2` on((`t1`.`classcategory_id1` = `t2`.`classcategory_id`))) left join `dtb_classcategory` `t4` on((`t1`.`classcategory_id2` = `t4`.`classcategory_id`)));

-- --------------------------------------------------------

--
-- ビュー用の構造 `vw_category_count`
--

CREATE VIEW `vw_category_count` AS select `t1`.`category_id` AS `category_id`,
`t1`.`category_name` AS `category_name`,
`t1`.`parent_category_id` AS `parent_category_id`,
`t1`.`level` AS `level`,
`t1`.`rank` AS `rank`,
`t2`.`product_count` AS `product_count` from (`dtb_category` `t1` left join `dtb_category_total_count` `t2` on((`t1`.`category_id` = `t2`.`category_id`)));

-- --------------------------------------------------------

--
-- ビュー用の構造 `vw_cross_class`
--

CREATE VIEW `vw_cross_class` AS select `t1`.`class_id` AS `class_id1`,
`t2`.`class_id` AS `class_id2`,
`t1`.`classcategory_id` AS `classcategory_id1`,
`t2`.`classcategory_id` AS `classcategory_id2`,
`t1`.`name` AS `name1`,
`t2`.`name` AS `name2`,
`t1`.`rank` AS `rank1`,
`t2`.`rank` AS `rank2` from (`dtb_classcategory` `t1` join `dtb_classcategory` `t2`);

-- --------------------------------------------------------

--
-- ビュー用の構造 `vw_cross_products_class`
--

CREATE VIEW `vw_cross_products_class` AS select `t1`.`class_id1` AS `class_id1`,
`t1`.`class_id2` AS `class_id2`,
`t1`.`classcategory_id1` AS `classcategory_id1`,
`t1`.`classcategory_id2` AS `classcategory_id2`,
`t2`.`product_id` AS `product_id`,
`t1`.`name1` AS `name1`,
`t1`.`name2` AS `name2`,
`t2`.`product_code` AS `product_code`,
`t2`.`stock` AS `stock`,
`t2`.`price01` AS `price01`,
`t2`.`price02` AS `price02`,
`t1`.`rank1` AS `rank1`,
`t1`.`rank2` AS `rank2` from (`vw_cross_class` `t1` left join `dtb_products_class` `t2` on(((`t1`.`classcategory_id1` = `t2`.`classcategory_id1`) and (`t1`.`classcategory_id2` = `t2`.`classcategory_id2`))));

-- --------------------------------------------------------
--
-- ビュー用の構造 `vw_products_allclass_detail`
--

CREATE VIEW `vw_products_allclass_detail` AS select `dtb_products`.`product_id` AS `product_id`,
`dtb_products`.`name` AS `name`,
`dtb_products`.`deliv_fee` AS `deliv_fee`,
`dtb_products`.`sale_limit` AS `sale_limit`,
`dtb_products`.`rank` AS `rank`,
`dtb_products`.`status` AS `status`,
`dtb_products`.`product_flag` AS `product_flag`,
`dtb_products`.`point_rate` AS `point_rate`,
`dtb_products`.`sale_unlimited` AS `sale_unlimited`,
`dtb_products`.`comment1` AS `comment1`,
`dtb_products`.`comment2` AS `comment2`,
`dtb_products`.`comment3` AS `comment3`,
`dtb_products`.`comment4` AS `comment4`,
`dtb_products`.`comment5` AS `comment5`,
`dtb_products`.`comment6` AS `comment6`,
`dtb_products`.`note` AS `note`,
`dtb_products`.`file1` AS `file1`,
`dtb_products`.`file2` AS `file2`,
`dtb_products`.`file3` AS `file3`,
`dtb_products`.`file4` AS `file4`,
`dtb_products`.`file5` AS `file5`,
`dtb_products`.`file6` AS `file6`,
`dtb_products`.`main_list_comment` AS `main_list_comment`,
`dtb_products`.`main_list_image` AS `main_list_image`,
`dtb_products`.`main_comment` AS `main_comment`,
`dtb_products`.`main_image` AS `main_image`,
`dtb_products`.`main_large_image` AS `main_large_image`,
`dtb_products`.`sub_title1` AS `sub_title1`,
`dtb_products`.`sub_comment1` AS `sub_comment1`,
`dtb_products`.`sub_image1` AS `sub_image1`,
`dtb_products`.`sub_large_image1` AS `sub_large_image1`,
`dtb_products`.`sub_title2` AS `sub_title2`,
`dtb_products`.`sub_comment2` AS `sub_comment2`,
`dtb_products`.`sub_image2` AS `sub_image2`,
`dtb_products`.`sub_large_image2` AS `sub_large_image2`,
`dtb_products`.`sub_title3` AS `sub_title3`,
`dtb_products`.`sub_comment3` AS `sub_comment3`,
`dtb_products`.`sub_image3` AS `sub_image3`,
`dtb_products`.`sub_large_image3` AS `sub_large_image3`,
`dtb_products`.`sub_title4` AS `sub_title4`,
`dtb_products`.`sub_comment4` AS `sub_comment4`,
`dtb_products`.`sub_image4` AS `sub_image4`,
`dtb_products`.`sub_large_image4` AS `sub_large_image4`,
`dtb_products`.`sub_title5` AS `sub_title5`,
`dtb_products`.`sub_comment5` AS `sub_comment5`,
`dtb_products`.`sub_image5` AS `sub_image5`,
`dtb_products`.`sub_large_image5` AS `sub_large_image5`,
`dtb_products`.`sub_title6` AS `sub_title6`,
`dtb_products`.`sub_comment6` AS `sub_comment6`,
`dtb_products`.`sub_image6` AS `sub_image6`,
`dtb_products`.`sub_large_image6` AS `sub_large_image6`,
`dtb_products`.`del_flg` AS `del_flg`,
`dtb_products`.`creator_id` AS `creator_id`,
`dtb_products`.`create_date` AS `create_date`,
`dtb_products`.`update_date` AS `update_date`,
`dtb_products`.`deliv_date_id` AS `deliv_date_id`,
`t4`.`product_code_min` AS `product_code_min`,
`t4`.`product_code_max` AS `product_code_max`,
`t4`.`price01_min` AS `price01_min`,
`t4`.`price01_max` AS `price01_max`,
`t4`.`price02_min` AS `price02_min`,
`t4`.`price02_max` AS `price02_max`,
`t4`.`stock_min` AS `stock_min`,
`t4`.`stock_max` AS `stock_max`,
`t4`.`stock_unlimited_min` AS `stock_unlimited_min`,
`t4`.`stock_unlimited_max` AS `stock_unlimited_max`,
`t4`.`class_count` AS `class_count` from (`dtb_products` left join `vw_T4` `t4` on((`dtb_products`.`product_id` = `t4`.`product_id`)));

-- --------------------------------------------------------

--
-- ビュー用の構造 `vw_products_allclass`
--

CREATE VIEW `vw_products_allclass` AS select `alldtl`.`product_id` AS `product_id`,
`alldtl`.`name` AS `name`,
`alldtl`.`deliv_fee` AS `deliv_fee`,
`alldtl`.`sale_limit` AS `sale_limit`,
`alldtl`.`rank` AS `rank`,
`alldtl`.`status` AS `status`,
`alldtl`.`product_flag` AS `product_flag`,
`alldtl`.`point_rate` AS `point_rate`,
`alldtl`.`sale_unlimited` AS `sale_unlimited`,
`alldtl`.`comment1` AS `comment1`,
`alldtl`.`comment2` AS `comment2`,
`alldtl`.`comment3` AS `comment3`,
`alldtl`.`comment4` AS `comment4`,
`alldtl`.`comment5` AS `comment5`,
`alldtl`.`comment6` AS `comment6`,
`alldtl`.`note` AS `note`,
`alldtl`.`file1` AS `file1`,
`alldtl`.`file2` AS `file2`,
`alldtl`.`file3` AS `file3`,
`alldtl`.`file4` AS `file4`,
`alldtl`.`file5` AS `file5`,
`alldtl`.`file6` AS `file6`,
`alldtl`.`main_list_comment` AS `main_list_comment`,
`alldtl`.`main_list_image` AS `main_list_image`,
`alldtl`.`main_comment` AS `main_comment`,
`alldtl`.`main_image` AS `main_image`,
`alldtl`.`main_large_image` AS `main_large_image`,
`alldtl`.`sub_title1` AS `sub_title1`,
`alldtl`.`sub_comment1` AS `sub_comment1`,
`alldtl`.`sub_image1` AS `sub_image1`,
`alldtl`.`sub_large_image1` AS `sub_large_image1`,
`alldtl`.`sub_title2` AS `sub_title2`,
`alldtl`.`sub_comment2` AS `sub_comment2`,
`alldtl`.`sub_image2` AS `sub_image2`,
`alldtl`.`sub_large_image2` AS `sub_large_image2`,
`alldtl`.`sub_title3` AS `sub_title3`,
`alldtl`.`sub_comment3` AS `sub_comment3`,
`alldtl`.`sub_image3` AS `sub_image3`,
`alldtl`.`sub_large_image3` AS `sub_large_image3`,
`alldtl`.`sub_title4` AS `sub_title4`,
`alldtl`.`sub_comment4` AS `sub_comment4`,
`alldtl`.`sub_image4` AS `sub_image4`,
`alldtl`.`sub_large_image4` AS `sub_large_image4`,
`alldtl`.`sub_title5` AS `sub_title5`,
`alldtl`.`sub_comment5` AS `sub_comment5`,
`alldtl`.`sub_image5` AS `sub_image5`,
`alldtl`.`sub_large_image5` AS `sub_large_image5`,
`alldtl`.`sub_title6` AS `sub_title6`,
`alldtl`.`sub_comment6` AS `sub_comment6`,
`alldtl`.`sub_image6` AS `sub_image6`,
`alldtl`.`sub_large_image6` AS `sub_large_image6`,
`alldtl`.`del_flg` AS `del_flg`,
`alldtl`.`creator_id` AS `creator_id`,
`alldtl`.`create_date` AS `create_date`,
`alldtl`.`update_date` AS `update_date`,
`alldtl`.`deliv_date_id` AS `deliv_date_id`,
`alldtl`.`product_code_min` AS `product_code_min`,
`alldtl`.`product_code_max` AS `product_code_max`,
`alldtl`.`price01_min` AS `price01_min`,
`alldtl`.`price01_max` AS `price01_max`,
`alldtl`.`price02_min` AS `price02_min`,
`alldtl`.`price02_max` AS `price02_max`,
`alldtl`.`stock_min` AS `stock_min`,
`alldtl`.`stock_max` AS `stock_max`,
`alldtl`.`stock_unlimited_min` AS `stock_unlimited_min`,
`alldtl`.`stock_unlimited_max` AS `stock_unlimited_max`,
`alldtl`.`class_count` AS `class_count`,
`dtb_category`.`rank` AS `category_rank`,
`t2`.`category_id` AS `category_id`,
`t2`.`rank` AS `product_rank` from ((`vw_products_allclass_detail` `alldtl` left join `dtb_product_categories` `t2` on((`alldtl`.`product_id` = `t2`.`product_id`))) left join `dtb_category` on((`t2`.`category_id` = `dtb_category`.`category_id`)));

-- --------------------------------------------------------

--
-- ビュー用の構造 `vw_products_nonclass`
--

CREATE VIEW `vw_products_nonclass` AS select `t1`.`product_id` AS `product_id`,
`t1`.`name` AS `name`,
`t1`.`deliv_fee` AS `deliv_fee`,
`t1`.`sale_limit` AS `sale_limit`,
`t1`.`sale_unlimited` AS `sale_unlimited`,
`t1`.`category_id` AS `category_id`,
`t1`.`rank` AS `rank`,
`t1`.`status` AS `status`,
`t1`.`product_flag` AS `product_flag`,
`t1`.`point_rate` AS `point_rate`,
`t1`.`comment1` AS `comment1`,
`t1`.`comment2` AS `comment2`,
`t1`.`comment3` AS `comment3`,
`t1`.`comment4` AS `comment4`,
`t1`.`comment5` AS `comment5`,
`t1`.`comment6` AS `comment6`,
`t1`.`note` AS `note`,
`t1`.`file1` AS `file1`,
`t1`.`file2` AS `file2`,
`t1`.`file3` AS `file3`,
`t1`.`file4` AS `file4`,
`t1`.`file5` AS `file5`,
`t1`.`file6` AS `file6`,
`t1`.`main_list_comment` AS `main_list_comment`,
`t1`.`main_list_image` AS `main_list_image`,
`t1`.`main_comment` AS `main_comment`,
`t1`.`main_image` AS `main_image`,
`t1`.`main_large_image` AS `main_large_image`,
`t1`.`sub_title1` AS `sub_title1`,
`t1`.`sub_comment1` AS `sub_comment1`,
`t1`.`sub_image1` AS `sub_image1`,
`t1`.`sub_large_image1` AS `sub_large_image1`,
`t1`.`sub_title2` AS `sub_title2`,
`t1`.`sub_comment2` AS `sub_comment2`,
`t1`.`sub_image2` AS `sub_image2`,
`t1`.`sub_large_image2` AS `sub_large_image2`,
`t1`.`sub_title3` AS `sub_title3`,
`t1`.`sub_comment3` AS `sub_comment3`,
`t1`.`sub_image3` AS `sub_image3`,
`t1`.`sub_large_image3` AS `sub_large_image3`,
`t1`.`sub_title4` AS `sub_title4`,
`t1`.`sub_comment4` AS `sub_comment4`,
`t1`.`sub_image4` AS `sub_image4`,
`t1`.`sub_large_image4` AS `sub_large_image4`,
`t1`.`sub_title5` AS `sub_title5`,
`t1`.`sub_comment5` AS `sub_comment5`,
`t1`.`sub_image5` AS `sub_image5`,
`t1`.`sub_large_image5` AS `sub_large_image5`,
`t1`.`sub_title6` AS `sub_title6`,
`t1`.`sub_comment6` AS `sub_comment6`,
`t1`.`sub_image6` AS `sub_image6`,
`t1`.`sub_large_image6` AS `sub_large_image6`,
`t1`.`del_flg` AS `del_flg`,
`t1`.`creator_id` AS `creator_id`,
`t1`.`create_date` AS `create_date`,
`t1`.`update_date` AS `update_date`,
`t1`.`deliv_date_id` AS `deliv_date_id`,
`t2`.`product_id_sub` AS `product_id_sub`,
`t2`.`product_code` AS `product_code`,
`t2`.`price01` AS `price01`,
`t2`.`price02` AS `price02`,
`t2`.`stock` AS `stock`,
`t2`.`stock_unlimited` AS `stock_unlimited`,
`t2`.`classcategory_id1` AS `classcategory_id1`,
`t2`.`classcategory_id2` AS `classcategory_id2` from (`dtb_products` `t1` left join `vw_T2` `t2` on((`t1`.`product_id` = `t2`.`product_id_sub`)));

-- --------------------------------------------------------

--
-- ビュー用の構造 `vw_product_class`
--

CREATE VIEW `vw_product_class` AS select `t5`.`product_class_id` AS `product_class_id`,
`t5`.`product_id_sub` AS `product_id_sub`,
`t5`.`classcategory_id1` AS `classcategory_id1`,
`t5`.`classcategory_id2` AS `classcategory_id2`,
`t5`.`rank1` AS `rank1`,
`t5`.`rank2` AS `rank2`,
`t5`.`class_id1` AS `class_id1`,
`t5`.`class_id2` AS `class_id2`,
`t5`.`stock` AS `stock`,
`t5`.`price01` AS `price01`,
`t5`.`price02` AS `price02`,
`t5`.`stock_unlimited` AS `stock_unlimited`,
`t5`.`product_code` AS `product_code`,
`t6`.`product_id` AS `product_id`,
`t6`.`name` AS `name`,
`t6`.`deliv_fee` AS `deliv_fee`,
`t6`.`sale_limit` AS `sale_limit`,
`t6`.`sale_unlimited` AS `sale_unlimited`,
`t6`.`category_id` AS `category_id`,
`t6`.`rank` AS `rank`,
`t6`.`status` AS `status`,
`t6`.`product_flag` AS `product_flag`,
`t6`.`point_rate` AS `point_rate`,
`t6`.`comment1` AS `comment1`,
`t6`.`comment2` AS `comment2`,
`t6`.`comment3` AS `comment3`,
`t6`.`comment4` AS `comment4`,
`t6`.`comment5` AS `comment5`,
`t6`.`comment6` AS `comment6`,
`t6`.`note` AS `note`,
`t6`.`file1` AS `file1`,
`t6`.`file2` AS `file2`,
`t6`.`file3` AS `file3`,
`t6`.`file4` AS `file4`,
`t6`.`file5` AS `file5`,
`t6`.`file6` AS `file6`,
`t6`.`main_list_comment` AS `main_list_comment`,
`t6`.`main_list_image` AS `main_list_image`,
`t6`.`main_comment` AS `main_comment`,
`t6`.`main_image` AS `main_image`,
`t6`.`main_large_image` AS `main_large_image`,
`t6`.`sub_title1` AS `sub_title1`,
`t6`.`sub_comment1` AS `sub_comment1`,
`t6`.`sub_image1` AS `sub_image1`,
`t6`.`sub_large_image1` AS `sub_large_image1`,
`t6`.`sub_title2` AS `sub_title2`,
`t6`.`sub_comment2` AS `sub_comment2`,
`t6`.`sub_image2` AS `sub_image2`,
`t6`.`sub_large_image2` AS `sub_large_image2`,
`t6`.`sub_title3` AS `sub_title3`,
`t6`.`sub_comment3` AS `sub_comment3`,
`t6`.`sub_image3` AS `sub_image3`,
`t6`.`sub_large_image3` AS `sub_large_image3`,
`t6`.`sub_title4` AS `sub_title4`,
`t6`.`sub_comment4` AS `sub_comment4`,
`t6`.`sub_image4` AS `sub_image4`,
`t6`.`sub_large_image4` AS `sub_large_image4`,
`t6`.`sub_title5` AS `sub_title5`,
`t6`.`sub_comment5` AS `sub_comment5`,
`t6`.`sub_image5` AS `sub_image5`,
`t6`.`sub_large_image5` AS `sub_large_image5`,
`t6`.`sub_title6` AS `sub_title6`,
`t6`.`sub_comment6` AS `sub_comment6`,
`t6`.`sub_image6` AS `sub_image6`,
`t6`.`sub_large_image6` AS `sub_large_image6`,
`t6`.`del_flg` AS `del_flg`,
`t6`.`creator_id` AS `creator_id`,
`t6`.`create_date` AS `create_date`,
`t6`.`update_date` AS `update_date`,
`t6`.`deliv_date_id` AS `deliv_date_id` from (`vw_T5` `t5` left join `dtb_products` `t6` on((`t5`.`product_id_sub` = `t6`.`product_id`)));

-- --------------------------------------------------------


※どうですか?劇的に速くなったでしょ?

 まぁ、これも全てパクリ ですが...


名古屋ではたらくWEB屋さんの読者になろう

ブログの更新情報が受け取れて、アクセスが簡単になります

Ameba人気のブログ

Amebaトピックス

    ブログをはじめる

    たくさんの芸能人・有名人が
    書いているAmebaブログを
    無料で簡単にはじめることができます。

    公式トップブロガーへ応募

    多くの方にご紹介したいブログを
    執筆する方を「公式トップブロガー」
    として認定しております。

    芸能人・有名人ブログを開設

    Amebaブログでは、芸能人・有名人ブログを
    ご希望される著名人の方/事務所様を
    随時募集しております。