Bug #79163 [NEW]: SQL SELECT EXISTS fills up memory

From: Date: Fri, 24 Jan 2020 09:06:18 +0000
Subject: Bug #79163 [NEW]: SQL SELECT EXISTS fills up memory
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-225085@lists.php.net to get a copy of this message
From:             kinimodmeyer at gmail dot com
Operating system: 
PHP version:      Irrelevant
Package:          MySQLi related
Bug Type:         Bug
Bug description:SQL SELECT EXISTS fills up memory

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

-- 
Edit bug report at https://bugs.php.net/bug.php?id=79163&edit=1
-- 
Fix committed:                    https://bugs.php.net/fix.php?id=79163&r=fixed
Fixed in release:                 https://bugs.php.net/fix.php?id=79163&r=alreadyfixed
Need backtrace:                   https://bugs.php.net/fix.php?id=79163&r=needtrace
Need Reproduce Script:            https://bugs.php.net/fix.php?id=79163&r=needscript
Try newer version:                https://bugs.php.net/fix.php?id=79163&r=oldversion
Not developer issue:              https://bugs.php.net/fix.php?id=79163&r=support
Expected behavior:                https://bugs.php.net/fix.php?id=79163&r=notwrong
Not enough info:                  https://bugs.php.net/fix.php?id=79163&r=notenoughinfo
Submitted twice:                  https://bugs.php.net/fix.php?id=79163&r=submittedtwice
register_globals:                 https://bugs.php.net/fix.php?id=79163&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=79163&r=phptooold
Daylight Savings:                 https://bugs.php.net/fix.php?id=79163&r=dst
IIS Stability:                    https://bugs.php.net/fix.php?id=79163&r=isapi
Install GNU Sed:                  https://bugs.php.net/fix.php?id=79163&r=gnused
Floating point limitations:       https://bugs.php.net/fix.php?id=79163&r=float
No Zend Extensions:               https://bugs.php.net/fix.php?id=79163&r=nozend
MySQL Configuration Error:        https://bugs.php.net/fix.php?id=79163&r=mysqlcfg


Thread (4 messages)

« previous php.bugs (#225085) next »