php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79163 SQL SELECT EXISTS fills up memory
Submitted: 2020-01-24 09:06 UTC Modified: 2020-01-24 09:47 UTC
From: kinimodmeyer at gmail dot com Assigned:
Status: Open Package: MySQLi related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: kinimodmeyer at gmail dot com
New email:
PHP Version: OS:

 

 [2020-01-24 09:06 UTC] kinimodmeyer at gmail dot com
Description:
------------
SELECT EXISTS in the query fills up the memory. see test-script below.

Test script:
---------------
<?php
$start = microtime(true);
var_dump(memory_get_usage(true));

for ($i = 0;$i<100000;$i++) {
    $sql = 'SELECT 1
            FROM `article`
            WHERE a_nr = "'.$mysqli->real_escape_string(bin2hex(random_bytes(10))).'"
            LIMIT 1';
    $mysqli->query($sql);
}

var_dump(microtime(true) - $start, memory_get_usage(true));
$start = microtime(true);

for ($i = 0;$i<100000;$i++) {
    $sql = 'SELECT EXISTS
            (
                SELECT 1
                FROM `article`
                WHERE a_nr = "'.$mysqli->real_escape_string(bin2hex(random_bytes(10))).'"
                LIMIT 1
            )';
    $mysqli->query($sql);
}

var_dump(microtime(true) - $start, memory_get_usage(true));

Expected result:
----------------
memory1: int(4194304)
memory2: int(4194304)
momory3: int(28311552)

Actual result:
--------------
php memory fills up in the second query

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-01-24 09:47 UTC] cmb@php.net
I cannot reproduce with PHP 7.4.3-dev using mysqlnd.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sat Jul 11 22:01:24 2020 UTC