Tuesday, June 5, 2012

Re: Optimize cakephp 1.3 for models with containable

sql dump for first case:

<table class="cake-sql-log" id="cakeSqlLog_13389350054fce86dd2f3f75_31179595" summary="Cake SQL Log" cellspacing="0" border="0"><caption>(default) 12 queries took 6 ms</caption> <thead>
<tr><th>Nr</th><th>Query</th><th>Error</th><th>Affected</th><th>Num. rows</th><th>Took (ms)</th></tr>
</thead>
<tbody>
<tr><td>1</td><td>EXPLAIN SELECT `Aro`.`id`, `Aro`.`parent_id`, `Aro`.`model`, `Aro`.`foreign_key`, `Aro`.`alias` FROM `aros` AS `Aro` LEFT JOIN `aros` AS `Aro0` ON (`Aro`.`lft` &lt;= `Aro0`.`lft` AND `Aro`.`rght` &gt;= `Aro0`.`rght`)  WHERE `Aro0`.`model` = 'Group' AND `Aro0`.`foreign_key` = 7   ORDER BY `Aro`.`lft` DESC </td><td></td><td style="text-align: right">2</td><td style="text-align: right">2</td><td style="text-align: right">0</td></tr>
<tr><td>2</td><td>EXPLAIN SELECT `Aco`.`id`, `Aco`.`parent_id`, `Aco`.`model`, `Aco`.`foreign_key`, `Aco`.`alias` FROM `acos` AS `Aco` LEFT JOIN `acos` AS `Aco0` ON (`Aco0`.`alias` = 'controllers') LEFT JOIN `acos` AS `Aco1` ON (`Aco1`.`lft` &gt; `Aco0`.`lft` AND `Aco1`.`rght` &lt; `Aco0`.`rght` AND `Aco1`.`alias` = 'Documents' AND `Aco0`.`id` = `Aco1`.`parent_id`) LEFT JOIN `acos` AS `Aco2` ON (`Aco2`.`lft` &gt; `Aco1`.`lft` AND `Aco2`.`rght` &lt; `Aco1`.`rght` AND `Aco2`.`alias` = 'buildingPrintList' AND `Aco1`.`id` = `Aco2`.`parent_id`)  WHERE ((`Aco`.`lft` &lt;= `Aco0`.`lft` AND `Aco`.`rght` &gt;= `Aco0`.`rght`) OR (`Aco`.`lft` &lt;= `Aco2`.`lft` AND `Aco`.`rght` &gt;= `Aco2`.`rght`))   ORDER BY `Aco`.`lft` DESC </td><td></td><td style="text-align: right">4</td><td style="text-align: right">4</td><td style="text-align: right">0</td></tr>
<tr><td>3</td><td>EXPLAIN SELECT `Permission`.`id`, `Permission`.`aro_id`, `Permission`.`aco_id`, `Permission`.`_create`, `Permission`.`_read`, `Permission`.`_update`, `Permission`.`_delete`, `Aro`.`id`, `Aro`.`parent_id`, `Aro`.`model`, `Aro`.`foreign_key`, `Aro`.`alias`, `Aro`.`lft`, `Aro`.`rght`, `Aco`.`id`, `Aco`.`parent_id`, `Aco`.`model`, `Aco`.`foreign_key`, `Aco`.`alias`, `Aco`.`lft`, `Aco`.`rght` FROM `aros_acos` AS `Permission` LEFT JOIN `aros` AS `Aro` ON (`Permission`.`aro_id` = `Aro`.`id`) LEFT JOIN `acos` AS `Aco` ON (`Permission`.`aco_id` = `Aco`.`id`)  WHERE `Permission`.`aro_id` = 6 AND `Permission`.`aco_id` IN (183, 181, 1)   ORDER BY `Aco`.`lft` desc </td><td></td><td style="text-align: right">3</td><td style="text-align: right">3</td><td style="text-align: right">0</td></tr>
<tr><td>4</td><td>EXPLAIN SELECT `Building`.`id`, `Building`.`country`, `Building`.`city`, `Building`.`district`, `Building`.`street`, `Building`.`street_number`, `Building`.`post_code`, `Building`.`notes`, `Building`.`address_id`, `Building`.`immovable_id`, `Building`.`land_id`, `Building`.`latitude`, `Building`.`longitude`, `Building`.`modified`, `Building`.`created`, (CONCAT(`Building`.`street`, " ", `Building`.`street_number`)) AS  `Building__street_name`, (SELECT COUNT(*) FROM apartaments where `apartaments`.`building_id` = `Building`.`id`) AS  `Building__apartaments_count`, (SELECT COUNT(*) FROM person_apartaments left join people on `person_apartaments`.`person_id`=`people`.`id` where `person_apartaments`.`building_id` = `Building`.`id` AND `people`.`member_id` &gt; 0 ) AS  `Building__members_count`, (SELECT COUNT(*) FROM person_apartaments left join people on `person_apartaments`.`person_id`=`people`.`id` where `person_apartaments`.`building_id` = `Building`.`id` AND `people`.`member_id` &lt; 0 ) AS  `Building__not_members_count` FROM `buildings` AS `Building`   WHERE `Building`.`id` IN (2036, 2022, 2024, 2026, 2033, 2032, 2031, 2030, 2023, 2029, 2027, 2021, 2028, 2035, 2034, 2025)   </td><td></td><td style="text-align: right">6</td><td style="text-align: right">6</td><td style="text-align: right">0</td></tr>
<tr><td>5</td><td>EXPLAIN SELECT `Apartament`.`id`, `Apartament`.`name`, `Apartament`.`persons`, `Apartament`.`area`, `Apartament`.`number`, `Apartament`.`type`, `Apartament`.`right`, `Apartament`.`notes`, `Apartament`.`building_id`, `Apartament`.`rent_id` FROM `apartaments` AS `Apartament`   WHERE `Apartament`.`building_id` IN (2021, 2022, 2023, 2024, 2025, 2026, 2027, 2028, 2029, 2030, 2031, 2032, 2033, 2034, 2035, 2036)   ORDER BY `Apartament`.`number` + 0 asc, `Apartament`.`number` desc </td><td></td><td style="text-align: right">1</td><td style="text-align: right">1</td><td style="text-align: right">0</td></tr>
<tr><td>6</td><td>EXPLAIN SELECT `Person`.`id`, `Person`.`name`, `Person`.`surname`, `Person`.`member_id`, `Person`.`document_id`, `Person`.`gender`, `Person`.`street`, `Person`.`street_number`, `Person`.`apartament_number`, `Person`.`post_code`, `Person`.`city`, `Person`.`country`, `Person`.`notes`, `Person`.`is_verified`, `Person`.`verified_date`, `Person`.`is_member`, `Person`.`is_representative`, `Person`.`is_law`, `Person`.`address_id`, `Person`.`representative_id22`, `Person`.`couple_id`, `Person`.`modified`, `Person`.`created`, (CONCAT(`Person`.`name`, " ", `Person`.`surname`)) AS  `Person__full_name`, `PersonApartament`.`id`, `PersonApartament`.`apartament_id`, `PersonApartament`.`person_id`, `PersonApartament`.`building_id`, `PersonApartament`.`apartaments_right_id`, `PersonApartament`.`is_corespondency`, `PersonApartament`.`notes`, `PersonApartament`.`type` FROM `people` AS `Person` JOIN `person_apartaments` AS `PersonApartament` ON (`PersonApartament`.`apartament_id` IN (3462, 3463, 3465, 3466, 3467, 3468, 3469, 3470, 3471, 3472, 3473, 3474, 3475, 3480, 2565, 2321, 2864, 2105, 2370, 3425, 2165, 3456, 2945, 2179, 3459, 3460, 2485, 3011, 3287, 2031, 2572, 2322, 2076, 2865, 2644, 3167, 2946, 2180, 2950, 2470, 2486, 3025, 2514, 3297, 2032, 2573, 2077, 2361, 2875, 2645, 3168, 2181, 2951, 2471, 2510, 3026, 2515, 2782, 3298, 2033, 2323, 2078, 2876, 2636, 2646, 3169, 2182, 2487, 3012, 3027, 2516, 2783, 3299, 2034, 2574, 2324, 2079, 2866, 2877, 2647, 2183, 2952, 2488, 3028, 2517, 3288, 3300, 2035, 2575, 2325, 2080, 2878, 2648, 3170, 2184, 2953, 2489, 3029, 2518, 2784, 3301, 2036, 2309, 2576, 2081, 2362, 2879, 2649, 3171, 2954, 2490, 3030, 2519, 2785, 3302, 2037, 2577, 2326, 2082, 2880, 2650, 3172, 2185, 2955, 2491, 3031, 2520, 2786, 3303, 2038, 2578, 2327, 2083, 2881, 2115, 2371, 2651, 3173, 2186, 2492, 3013, 3032, 2521, 2787, 3304, 2039, 2579, 2084, 2363, 2882, 2116, 2372, 2652, 3174, 2187, 2956, 2493, 3033, 2522, 2788, 3305, 2040, 2580, 2328, 2085, 2883, 2373, 2653, 3175, 2188, 2957, 2494, 3034, 2523, 2789, 3306, 2041, 2310, 2581, 2329, 2086, 2867, 2884, 2117, 2374, 2654, 3176, 2495, 3014, 3035, 2524, 3307, 2042, 2582, 2330, 2087, 2885, 2655, 3177, 2189, 2958, 2472, 2496, 2525, 2790, 3308, 2043, 2583, 2331, 2112, 2886, 3155, 3178, 2190, 2473, 2497, 3015, 2770, 2526, 2791, 3309, 2044, 2332, 2088, 2375, 2887, 2637, 2656, 2191, 3016, 2511, 3289, 3036, 2527, 2792, 3310, 2045, 2584, 2073, 2333, 2089, 2376, 2888, 2657, 3426, 3179, 2959, 2192, 2498, 3037, 2528, 2793, 2566, 2585, 2334, 2090, 2377, 2889, 2658, 3180, 2960, 2193, 2499, 3038, 2794, 3311, 2046, 2567, 2586, 2335, 2091, 2378, 2890, 3181, 3454, 2961, 2194, 2771, 3039, 2795, 2047, 2048, 2587, 2336, 2092, 2379, 2891, 2659, 2195, 2500, 3017, 3290, 3040, 2529, 2796, 3312, 2049, 2588, 2337, 2113, 2118, 2892, 2660, 3182, 2962, 2196, 2474, 2501, 3041, 2530, 2797, 3313, 2050, 2338, 2114, 2119, 2380, 2893, 2638, 2661, 3183, 2963, 2197, 2502, 3042, 2531, 3314, 2051, 2589, 2093, 2364, 2120, 2894, 2662, 3184, 2198, 2475, 2503, 3018, 3043, 2532, 2798, 3315, 2052, 2590, 2094, 2365, 2121, 2381, 2895, 3427, 2663, 3185, 2964, 2199, 2512, 3044, 2533, 2799, 2053, 2591, 2339, 2095, 2122, 2382, 2896, 3156, 3186, 3457, 2965, 2200, 2504, 2534, 2800, 3316, 2054, 2592, 2340, 2096, 2868, 2383, 2897, 2664, 3187, 2166, 2966, 2201, 2505, 3045, 2535, 3317, 2055, 2593, 2341, 2097, 2384, 2898, 2665, 3188, 2167, 2967, 2202, 2513, 3046, 2536, 2801, 3318, 2056, 2594, 2342, 2098, 2123, 2385, 2899, 2666, 3189, 2968, 2203, 2506, 3047, 2537, 2802, 3319, 2311, 2057, 2595, 2343, 2099, 2124, 2386, 2900, 2667, 3190, 2969, 2507, 3048, 2538, 2803, 3320, 2312, 2568, 2058, 2596, 2344, 2110, 2387, 2901, 2668, 3191, 2168, 3019, 2508, 3049, 3321, 2059, 2597, 2345, 2100, 2125, 2388, 2669, 3192, 2947, 2970, 2204, 3050, 2539, 2804, 3322, 2060, 2346, 2101, 2126, 2639, 2389, 2902, 2670, 3193, 2971, 2205, 3051, 2540, 2805, 3323, 2061, 2598, 2347, 2102, 2390, 2903, 2671, 2170, 3194, 2972, 2206, 3052, 2541, 2806, 3324, 2569, 2062, 2599, 2348, 2103, 2127, 2391, 2904, 3428, 2672, 3195, 2973, 2207, 3053, 2807, 2063, 2600, 2349, 2869, 2104, 2128, 2392, 2905, 2673, 3196, 2974, 2208, 2542, 3054, 3325, 2064, 2601, 2350, 2111, 2129, 2393, 2906, 2674, 3197, 2975, 2209, 2543, 3055, 2808, 3326, 2074, 2602, 2351, 2130, 2394, 2907, 2675, 3198, 2976, 2210, 2544, 3056, 2809, 3327, 3328, 2065, 2603, 2352, 2131, 2395, 2908, 2676, 3199, 2977, 2211, 2545, 3057, 2810, 3329, 2066, 2604, 2353, 2132, 2909, 2978, 2212, 2476, 2772, 2546, 3058, 2811, 3330, 2075, 2605, 2354, 2870, 2133, 2396, 2910, 2677, 3200, 2979, 2213, 2547, 3059, 2067, 2606, 2355, 2134, 2397, 2911, 3429, 2678, 3201, 2980, 2214, 2548, 3060, 2812, 3331, 2068, 2607, 2356, 2135, 2398, 2912, 3202, 2981, 2215, 2549, 3061, 2813, 3332, 2069, 2608, 2357, 2136, 2399, 2913, 2679, 3203, 2982, 2216, 2550, 3062, 2814, 3333, 2070, 2609, 2358, 2871, 2137, 2400, 2914, 2680, 3204, 2983, 2217, 2551, 3063, 3334, 2071, 2366, 2640, 2138, 2401, 2915, 2681, 3205, 2984, 2218, 3064, 2815, 2816, 3335, 2072, 2610, 2367, 2402, 2916, 2682, 2171, 3206, 2985, 2219, 2552, 3065, 2817, 2611, 2359, 2139, 2403, 2917, 3430, 3207, 2986, 2220, 2553, 3066, 2818, 3336, 2313, 2570, 2612, 2360, 2140, 2404, 2918, 2683, 3208, 2987, 3067, 2819, 3337, 2314, 2613, 2368, 2141, 2405, 2919, 2684, 3209, 2988, 2554, 3068, 2820, 3338, 2614, 2142, 2406, 2920, 2685, 3210, 2221, 2989, 2555, 3069, 2821, 2571, 3339, 2615, 2143, 2407, 2921, 2686, 3211, 2222, 2990, 3070, 2822, 3340, 2616, 2144, 2408, 2922, 2687, 3212, 2223, 2991, 2556, 3071, 3072, 2872, 2617, 2145, 3431, 2409, 2923, 2688, 3213, 2224, 2992, 2557, 3073, 2823, 3341, 2618, 2146, 2410, 2924, 2689, 3214, 2225, 3020, 2558, 3074, 3342, 2873, 2619, 2147, 2411, 2925, 2690, 3215, 2993, 2226, 2559, 2560, 3075, 3343, 2874, 2641, 2148, 2412, 2926, 2691, 3216, 2994, 2227, 2561, 3076, 2824, 3344, 2620, 2149, 2413, 2692, 2948, 3217, 2995, 2228, 2562, 3077, 2825, 3345, 2642, 2150, 2414, 2927, 2693, 3218, 2996, 2229, 2563, 3078, 2826, 2320, 3346, 2621, 2151, 2415, 2928, 2694, 3219, 2997, 2564, 3079, 2827, 3347, 2622, 2416, 2929, 2172, 2695, 3220, 2230, 2998, 3080, 2828, 3348, 2623, 2152, 2417, 2696, 3221, 2231, 2999, 3081, 2829, 3349, 2624, 2153, 2418, 2930, 2697, 3222, 2232, 3000, 3082, 2830, 3350, 2625, 2154, 2419, 2698, 3223, 2233, 3001, 2315, 3083, 2831, 3351, 2626, 2155, 2931, 2420, 2699, 3224, 3002, 2773, 2832, 2627, 3432, 2421, 2173, 2949, 2700, 2234, 3003, 3291, 3084, 2833, 3352, 2628, 2156, 2932, 2422, 2701, 3225, 2235, 3021, 3085, 2834, 3353, 2629, 2157, 2933, 2423, 2702, 3226, 2236, 3004, 3086, 2835, 3354, 2630, 2158, 2934, 2424, 2703, 3227, 2237, 3005, 2836, 3355, 2631, 3157, 2159, 2935, 2425, 2704, 3228, 2238, 3006, 2837, 3356, 2643, 2160, 2936, 2426, 2705, 3229, 2239, 3007, 2838, 3357, 2632, 3158, 2937, 2427, 2174, 2706, 3230, 2240, 3022, 3087, 2839, 3358, 2633, 2161, 2938, 2428, 2707, 3231, 3008, 2241, 3088, 2840, 2634, 3433, 2162, 2939, 2429, 2708, 3232, 2242, 3023, 3089, 2841, 3359, 2635, 2940, 2430, 2175, 3455, 2709, 3233, 2243, 3090, 2842, 3360, 2941, 2431, 2176, 2710, 3234, 3009, 2244, 3091, 2843, 3361, 2163, 2942, 2432, 2711, 3235, 2245, 3024, 3092, 2844, 3362, 2164, 2943, 2433, 3010, 2246, 3292, 3093, 2845, 3363, 2944, 2177, 2434, 2712, 3236, 2247, 3094, 2846, 3364, 2178, 2435, 2713, 3237, 2248, 3095, 2847, 3365, 2436, 2714, 3238, 2249, 3096, 2848, 3366, 2437, 3239, 2250, 3097, 2849, 3367, 3240, 2477, 2251, 2774, 3098, 2850, 3368, 2438, 2715, 3241, 2252, 3099, 2851, 3369, 2439, 2716, 3242, 2253, 3100, 2852, 3434, 2440, 2717, 3243, 2254, 3101, 2853, 3370, 2441, 2718, 3244, 2255, 3102, 2854, 3371, 2442, 2719, 3245, 2256, 3103, 2855, 3372, 2443, 3246, 2257, 2775, 3104, 2856, 3373, 2444, 2720, 3247, 2258, 3105, 2857, 3374, 2445, 2721, 3248, 2259, 2858, 3375, 3458, 2446, 2722, 3249, 2260, 3106, 2859, 3435, 2447, 2723, 3250, 2261, 3107, 2860, 3376, 2724, 2478, 2262, 3293, 3108, 2861, 3377, 2448, 2725, 3251, 2263, 3109, 2862, 3378, 2726, 2479, 3252, 2264, 3110, 2863, 3379, 2449, 3253, 2265, 3380, 3159, 2450, 2727, 2266, 3294, 3111, 3381, 2451, 2728, 3254, 2267, 3112, 3382, 2452, 2729, 3255, 2268, 3113, 3383, 2453, 3256, 2776, 2269, 3114, 3384, 2730, 2480, 3257, 2270, 3385, 3160, 2454, 3258, 2777, 2271, 3386, 3161, 2455, 2731, 3259, 2272, 2316, 3115, 3436, 2456, 2732, 3260, 3116, 3387, 2457, 2733, 2273, 3117, 3388, 2458, 2734, 3295, 2274, 3118, 3389, 2735, 2481, 3261, 2275, 3119, 3390, 2736, 2482, 3262, 2276, 3120, 3391, 2459, 2737, 3263, 2277, 3121, 3392, 2460, 2738, 3264, 2278, 3122, 3437, 2461, 2739, 3265, 2279, 3123, 3393, 2462, 2740, 3266, 2280, 3124, 3394, 2483, 2741, 3267, 2281, 3125, 3395, 2463, 2742, 3268, 2282, 3126, 3396, 2484, 3269, 2778, 2283, 3127, 3397, 2464, 2743, 3270, 2284, 3398, 3162, 2465, 2744, 3271, 2285, 2317, 3128, 3438, 2466, 2745, 3272, 3129, 3399, 2467, 2746, 3273, 2286, 3130, 3439, 2468, 2747, 3274, 2287, 3131, 3400, 2469, 2748, 3275, 2288, 3132, 3401, 2749, 3296, 2289, 2318, 3163, 3440, 2750, 3276, 3133, 3402, 2751, 3277, 2290, 3134, 3403, 2752, 3278, 2291, 3135, 3404, 2753, 3279, 2292, 3136, 3405, 2754, 3280, 2293, 3137, 3441, 3281, 2779, 2294, 3138, 3406, 2755, 3282, 2295, 3139, 3407, 2756, 3283, 2296, 3140, 3408, 3284, 2297, 3409, 2757, 3285, 2298, 3141, 3410, 2758, 2299, 3142, 3411, 2759, 3286, 2300, 3143, 3412, 2760, 2301, 3144, 3413, 2761, 2302, 2319, 3145, 3461, 2762, 3146, 3414, 2763, 2303, 2304, 3415, 2764, 2305, 3147, 3442, 2780, 2306, 3148, 3443, 2765, 2307, 3149, 3416, 2766, 2308, 3150, 3417, 2767, 3151, 3418, 2768, 3152, 3419, 2769, 3164, 3420, 2781, 3153, 3444, 3154, 3421, 3165, 3422, 3166, 3423, 3445, 3424, 3446) AND `PersonApartament`.`person_id` = `Person`.`id`)  WHERE `Person`.`member_id` &gt; 1   </td><td></td><td style="text-align: right">2</td><td style="text-align: right">2</td><td style="text-align: right">5</td></tr>
</tbody></table>

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: