定制 mfn/cakephp2-postgres-no-meta 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mfn/cakephp2-postgres-no-meta

最新稳定版本:0.0.6

Composer 安装命令:

composer require mfn/cakephp2-postgres-no-meta

包简介

A CakePHP2 Postgres database driver without getColumnMeta() support

README 文档

README

This driver was changed in the following ways:

  1. The default CakePHP 2.x Postgres driver uses getColumnMeta to infer column types from the server. Although the PHP part has been optimized in recent years [1], it still incurs an overhead to hit the Postgres database on every call with a query like SELECT RELNAME FROM PG_CLASS WHERE OID=... [2]

Thus, this implementation is born which foregoes any use of the meta data and simply uses PDO::FETCH_ASSOC.

  1. There's a problem with special crafted SQL statements which contain the \ character [3] which actually isn't CakePHP specific but a problem of the underlying PDO/PgSQL driver [4].

The method \Postgres::value() was overriden to apply the special C-style escape operation to strings [5].

  1. The default PHP/PDO lastInsertId always returns a string. This driver is adapted to return an integer if is_numeric returns true on it. This allows easier integration with codebases using strict_types=1.

Requirements and Installation

  1. You need at least CakePHP 2.10.12
    For CakePHP >= 2.0 and < 2.10.12 , you can use version 0.0.2 of this package
  2. Add the line "mfn/cakephp2-postgres-no-meta": "^0.0.6" to your app/composer.json
  3. Run php composer.phar require mfn/cakephp2-postgres-no-meta
  4. Load the plugin in app/Config/bootstrap.php with the line
CakePlugin::load('PostgresNoMeta');
  1. Use the driver in your app/Config/database.php: PostgresNoMeta.Database/PostgresNoMeta (instead of Database/Postgres)
  2. Profit!

Rational

During the switch of a big application from MySQL to Postgres it was discovered that much overhead was lost on Postgres and it was finally discovered that these meta queries incur a measurable overhead.

The individual queries are very fast but, depending on your queries, they may add up until a measurable point.

In our case there were performance improvement of up to 50% without any additional changes except activating this class. YMMV.

A little bit later also found problems with the generated SQL statements, which in special cases were translated from:

INSERT INTO models(field) VALUES('\'':1');

to

INSERT INTO models(field) VALUES('\''$1');

before sent to the server, causing various problems.

Further reference

统计信息

  • 总下载量: 2.04k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 8
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 8
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-01-18