MySQL Forums
Forum List  »  Performance

Re: Query Takes Longer Each Time Its Run
Posted by: anthony
Date: January 31, 2011 01:22AM

Here is a test database with one table, 626 rows, and 4 udfs required for the query:

-- ------------------------------------------------------
-- Server version 5.5.8-log

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Table structure for table `records`
--

DROP TABLE IF EXISTS `records`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `records` (
`RecordID` int(11) unsigned NOT NULL AUTO_INCREMENT,
`UserID` int(11) unsigned NOT NULL DEFAULT '0',
`ClockIn` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (`RecordID`),
KEY `ix_unpaidhours` (`UserID`),
KEY `ix_userid` (`UserID`),
KEY `idx_xhours` (`UserID`),
KEY `idx_recordalerts` (`UserID`),
KEY `idx_usertimeclass` (`UserID`)
) ENGINE=MyISAM AUTO_INCREMENT=3911876 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `records`
--

LOCK TABLES `records` WRITE;
/*!40000 ALTER TABLE `records` DISABLE KEYS */;
INSERT INTO `records` VALUES (2173266,23993,'2009-09-24 20:05:00'),(2176436,23993,'2009-09-25 12:58:00'),(2177529,23993,'2009-09-25 19:58:00'),(2181635,23993,'2009-09-28 13:05:00'),(2182824,23993,'2009-09-28 20:06:00'),(2185903,23993,'2009-09-29 12:57:00'),(2187293,23993,'2009-09-29 20:13:00'),(2190206,23993,'2009-09-30 12:58:00'),(2191702,23993,'2009-09-30 19:46:00'),(2194625,23993,'2009-10-01 13:31:00'),(2196269,23993,'2009-10-01 20:16:00'),(2198948,23993,'2009-10-02 12:58:00'),(2200287,23993,'2009-10-02 19:44:00'),(2204085,23993,'2009-10-05 12:58:00'),(2205531,23993,'2009-10-05 19:44:00'),(2208525,23993,'2009-10-06 13:12:00'),(2209923,23993,'2009-10-06 20:06:00'),(2212728,23993,'2009-10-07 13:01:00'),(2214126,23993,'2009-10-07 19:50:00'),(2217113,23993,'2009-10-08 13:00:00'),(2218396,23993,'2009-10-08 19:56:00'),(2221041,23993,'2009-10-09 12:53:00'),(2223160,23993,'2009-10-09 20:48:00'),(2226604,23993,'2009-10-12 12:53:00'),(2229510,23993,'2009-10-12 20:06:00'),(2230543,23993,'2009-10-13 14:25:00'),(2232554,23993,'2009-10-13 19:17:00'),(2235238,23993,'2009-10-14 12:58:00'),(2236567,23993,'2009-10-14 20:25:00'),(2239429,23993,'2009-10-15 12:57:00'),(2240735,23993,'2009-10-15 19:52:00'),(2243518,23993,'2009-10-16 11:47:00'),(2248546,23993,'2009-10-19 13:03:00'),(2249969,23993,'2009-10-19 19:42:00'),(2253020,23993,'2009-10-20 13:00:00'),(2254294,23993,'2009-10-20 19:49:00'),(2257516,23993,'2009-10-21 13:05:00'),(2258899,23993,'2009-10-21 20:14:00'),(2261642,23993,'2009-10-22 12:54:00'),(2263080,23993,'2009-10-22 19:43:00'),(2266084,23993,'2009-10-23 13:09:00'),(2267399,23993,'2009-10-23 20:12:00'),(2283464,23993,'2009-10-28 07:00:00'),(2283465,23993,'2009-10-26 07:00:00'),(2283466,23993,'2009-10-27 07:00:00'),(2283467,23993,'2009-10-29 07:00:00'),(2283468,23993,'2009-10-30 07:00:00'),(2294134,23993,'2009-11-02 14:02:00'),(2295493,23993,'2009-11-02 21:00:00'),(2298547,23993,'2009-11-03 13:47:00'),(2299987,23993,'2009-11-03 20:59:00'),(2302958,23993,'2009-11-04 14:04:00'),(2304404,23993,'2009-11-04 20:49:00'),(2307728,23993,'2009-11-05 13:52:00'),(2308939,23993,'2009-11-05 21:50:00'),(2311893,23993,'2009-11-06 13:54:00'),(2313012,23993,'2009-11-06 21:08:00'),(2317088,23993,'2009-11-09 14:04:00'),(2318530,23993,'2009-11-09 20:59:00'),(2322088,23993,'2009-11-10 13:58:00'),(2323462,23993,'2009-11-10 21:08:00'),(2326323,23993,'2009-11-11 14:04:00'),(2327645,23993,'2009-11-11 21:01:00'),(2330501,23993,'2009-11-12 14:01:00'),(2332004,23993,'2009-11-12 20:55:00'),(2334858,23993,'2009-11-13 13:52:00'),(2336153,23993,'2009-11-13 20:56:00'),(2340029,23993,'2009-11-16 13:55:00'),(2341470,23993,'2009-11-16 20:40:00'),(2344715,23993,'2009-11-17 14:03:00'),(2345995,23993,'2009-11-17 20:57:00'),(2349119,23993,'2009-11-18 13:39:00'),(2350328,23993,'2009-11-18 21:05:00'),(2355502,23993,'2009-11-19 14:00:00'),(2355504,23993,'2009-11-19 20:00:00'),(2357862,23993,'2009-11-20 14:00:00'),(2359318,23993,'2009-11-20 17:30:00'),(2363242,23993,'2009-11-23 14:03:00'),(2364801,23993,'2009-11-23 20:46:00'),(2367992,23993,'2009-11-24 14:00:00'),(2369293,23993,'2009-11-24 21:10:00'),(2372501,23993,'2009-11-25 14:04:00'),(2373922,23993,'2009-11-25 21:09:00'),(2375710,23993,'2009-11-27 12:49:00'),(2375998,23993,'2009-11-27 20:16:00'),(2379873,23993,'2009-11-30 14:04:00'),(2381381,23993,'2009-11-30 21:15:00'),(2382498,23993,'2009-11-26 08:00:00'),(2382669,23993,'2009-11-27 08:00:00'),(2384678,23993,'2009-12-01 14:04:00'),(2386233,23993,'2009-12-01 21:01:00'),(2389352,23993,'2009-12-02 14:37:00'),(2390947,23993,'2009-12-02 20:30:00'),(2398348,23993,'2009-12-04 13:49:00'),(2399677,23993,'2009-12-04 20:45:00'),(2403869,23993,'2009-12-07 13:59:00'),(2405092,23993,'2009-12-07 20:52:00'),(2408199,23993,'2009-12-08 13:55:00'),(2409420,23993,'2009-12-08 20:56:00'),(2412478,23993,'2009-12-09 13:59:00'),(2413937,23993,'2009-12-09 20:57:00'),(2416859,23993,'2009-12-10 13:56:00'),(2418275,23993,'2009-12-10 21:01:00'),(2421171,23993,'2009-12-11 13:59:00'),(2422312,23993,'2009-12-11 20:49:00'),(2426352,23993,'2009-12-14 14:00:00'),(2427737,23993,'2009-12-14 20:57:00'),(2430879,23993,'2009-12-15 13:56:00'),(2432104,23993,'2009-12-15 21:06:00'),(2435351,23993,'2009-12-16 14:08:00'),(2436752,23993,'2009-12-16 20:53:00'),(2439636,23993,'2009-12-17 14:13:00'),(2441013,23993,'2009-12-17 20:40:00'),(2443894,23993,'2009-12-18 14:36:00'),(2445501,23993,'2009-12-18 20:36:00'),(2449252,23993,'2009-12-21 14:09:00'),(2450585,23993,'2009-12-21 20:43:00'),(2453377,23993,'2009-12-22 14:05:00'),(2454919,23993,'2009-12-22 21:04:00'),(2457634,23993,'2009-12-23 13:55:00'),(2458849,23993,'2009-12-23 20:56:00'),(2464441,23993,'2009-12-28 08:00:00'),(2469145,23993,'2009-12-29 13:57:00'),(2470795,23993,'2009-12-29 21:09:00'),(2473531,23993,'2009-12-30 13:59:00'),(2474843,23993,'2009-12-30 21:16:00'),(2477626,23993,'2009-12-31 13:54:00'),(2478437,23993,'2009-12-31 20:44:00'),(2480365,23993,'2009-12-24 08:00:00'),(2480625,23993,'2010-01-01 08:00:00'),(2481999,23993,'2009-12-25 08:00:00'),(2483015,23993,'2010-01-04 13:55:00'),(2484594,23993,'2010-01-04 20:56:00'),(2487667,23993,'2010-01-05 14:04:00'),(2489248,23993,'2010-01-05 20:58:00'),(2492303,23993,'2010-01-06 13:54:00'),(2493839,23993,'2010-01-06 20:57:00'),(2496846,23993,'2010-01-07 13:59:00'),(2498297,23993,'2010-01-07 20:47:00'),(2501151,23993,'2010-01-08 13:50:00'),(2502550,23993,'2010-01-08 20:55:00'),(2506664,23993,'2010-01-11 13:56:00'),(2507900,23993,'2010-01-11 20:46:00'),(2511065,23993,'2010-01-12 14:09:00'),(2512679,23993,'2010-01-12 20:56:00'),(2515543,23993,'2010-01-13 13:56:00'),(2516855,23993,'2010-01-13 20:45:00'),(2520056,23993,'2010-01-14 14:09:00'),(2521689,23993,'2010-01-14 20:57:00'),(2524550,23993,'2010-01-15 14:00:00'),(2525964,23993,'2010-01-15 20:50:00'),(2528985,23993,'2010-01-18 13:54:00'),(2535792,23993,'2010-01-19 08:00:00'),(2535795,23993,'2010-01-18 08:00:00'),(2538514,23993,'2010-01-20 13:58:00'),(2539778,23993,'2010-01-20 21:23:00'),(2542793,23993,'2010-01-21 13:56:00'),(2544230,23993,'2010-01-21 20:43:00'),(2547035,23993,'2010-01-22 13:58:00'),(2548382,23993,'2010-01-22 20:35:00'),(2552685,23993,'2010-01-25 13:58:00'),(2553920,23993,'2010-01-25 20:50:00'),(2557207,23993,'2010-01-26 13:57:00'),(2561777,23993,'2010-01-27 14:01:00'),(2562988,23993,'2010-01-27 20:47:00'),(2566359,23993,'2010-01-28 14:04:00'),(2567714,23993,'2010-01-28 21:16:00'),(2570529,23993,'2010-01-29 13:52:00'),(2571980,23993,'2010-01-29 20:41:00'),(2576198,23993,'2010-02-01 13:55:00'),(2577501,23993,'2010-02-01 20:45:00'),(2580654,23993,'2010-02-02 13:55:00'),(2582081,23993,'2010-02-02 21:06:00'),(2585151,23993,'2010-02-03 13:55:00'),(2586611,23993,'2010-02-03 20:47:00'),(2589635,23993,'2010-02-04 13:57:00'),(2590865,23993,'2010-02-04 20:51:00'),(2594095,23993,'2010-02-05 13:52:00'),(2595165,23993,'2010-02-05 20:50:00'),(2599755,23993,'2010-02-08 14:24:00'),(2600715,23993,'2010-02-08 21:17:00'),(2603989,23993,'2010-02-09 13:55:00'),(2605489,23993,'2010-02-09 21:07:00'),(2608447,23993,'2010-02-10 13:58:00'),(2609739,23993,'2010-02-10 20:43:00'),(2613010,23993,'2010-02-11 14:54:00'),(2614514,23993,'2010-02-11 21:00:00'),(2617448,23993,'2010-02-12 13:56:00'),(2618854,23993,'2010-02-12 21:20:00'),(2622639,23993,'2010-02-15 13:56:00'),(2623700,23993,'2010-02-15 20:45:00'),(2626601,23993,'2010-02-16 14:10:00'),(2627987,23993,'2010-02-16 20:40:00'),(2631012,23993,'2010-02-17 13:53:00'),(2632361,23993,'2010-02-17 20:46:00'),(2635594,23993,'2010-02-18 14:31:00'),(2637022,23993,'2010-02-18 20:32:00'),(2640116,23993,'2010-02-19 14:01:00'),(2641528,23993,'2010-02-19 20:57:00'),(2645922,23993,'2010-02-22 13:56:00'),(2649039,23993,'2010-02-22 21:30:00'),(2650399,23993,'2010-02-23 13:54:00'),(2651749,23993,'2010-02-23 21:10:00'),(2654932,23993,'2010-02-24 13:50:00'),(2656385,23993,'2010-02-24 20:53:00'),(2659549,23993,'2010-02-25 14:08:00'),(2660973,23993,'2010-02-25 21:10:00'),(2663864,23993,'2010-02-26 13:59:00'),(2665214,23993,'2010-02-26 20:54:00'),(2669740,23993,'2010-03-01 13:58:00'),(2671213,23993,'2010-03-01 21:12:00'),(2674222,23993,'2010-03-02 14:01:00'),(2675674,23993,'2010-03-02 20:56:00'),(2678808,23993,'2010-03-03 13:58:00'),(2680252,23993,'2010-03-03 20:56:00'),(2683446,23993,'2010-03-04 14:02:00'),(2684802,23993,'2010-03-04 20:55:00'),(2688092,23993,'2010-03-05 14:12:00'),(2691282,23993,'2010-03-05 20:51:00'),(2693618,23993,'2010-03-08 13:48:00'),(2695044,23993,'2010-03-08 20:50:00'),(2698260,23993,'2010-03-09 13:56:00'),(2699901,23993,'2010-03-09 20:58:00'),(2702908,23993,'2010-03-10 13:54:00'),(2704304,23993,'2010-03-10 20:54:00'),(2707694,23993,'2010-03-11 13:57:00'),(2709183,23993,'2010-03-11 21:04:00'),(2712193,23993,'2010-03-12 13:56:00'),(2713558,23993,'2010-03-12 20:50:00'),(2717784,23993,'2010-03-15 12:48:00'),(2718933,23993,'2010-03-15 20:03:00'),(2722402,23993,'2010-03-16 12:52:00'),(2723584,23993,'2010-03-16 20:03:00'),(2726685,23993,'2010-03-17 12:52:00'),(2728026,23993,'2010-03-17 19:59:00'),(2731456,23993,'2010-03-18 12:55:00'),(2732700,23993,'2010-03-18 19:52:00'),(2735664,23993,'2010-03-19 12:49:00'),(2737296,23993,'2010-03-19 19:59:00'),(2741265,23993,'2010-03-22 12:54:00'),(2742605,23993,'2010-03-22 19:50:00'),(2745968,23993,'2010-03-23 12:52:00'),(2747457,23993,'2010-03-23 19:53:00'),(2750550,23993,'2010-03-24 12:49:00'),(2751941,23993,'2010-03-24 19:41:00'),(2755082,23993,'2010-03-25 12:48:00'),(2756594,23993,'2010-03-25 19:57:00'),(2760077,23993,'2010-03-26 12:55:00'),(2761060,23993,'2010-03-26 20:41:00'),(2765504,23993,'2010-03-29 12:58:00'),(2766625,23993,'2010-03-29 20:16:00'),(2770138,23993,'2010-03-30 12:52:00'),(2771305,23993,'2010-03-30 20:14:00'),(2774547,23993,'2010-03-31 12:55:00'),(2776118,23993,'2010-03-31 19:49:00'),(2779327,23993,'2010-04-01 13:02:00'),(2780692,23993,'2010-04-01 19:54:00'),(2783620,23993,'2010-04-02 12:49:00'),(2784723,23993,'2010-04-02 19:52:00'),(2788387,23993,'2010-04-05 12:54:00'),(2789744,23993,'2010-04-05 19:51:00'),(2793046,23993,'2010-04-06 12:52:00'),(2794391,23993,'2010-04-06 20:07:00'),(2797691,23993,'2010-04-07 12:52:00'),(2801043,23993,'2010-04-07 19:58:00'),(2802262,23993,'2010-04-08 12:51:00'),(2803815,23993,'2010-04-08 19:58:00'),(2806924,23993,'2010-04-09 12:50:00'),(2808345,23993,'2010-04-09 20:00:00'),(2812651,23993,'2010-04-12 12:49:00'),(2814056,23993,'2010-04-12 20:31:00'),(2817196,23993,'2010-04-13 12:59:00'),(2818551,23993,'2010-04-13 19:51:00'),(2822004,23993,'2010-04-14 13:00:00'),(2823451,23993,'2010-04-14 19:54:00'),(2827061,23993,'2010-04-15 12:48:00'),(2828264,23993,'2010-04-15 20:24:00'),(2831694,23993,'2010-04-16 12:49:00'),(2832821,23993,'2010-04-16 20:19:00'),(2837031,23993,'2010-04-19 12:48:00'),(2838304,23993,'2010-04-19 20:05:00'),(2841755,23993,'2010-04-20 12:59:00'),(2842978,23993,'2010-04-20 20:20:00'),(2846195,23993,'2010-04-21 12:52:00'),(2847622,23993,'2010-04-21 19:58:00'),(2850762,23993,'2010-04-22 12:48:00'),(2852152,23993,'2010-04-22 19:55:00'),(2855605,23993,'2010-04-23 12:55:00'),(2857083,23993,'2010-04-23 20:25:00'),(2861116,23993,'2010-04-26 12:54:00'),(2862478,23993,'2010-04-26 19:57:00'),(2865937,23993,'2010-04-27 12:56:00'),(2869441,23993,'2010-04-27 20:00:00'),(2870911,23993,'2010-04-28 12:53:00'),(2872230,23993,'2010-04-28 20:03:00'),(2875559,23993,'2010-04-29 12:58:00'),(2876943,23993,'2010-04-29 19:57:00'),(2880167,23993,'2010-04-30 12:57:00'),(2881682,23993,'2010-04-30 19:55:00'),(2885744,23993,'2010-05-03 12:57:00'),(2887137,23993,'2010-05-03 19:57:00'),(2890563,23993,'2010-05-04 12:56:00'),(2891868,23993,'2010-05-04 20:09:00'),(2895228,23993,'2010-05-05 12:52:00'),(2896713,23993,'2010-05-05 19:54:00'),(2900026,23993,'2010-05-06 12:59:00'),(2901515,23993,'2010-05-06 20:00:00'),(2904720,23993,'2010-05-07 12:53:00'),(2906173,23993,'2010-05-07 19:58:00'),(2910649,23993,'2010-05-10 12:53:00'),(2912108,23993,'2010-05-10 20:30:00'),(2915231,23993,'2010-05-11 12:54:00'),(2918820,23993,'2010-05-11 20:08:00'),(2920064,23993,'2010-05-12 12:53:00'),(2921459,23993,'2010-05-12 20:02:00'),(2924910,23993,'2010-05-13 12:47:00'),(2926484,23993,'2010-05-13 20:00:00'),(2929614,23993,'2010-05-14 12:53:00'),(2931040,23993,'2010-05-14 19:48:00'),(2935329,23993,'2010-05-17 12:53:00'),(2936938,23993,'2010-05-17 19:52:00'),(2940377,23993,'2010-05-18 12:55:00'),(2941808,23993,'2010-05-18 20:02:00'),(2945120,23993,'2010-05-19 12:52:00'),(2946463,23993,'2010-05-19 20:07:00'),(2950115,23993,'2010-05-20 12:58:00'),(2951195,23993,'2010-05-20 20:57:00'),(2954457,23993,'2010-05-21 13:05:00'),(2955896,23993,'2010-05-21 20:05:00'),(2960102,23993,'2010-05-24 12:56:00'),(2961612,23993,'2010-05-24 19:58:00'),(2965192,23993,'2010-05-25 12:58:00'),(2966782,23993,'2010-05-25 20:06:00'),(2970082,23993,'2010-05-26 12:58:00'),(2972742,23993,'2010-05-26 19:45:00'),(2975308,23993,'2010-05-27 12:58:00'),(2976599,23993,'2010-05-27 20:05:00'),(2980126,23993,'2010-05-28 12:52:00'),(2983060,23993,'2010-05-28 20:15:00'),(2986470,23993,'2010-06-01 12:51:00'),(2988220,23993,'2010-06-01 19:55:00'),(2989427,23993,'2010-05-31 07:00:00'),(2992041,23993,'2010-06-02 12:56:00'),(2993399,23993,'2010-06-02 20:00:00'),(2997031,23993,'2010-06-03 12:52:00'),(2998892,23993,'2010-06-03 20:06:00'),(3002219,23993,'2010-06-04 12:54:00'),(3003466,23993,'2010-06-04 20:22:00'),(3008182,23993,'2010-06-07 12:58:00'),(3009727,23993,'2010-06-07 19:42:00'),(3013272,23993,'2010-06-08 12:52:00'),(3014817,23993,'2010-06-08 19:55:00'),(3018394,23993,'2010-06-09 12:57:00'),(3019891,23993,'2010-06-09 19:59:00'),(3025171,23993,'2010-06-10 12:54:00'),(3028585,23993,'2010-06-11 12:49:00'),(3029993,23993,'2010-06-11 19:57:00'),(3034715,23993,'2010-06-14 12:59:00'),(3036252,23993,'2010-06-14 19:58:00'),(3039933,23993,'2010-06-15 12:54:00'),(3041397,23993,'2010-06-15 20:12:00'),(3045275,23993,'2010-06-16 13:00:00'),(3046942,23993,'2010-06-16 20:29:00'),(3050534,23993,'2010-06-17 13:01:00'),(3051794,23993,'2010-06-17 20:34:00'),(3055172,23993,'2010-06-18 13:01:00'),(3056720,23993,'2010-06-18 19:56:00'),(3061197,23993,'2010-06-21 12:58:00'),(3063112,23993,'2010-06-21 20:07:00'),(3066434,23993,'2010-06-22 12:55:00'),(3068082,23993,'2010-06-22 19:59:00'),(3071752,23993,'2010-06-23 13:05:00'),(3073192,23993,'2010-06-23 20:00:00'),(3076791,23993,'2010-06-24 13:00:00'),(3078414,23993,'2010-06-24 19:51:00'),(3082136,23993,'2010-06-25 12:58:00'),(3083500,23993,'2010-06-25 20:03:00'),(3088294,23993,'2010-06-28 12:59:00'),(3089963,23993,'2010-06-28 19:52:00'),(3093509,23993,'2010-06-29 11:55:00'),(3098972,23993,'2010-06-30 12:53:00'),(3101961,23993,'2010-06-30 20:00:00'),(3104175,23993,'2010-07-01 12:59:00'),(3105732,23993,'2010-07-01 20:00:00'),(3116692,23993,'2010-07-06 12:56:00'),(3118216,23993,'2010-07-06 20:05:00'),(3121913,23993,'2010-07-07 12:58:00'),(3123477,23993,'2010-07-07 19:39:00'),(3127401,23993,'2010-07-08 12:58:00'),(3128891,23993,'2010-07-08 20:12:00'),(3132942,23993,'2010-07-09 12:52:00'),(3134007,23993,'2010-07-09 20:42:00'),(3139053,23993,'2010-07-12 12:53:00'),(3140454,23993,'2010-07-12 20:02:00'),(3144313,23993,'2010-07-13 13:01:00'),(3145967,23993,'2010-07-13 20:12:00'),(3149521,23993,'2010-07-14 12:58:00'),(3151326,23993,'2010-07-14 20:03:00'),(3154866,23993,'2010-07-15 13:00:00'),(3156597,23993,'2010-07-15 20:02:00'),(3160316,23993,'2010-07-16 12:52:00'),(3161745,23993,'2010-07-16 20:18:00'),(3166745,23993,'2010-07-19 12:59:00'),(3168504,23993,'2010-07-19 20:19:00'),(3171968,23993,'2010-07-20 12:53:00'),(3173524,23993,'2010-07-20 20:03:00'),(3177178,23993,'2010-07-21 12:53:00'),(3178958,23993,'2010-07-21 20:02:00'),(3182578,23993,'2010-07-22 12:53:00'),(3184154,23993,'2010-07-22 20:00:00'),(3187836,23993,'2010-07-23 12:58:00'),(3189349,23993,'2010-07-23 20:11:00'),(3194019,23993,'2010-07-26 12:57:00'),(3195665,23993,'2010-07-26 19:55:00'),(3199520,23993,'2010-07-27 12:56:00'),(3200905,23993,'2010-07-27 20:12:00'),(3205128,23993,'2010-07-28 12:53:00'),(3206323,23993,'2010-07-28 20:44:00'),(3210241,23993,'2010-07-29 12:54:00'),(3211803,23993,'2010-07-29 20:00:00'),(3215702,23993,'2010-07-30 12:55:00'),(3217223,23993,'2010-07-30 20:39:00'),(3222285,23993,'2010-08-02 12:55:00'),(3223739,23993,'2010-08-02 19:59:00'),(3227646,23993,'2010-08-03 12:57:00'),(3229111,23993,'2010-08-03 20:10:00'),(3232818,23993,'2010-08-04 12:49:00'),(3234411,23993,'2010-08-04 19:57:00'),(3238035,23993,'2010-08-05 12:59:00'),(3240013,23993,'2010-08-05 20:07:00'),(3243596,23993,'2010-08-06 12:53:00'),(3245009,23993,'2010-08-06 20:19:00'),(3249658,23993,'2010-08-09 12:51:00'),(3251269,23993,'2010-08-09 19:52:00'),(3255029,23993,'2010-08-10 12:48:00'),(3256695,23993,'2010-08-10 20:05:00'),(3260535,23993,'2010-08-11 12:42:00'),(3261993,23993,'2010-08-11 20:17:00'),(3266465,23993,'2010-08-12 12:46:00'),(3269560,23993,'2010-08-12 21:56:00'),(3271740,23993,'2010-08-13 19:09:00'),(3273440,23993,'2010-08-13 22:00:00'),(3277596,23993,'2010-08-16 12:42:00'),(3279314,23993,'2010-08-16 19:59:00'),(3283113,23993,'2010-08-17 12:51:00'),(3285121,23993,'2010-08-17 20:13:00'),(3288427,23993,'2010-08-18 12:42:00'),(3290038,23993,'2010-08-18 19:59:00'),(3293899,23993,'2010-08-19 12:48:00'),(3295284,23993,'2010-08-19 20:18:00'),(3299199,23993,'2010-08-20 12:48:00'),(3300588,23993,'2010-08-20 20:10:00'),(3311014,23993,'2010-08-24 12:53:00'),(3312520,23993,'2010-08-24 20:07:00'),(3316539,23993,'2010-08-25 12:58:00'),(3317951,23993,'2010-08-25 20:15:00'),(3321676,23993,'2010-08-26 12:49:00'),(3323427,23993,'2010-08-26 20:16:00'),(3327366,23993,'2010-08-27 12:53:00'),(3328876,23993,'2010-08-27 20:25:00'),(3334109,23993,'2010-08-30 12:48:00'),(3335877,23993,'2010-08-30 20:26:00'),(3339600,23993,'2010-08-31 12:45:00'),(3341546,23993,'2010-08-31 20:00:00'),(3345084,23993,'2010-09-01 12:50:00'),(3346855,23993,'2010-09-01 20:03:00'),(3350877,23993,'2010-09-02 12:50:00'),(3352613,23993,'2010-09-02 20:10:00'),(3356269,23993,'2010-09-03 12:51:00'),(3357832,23993,'2010-09-03 20:16:00'),(3363743,23993,'2010-09-07 12:48:00'),(3365739,23993,'2010-09-07 20:19:00'),(3369654,23993,'2010-09-08 12:47:00'),(3371170,23993,'2010-09-08 20:17:00'),(3375309,23993,'2010-09-09 12:52:00'),(3376852,23993,'2010-09-09 20:34:00'),(3380738,23993,'2010-09-10 12:54:00'),(3382399,23993,'2010-09-10 19:57:00'),(3387916,23993,'2010-09-13 12:59:00'),(3389671,23993,'2010-09-13 20:10:00'),(3393318,23993,'2010-09-14 12:48:00'),(3458072,23993,'2010-09-29 12:46:00'),(3459718,23993,'2010-09-29 20:19:00'),(3463925,23993,'2010-09-30 12:57:00'),(3465360,23993,'2010-09-30 20:41:00'),(3469491,23993,'2010-10-01 12:43:00'),(3470950,23993,'2010-10-01 20:06:00'),(3476182,23993,'2010-10-04 12:52:00'),(3478024,23993,'2010-10-04 20:03:00'),(3481803,23993,'2010-10-05 12:56:00'),(3483447,23993,'2010-10-05 20:15:00'),(3487220,23993,'2010-10-06 12:58:00'),(3489232,23993,'2010-10-06 19:51:00'),(3492864,23993,'2010-10-07 12:59:00'),(3494625,23993,'2010-10-07 20:12:00'),(3498496,23993,'2010-10-08 12:57:00'),(3499923,23993,'2010-10-08 20:05:00'),(3505148,23993,'2010-10-11 12:51:00'),(3506647,23993,'2010-10-11 20:03:00'),(3510464,23993,'2010-10-12 12:51:00'),(3512249,23993,'2010-10-12 19:54:00'),(3516300,23993,'2010-10-13 12:56:00'),(3518077,23993,'2010-10-13 19:59:00'),(3522236,23993,'2010-10-14 12:54:00'),(3523774,23993,'2010-10-14 20:14:00'),(3527715,23993,'2010-10-15 12:58:00'),(3529528,23993,'2010-10-15 19:45:00'),(3534555,23993,'2010-10-18 12:58:00'),(3536566,23993,'2010-10-18 19:52:00'),(3540294,23993,'2010-10-19 12:59:00'),(3542014,23993,'2010-10-19 20:09:00'),(3545860,23993,'2010-10-20 13:00:00'),(3547807,23993,'2010-10-20 19:50:00'),(3551554,23993,'2010-10-21 12:59:00'),(3553649,23993,'2010-10-21 19:59:00'),(3557174,23993,'2010-10-22 13:01:00'),(3559145,23993,'2010-10-22 19:53:00'),(3564361,23993,'2010-10-25 12:55:00'),(3566296,23993,'2010-10-25 20:36:00'),(3570031,23993,'2010-10-26 12:55:00'),(3571857,23993,'2010-10-26 20:07:00'),(3575728,23993,'2010-10-27 12:56:00'),(3577618,23993,'2010-10-27 19:50:00'),(3581282,23993,'2010-10-28 12:55:00'),(3583282,23993,'2010-10-28 19:53:00'),(3587147,23993,'2010-10-29 12:54:00'),(3589175,23993,'2010-10-29 20:08:00'),(3594055,23993,'2010-11-01 13:03:00'),(3599658,23993,'2010-11-02 12:56:00'),(3601602,23993,'2010-11-02 20:05:00'),(3605346,23993,'2010-11-03 12:55:00'),(3607031,23993,'2010-11-03 19:56:00'),(3610880,23993,'2010-11-04 12:56:00'),(3612485,23993,'2010-11-04 20:00:00'),(3616724,23993,'2010-11-05 12:57:00'),(3618882,23993,'2010-11-05 20:11:00'),(3624271,23993,'2010-11-08 13:55:00'),(3626322,23993,'2010-11-08 21:04:00'),(3629984,23993,'2010-11-09 13:49:00'),(3631715,23993,'2010-11-09 21:05:00'),(3635835,23993,'2010-11-10 13:50:00'),(3637717,23993,'2010-11-10 20:54:00'),(3641522,23993,'2010-11-11 13:57:00'),(3643232,23993,'2010-11-11 20:56:00'),(3646931,23993,'2010-11-12 14:00:00'),(3648883,23993,'2010-11-12 21:00:00'),(3659841,23993,'2010-11-16 13:48:00'),(3661745,23993,'2010-11-16 21:01:00'),(3665973,23993,'2010-11-17 13:57:00'),(3667615,23993,'2010-11-17 21:11:00'),(3671710,23993,'2010-11-18 13:51:00'),(3673541,23993,'2010-11-18 20:58:00'),(3677552,23993,'2010-11-19 13:53:00'),(3679496,23993,'2010-11-19 20:59:00'),(3685193,23993,'2010-11-22 13:57:00'),(3687616,23993,'2010-11-22 20:56:00'),(3691595,23993,'2010-11-23 13:54:00'),(3693385,23993,'2010-11-23 20:55:00'),(3697502,23993,'2010-11-24 13:55:00'),(3699532,23993,'2010-11-24 21:10:00'),(3706713,23993,'2010-11-29 13:56:00'),(3708787,23993,'2010-11-29 21:15:00'),(3713164,23993,'2010-11-30 13:56:00'),(3714766,23993,'2010-11-30 21:37:00'),(3719059,23993,'2010-12-01 13:54:00'),(3720971,23993,'2010-12-01 21:08:00'),(3725049,23993,'2010-12-02 13:57:00'),(3726769,23993,'2010-12-02 21:14:00'),(3730527,23993,'2010-12-03 13:56:00'),(3732449,23993,'2010-12-03 20:46:00'),(3737875,23993,'2010-12-06 13:58:00'),(3739666,23993,'2010-12-06 20:51:00'),(3743504,23993,'2010-12-07 13:55:00'),(3745499,23993,'2010-12-07 20:58:00'),(3749580,23993,'2010-12-08 13:57:00'),(3751225,23993,'2010-12-08 21:26:00'),(3755203,23993,'2010-12-09 13:55:00'),(3757191,23993,'2010-12-09 21:05:00'),(3760849,23993,'2010-12-10 13:57:00'),(3762715,23993,'2010-12-10 20:53:00'),(3767759,23993,'2010-12-13 13:53:00'),(3769642,23993,'2010-12-13 20:58:00'),(3773833,23993,'2010-12-14 13:55:00'),(3775739,23993,'2010-12-14 21:03:00'),(3779769,23993,'2010-12-15 13:55:00'),(3781618,23993,'2010-12-15 21:17:00'),(3785684,23993,'2010-12-16 13:54:00'),(3787700,23993,'2010-12-16 21:04:00'),(3791412,23993,'2010-12-17 13:58:00'),(3793333,23993,'2010-12-17 21:09:00'),(3799018,23993,'2010-12-20 13:54:00'),(3800969,23993,'2010-12-20 21:35:00'),(3804066,23993,'2010-12-21 13:57:00'),(3806086,23993,'2010-12-21 21:07:00'),(3810651,23993,'2010-12-22 13:59:00'),(3812010,23993,'2010-12-22 21:57:00'),(3816125,23993,'2010-12-23 13:58:00'),(3817893,23993,'2010-12-23 20:53:00'),(3828023,23993,'2010-12-28 13:54:00'),(3829729,23993,'2010-12-28 20:52:00'),(3833422,23993,'2010-12-29 13:57:00'),(3835179,23993,'2010-12-29 21:04:00'),(3838809,23993,'2010-12-30 14:11:00'),(3840529,23993,'2010-12-30 21:09:00'),(3847084,23993,'2011-01-03 13:56:00'),(3849214,23993,'2011-01-03 21:13:00'),(3853369,23993,'2011-01-04 13:55:00'),(3855200,23993,'2011-01-04 21:17:00'),(3859575,23993,'2011-01-05 13:56:00'),(3861928,23993,'2011-01-05 21:09:00'),(3865532,23993,'2011-01-06 13:55:00'),(3867607,23993,'2011-01-06 21:10:00'),(3871468,23993,'2011-01-07 13:49:00'),(3873372,23993,'2011-01-07 21:01:00'),(3879150,23993,'2011-01-10 13:53:00'),(3880787,23993,'2011-01-10 21:26:00'),(3884726,23993,'2011-01-11 13:56:00'),(3886430,23993,'2011-01-11 20:50:00'),(3890671,23993,'2011-01-12 13:56:00'),(3892583,23993,'2011-01-12 21:08:00'),(3897017,23993,'2011-01-13 13:56:00'),(3898783,23993,'2011-01-13 21:14:00'),(3902776,23993,'2011-01-14 13:52:00'),(3905051,23993,'2011-01-14 20:53:00'),(3910107,23993,'2011-01-17 13:53:00'),(3911875,23993,'2011-01-17 21:07:00');
/*!40000 ALTER TABLE `records` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Dumping routines for database 'test'
--
/*!50003 DROP FUNCTION IF EXISTS `ConvertGMTDateToLocalDate` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = latin1 */ ;
/*!50003 SET character_set_results = latin1 */ ;
/*!50003 SET collation_connection = latin1_swedish_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = '' */ ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50020 DEFINER=`root`@`%`*/ /*!50003 FUNCTION `ConvertGMTDateToLocalDate`(
WorkDate datetime,
TimezoneOffset decimal(3,1),
DSTEnabled tinyint(3) unsigned,
TimezoneDSTOffset decimal(3,1)
) RETURNS datetime
DETERMINISTIC
BEGIN

DECLARE LocalDateTime datetime;
DECLARE DSTStart datetime;
DECLARE DSTEnd datetime;
DECLARE TimezoneOffsetHour int;
DECLARE TimezoneOffsetMinute int;
DECLARE TimezoneDSTOffsetHour int;
DECLARE TimezoneDSTOffsetMinute int;

IF ( TimezoneOffset < 0 )
THEN
SET TimezoneOffsetHour = CEILING(TimezoneOffset);
SET TimezoneOffsetMinute = ABS(60 * (TimezoneOffset - CEILING(TimezoneOffset)));
ELSE
SET TimezoneOffsetHour = FLOOR(TimezoneOffset);
SET TimezoneOffsetMinute = ABS(60 * (TimezoneOffset - FLOOR(TimezoneOffset)));
END IF;

IF ( TimezoneDSTOffset < 0 )
THEN
SET TimezoneDSTOffsetHour = CEILING(TimezoneDSTOffset);
SET TimezoneDSTOffsetMinute = ABS(60 * (TimezoneDSTOffset - CEILING(TimezoneDSTOffset)));
ELSE
SET TimezoneDSTOffsetHour = FLOOR(TimezoneDSTOffset);
SET TimezoneDSTOffsetMinute = ABS(60 * (TimezoneDSTOffset - FLOOR(TimezoneDSTOffset)));
END IF;

IF ( DSTEnabled = 1 )
THEN
SET DSTStart = GetDaylightSavingTimeStart(YEAR(WorkDate));
SET DSTEnd = GetDaylightSavingTimeEnd(YEAR(WorkDate));

SET DSTStart = STR_TO_DATE(CONCAT(YEAR(DSTStart),'-',MONTH(DSTStart),'-',DAY(DSTStart),'-',ABS(TimezoneOffsetHour)+2,'-',TimezoneOffsetMinute,'-0'),'%Y-%m-%d-%H-%i-%s');
SET DSTEnd = STR_TO_DATE(CONCAT(YEAR(DSTEnd),'-',MONTH(DSTEnd),'-',DAY(DSTEnd),'-',ABS(TimezoneDSTOffsetHour)+2,'-',TimezoneDSTOffsetMinute,'-0'),'%Y-%m-%d-%H-%i-%s');

IF ( WorkDate >= DSTStart AND WorkDate < DSTEnd )
THEN
SET LocalDateTime = DATE_ADD(WorkDate,INTERVAL CONCAT(TimezoneDSTOffsetHour,':',TimezoneDSTOffsetMinute) HOUR_MINUTE);
ELSE
SET LocalDateTime = DATE_ADD(WorkDate,INTERVAL CONCAT(TimezoneOffsetHour,':',TimezoneOffsetMinute) HOUR_MINUTE);
END IF;
ELSE
SET LocalDateTime = DATE_ADD(WorkDate,INTERVAL CONCAT(TimezoneOffsetHour,':',TimezoneOffsetMinute) HOUR_MINUTE);
END IF;

RETURN LocalDateTime;

END */;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `GetDaylightSavingTimeEnd` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8 */ ;
/*!50003 SET character_set_results = utf8 */ ;
/*!50003 SET collation_connection = utf8_general_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = '' */ ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50020 DEFINER=`root`@`%`*/ /*!50003 FUNCTION `GetDaylightSavingTimeEnd`(
TheYear int
) RETURNS date
DETERMINISTIC
BEGIN

DECLARE TheEndDate date;
DECLARE LastSunday int;

IF ( TheYear < 2007 )
THEN
SET LastSunday = GetNthOccOfDayInMonth(5,1,10,TheYear);
IF ( LastSunday <= -1 )
THEN
SET TheEndDate = STR_TO_DATE(CONCAT(TheYear,'-10-',GetNthOccOfDayInMonth(4,1,10,TheYear)),'%Y-%m-%d');
ELSE
SET TheEndDate = STR_TO_DATE(CONCAT(TheYear,'-10-',LastSunday),'%Y-%m-%d');
END IF;
ELSE
SET TheEndDate = STR_TO_DATE(CONCAT(TheYear,'-11-',GetNthOccOfDayInMonth(1,1,11,TheYear)),'%Y-%m-%d');
END IF;

RETURN TheEndDate;

END */;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `GetDaylightSavingTimeStart` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8 */ ;
/*!50003 SET character_set_results = utf8 */ ;
/*!50003 SET collation_connection = utf8_general_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = '' */ ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50020 DEFINER=`root`@`%`*/ /*!50003 FUNCTION `GetDaylightSavingTimeStart`(
TheYear int
) RETURNS date
DETERMINISTIC
BEGIN

DECLARE TheStartDate date;

IF ( TheYear < 2007 )
THEN
SET TheStartDate = STR_TO_DATE(CONCAT(TheYear,'-4-',GetNthOccOfDayInMonth(1,1,4,TheYear)),'%Y-%m-%d');
ELSE
SET TheStartDate = STR_TO_DATE(CONCAT(TheYear,'-3-',GetNthOccOfDayInMonth(2,1,3,TheYear)),'%Y-%m-%d');
END IF;

RETURN TheStartDate;

END */;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `GetNthOccOfDayInMonth` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8 */ ;
/*!50003 SET character_set_results = utf8 */ ;
/*!50003 SET collation_connection = utf8_general_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = '' */ ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50020 DEFINER=`root`@`%`*/ /*!50003 FUNCTION `GetNthOccOfDayInMonth`(
NthOccurrence int,
TheDayOfWeek int,
TheMonth tinyint,
TheYear int
) RETURNS int(11)
DETERMINISTIC
BEGIN
DECLARE TheDayInMonth int(11);
DECLARE DateToTest date;
DECLARE DayOfWeekToTest int(11);

SET TheDayInMonth = 0;
SET DateToTest = STR_TO_DATE(CONCAT(TheYear,'-',TheMonth,'-',1),'%Y-%m-%d');
SET DayOfWeekToTest = DAYOFWEEK(DateToTest);

IF ( TheDayOfWeek < DayOfWeekToTest )
THEN
SET TheDayInMonth = (1 + (NthOccurrence*7) + ((TheDayOfWeek-DayOfWeekToTest) % 7));
ELSE
SET TheDayInMonth = (1 + ((NthOccurrence-1)*7) + ((TheDayOfWeek-DayOfWeekToTest) % 7));
END IF;

IF ( TheDayInMonth > DAY(LAST_DAY(DateToTest)) OR TheDayInMonth < 1 )
THEN
RETURN -1;
ELSE
RETURN TheDayInMonth;
END IF;

END */;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2011-01-30 23:18:32

Options: ReplyQuote


Subject
Views
Written By
Posted
4002
January 26, 2011 02:59PM
1535
January 27, 2011 02:35PM
1615
January 27, 2011 10:59PM
2060
January 28, 2011 01:38PM
1396
January 30, 2011 07:20PM
Re: Query Takes Longer Each Time Its Run
1450
January 31, 2011 01:22AM
1556
January 31, 2011 01:25AM
1401
February 01, 2011 12:38AM
1519
February 01, 2011 12:56AM
1470
February 01, 2011 01:23PM
1703
February 01, 2011 08:41PM
2209
February 03, 2011 02:04PM
1667
February 15, 2011 09:24PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.