{"action":"opened","issue":{"url":"https://api.github.com/repos/yiisoft/yii2/issues/7913","labels_url":"https://api.github.com/repos/yiisoft/yii2/issues/7913/labels{/name}","comments_url":"https://api.github.com/repos/yiisoft/yii2/issues/7913/comments","events_url":"https://api.github.com/repos/yiisoft/yii2/issues/7913/events","html_url":"https://github.com/yiisoft/yii2/issues/7913","id":65175437,"number":7913,"title":"Memory limit exceeded on DB query","user":{"login":"ominds","id":303512,"avatar_url":"https://avatars.githubusercontent.com/u/303512?v=3","gravatar_id":"","url":"https://api.github.com/users/ominds","html_url":"https://github.com/ominds","followers_url":"https://api.github.com/users/ominds/followers","following_url":"https://api.github.com/users/ominds/following{/other_user}","gists_url":"https://api.github.com/users/ominds/gists{/gist_id}","starred_url":"https://api.github.com/users/ominds/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ominds/subscriptions","organizations_url":"https://api.github.com/users/ominds/orgs","repos_url":"https://api.github.com/users/ominds/repos","events_url":"https://api.github.com/users/ominds/events{/privacy}","received_events_url":"https://api.github.com/users/ominds/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-03-30T09:49:27Z","updated_at":"2015-03-30T09:49:27Z","closed_at":null,"body":"I'm having this error message show up every hour or so in my PHP log files\r\n\r\n[30-Mar-2015 08:37:52 UTC] PHP Fatal error:  Allowed memory size of 335544320 bytes exhausted (tried to allocate 83 bytes) in /var/www/htdocs/yaqut/yii-api/vendor/yiisoft/yii2/db/BaseActiveRecord.php on line 1048\r\n\r\nAs you can see, I raised the limit from 192 MB to 320 MB and still getting the same problem. And on the same line of code. From the stack trace, here's the relevant code information from my file that's ultimately causing this\r\n\r\n    public static function highlightsByUserAndBook($userprofile_id, $book_id, $wheres = []) {\r\n        $highlights = self::find()->where(['userprofile_id' => $userprofile_id, 'book_id' => $book_id]);\r\n        \r\n        foreach ($wheres AS $where) {\r\n            $highlights->andWhere($where);\r\n        }\r\n        \r\n        $highlights_result = $highlights->all(); // This is the line that crashes!!!\r\n        \r\n        $highlights_array = [];\r\n        \r\n        foreach ($highlights_result AS $highlight) {\r\n            $highlights_array[] = $highlight->mapAttribs(['serverId' => 'id', 'bookId' => 'book_id', 'fromOffset', 'toOffset', \r\n            'color' => 'markColor', 'noteText' => 'displayText', 'deleted']);\r\n        }\r\n        \r\n        return $highlights_array;\r\n    }\r\n\r\nHere's the Table Schema for Highlights\r\n\r\n    CREATE TABLE `yqt_highlights` (\r\n      `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\r\n      `userprofile_id` bigint(20) NOT NULL,\r\n      `book_id` int(10) unsigned NOT NULL,\r\n      `fromOffset` int(11) unsigned NOT NULL,\r\n      `toOffset` int(11) unsigned NOT NULL,\r\n      `markColor` int(11) unsigned NOT NULL,\r\n      `displayText` varchar(150) DEFAULT NULL,\r\n      `accessType` smallint(5) unsigned NOT NULL,\r\n      `deleted` tinyint(1) unsigned NOT NULL DEFAULT '0',\r\n      `created` timestamp NULL DEFAULT CURRENT_TIMESTAMP,\r\n      `modified` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\r\n      PRIMARY KEY (`id`),\r\n      KEY `userprofileId` (`userprofile_id`,`book_id`),\r\n      KEY `IDX_yqt_highlights_deleted` (`deleted`)\r\n    ) ENGINE=InnoDB AUTO_INCREMENT=54659975 DEFAULT CHARSET=utf8\r\n\r\nFinally, here's the query that's happening\r\n\r\n    SELECT * FROM `yqt_highlights` WHERE ((`userprofile_id`=193821) AND (`book_id`=987)) AND (`modified` >= '2015-03-25 21:30:15')\r\n\r\nAnd the call signature\r\n\r\n    193821, 987, [['>=', 'modified', '2015-03-25 21:30:15']]\r\n\r\nI think that covers it. I'm not sure what the problem is and why it's happening."}}