Bug #34254 | Very slow queries when using functions in SELECT statements | ||
---|---|---|---|
Submitted: | 2 Feb 2008 20:26 | Modified: | 4 Feb 2008 2:23 |
Reporter: | Van Stokes | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server: General | Severity: | S2 (Serious) |
Version: | 5.1.22 RC (x64) | OS: | Windows (XP x64 AMD DC) |
Assigned to: | CPU Architecture: | Any | |
Tags: | innodb, SELECT |
[2 Feb 2008 20:26]
Van Stokes
[3 Feb 2008 19:25]
Valeriy Kravchuk
Thank you for a detailed problem report. Please, try to declare function as DETERMINISTIC and check if you'll get the results faster.
[4 Feb 2008 2:23]
Van Stokes
Yes that did it! Declaring the function with the DETERMINISTIC option made all the difference in the world. Example: CREATE FUNCTION InventoryGetLocationInvKey( pInventoryKey INT UNSIGNED ) RETURNS INT UNSIGNED DETERMINISTIC MAIN: BEGIN DECLARE mInventoryKey INT UNSIGNED DEFAULT 0; DECLARE mLastInventoryKey INT UNSIGNED DEFAULT 0; SET mLastInventoryKey = pInventoryKey; SEARCH: LOOP -- Get the Parent/Containing Inventory Key. SET mInventoryKey = InventoryGetParentInvKey( mLastInventoryKey ); IF mInventoryKey < 1 THEN -- This inventory key is not contained and therefore -- is an inventory item that appears in a scene. -- That is, it's the HIGHEST most item in the hiarchy. LEAVE SEARCH; END IF; SET mLastInventoryKey = mInventoryKey; END LOOP SEARCH; RETURN mLastInventoryKey; END MAIN;