Skip to content

Commit 42b6b8a

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Fix #80027 Terrible performance using $query->fetch on queries with many bind parameters
2 parents b396fb3 + 44ade0e commit 42b6b8a

File tree

8 files changed

+33
-2
lines changed

8 files changed

+33
-2
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ PHP NEWS
1818
. Fixed bug #80002 (calc free space for new interned string is wrong).
1919
(t-matsuno)
2020

21+
- PDO:
22+
. Fixed bug #80027 (Terrible performance using $query->fetch on queries with
23+
many bind parameters (Matteo)
24+
2125
- Standard:
2226
. Fixed bug #79986 (str_ireplace bug with diacritics characters). (cmb)
2327

ext/pdo/pdo_stmt.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ static int dispatch_param_event(pdo_stmt_t *stmt, enum pdo_param_event event_typ
163163
struct pdo_bound_param_data *param;
164164
HashTable *ht;
165165

166+
if (stmt->dbh->skip_param_evt & (1 << event_type)) {
167+
return 1;
168+
}
169+
166170
if (!stmt->methods->param_hook) {
167171
return 1;
168172
}

ext/pdo/php_pdo_driver.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,9 +468,12 @@ struct _pdo_dbh_t {
468468
/* when set, convert int/floats to strings */
469469
unsigned stringify:1;
470470

471+
/* bitmap for pdo_param_event(s) to skip in dispatch_param_event */
472+
unsigned skip_param_evt:7;
473+
471474
/* the sum of the number of bits here and the bit fields preceding should
472475
* equal 32 */
473-
unsigned _reserved_flags:21;
476+
unsigned _reserved_flags:14;
474477

475478
/* data source string used to open this handle */
476479
const char *data_source;

ext/pdo_mysql/mysql_driver.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,13 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options)
619619

620620
dbh->driver_data = H;
621621

622+
dbh->skip_param_evt =
623+
1 << PDO_PARAM_EVT_FREE |
624+
1 << PDO_PARAM_EVT_EXEC_POST |
625+
1 << PDO_PARAM_EVT_FETCH_PRE |
626+
1 << PDO_PARAM_EVT_FETCH_POST |
627+
1 << PDO_PARAM_EVT_NORMALIZE;
628+
622629
#ifndef PDO_USE_MYSQLND
623630
H->max_buffer_size = 1024*1024;
624631
#endif

ext/pdo_oci/oci_driver.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,11 @@ static int pdo_oci_handle_factory(pdo_dbh_t *dbh, zval *driver_options) /* {{{ *
688688
H = pecalloc(1, sizeof(*H), dbh->is_persistent);
689689
dbh->driver_data = H;
690690

691+
dbh->skip_param_evt =
692+
1 << PDO_PARAM_EVT_FETCH_PRE |
693+
1 << PDO_PARAM_EVT_FETCH_POST |
694+
1 << PDO_PARAM_EVT_NORMALIZE;
695+
691696
H->prefetch = PDO_OCI_PREFETCH_DEFAULT;
692697

693698
/* allocate an environment */

ext/pdo_pgsql/pgsql_driver.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,6 +1196,11 @@ static int pdo_pgsql_handle_factory(pdo_dbh_t *dbh, zval *driver_options) /* {{{
11961196
H = pecalloc(1, sizeof(pdo_pgsql_db_handle), dbh->is_persistent);
11971197
dbh->driver_data = H;
11981198

1199+
dbh->skip_param_evt =
1200+
1 << PDO_PARAM_EVT_EXEC_POST |
1201+
1 << PDO_PARAM_EVT_FETCH_PRE |
1202+
1 << PDO_PARAM_EVT_FETCH_POST;
1203+
11991204
H->einfo.errcode = 0;
12001205
H->einfo.errmsg = NULL;
12011206

ext/pdo_pgsql/pgsql_statement.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ static int pgsql_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *
399399
}
400400
break;
401401
}
402-
} else if (param->is_param) {
402+
} else if (param->is_param && event_type == PDO_PARAM_EVT_NORMALIZE) {
403403
/* We need to manually convert to a pg native boolean value */
404404
if (PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_BOOL &&
405405
((param->param_type & PDO_PARAM_INPUT_OUTPUT) != PDO_PARAM_INPUT_OUTPUT)) {

ext/pdo_sqlite/sqlite_driver.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,9 @@ static int pdo_sqlite_handle_factory(pdo_dbh_t *dbh, zval *driver_options) /* {{
806806
H->einfo.errmsg = NULL;
807807
dbh->driver_data = H;
808808

809+
/* skip all but this one param event */
810+
dbh->skip_param_evt = 0x7F ^ (1 << PDO_PARAM_EVT_EXEC_PRE);
811+
809812
filename = make_filename_safe(dbh->data_source);
810813

811814
if (!filename) {

0 commit comments

Comments
 (0)