From: reynierpm@gmail.com Date: August 27 2012 2:27pm Subject: =?UTF-8?Q?Procedimiento_o_funci=C3=B3n=3F_Cual_de_los_dos_usar_y_por?= =?UTF-8?Q?_donde_comenzar_=2E=2E=2E?= List-Archive: http://lists.mysql.com/mysql-es/3939 Message-Id: MIME-Version: 1.0 Content-Type: multipart/alternative; boundary=0015173ff30e591f7004c8402117 --0015173ff30e591f7004c8402117 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hola listeros, tengo un problema y no se que enfoque o soluci=C3=B3n darle,= me explico: Resulta que tengo las siguientes tablas: CREATE TABLE IF NOT EXISTS `default_comment` ( `comment_id` int(11) NOT NULL AUTO_INCREMENT, `friend_id` int(11) NOT NULL, `message` text COLLATE utf8_unicode_ci NOT NULL, `created_at` timestamp NULL DEFAULT NULL, `status_id` int(11) NOT NULL, `device` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `deleted` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`comment_id`) ) ENGINE=3DMyISAM DEFAULT CHARSET=3Dutf8 COLLATE=3Dutf8_unicode_ci AUTO_INCREMENT=3D1 ; CREATE TABLE IF NOT EXISTS `default_friend` ( `id` int(11) NOT NULL AUTO_INCREMENT, `friend_id` int(8) NOT NULL, `user_id` int(8) NOT NULL, `is_suscriber` tinyint(1) NOT NULL DEFAULT '1', `privacy` tinyint(1) NOT NULL DEFAULT '0', `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `friend_list_id` int(4) NOT NULL, `approved` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=3DMyISAM DEFAULT CHARSET=3Dutf8 COLLATE=3Dutf8_unicode_ci AUTO_INCREMENT=3D1 ; CREATE TABLE IF NOT EXISTS `default_profiles` ( `id` int(9) NOT NULL AUTO_INCREMENT, `created` datetime DEFAULT NULL, `updated` datetime DEFAULT NULL, `created_by` int(11) DEFAULT NULL, `ordering_count` int(11) DEFAULT NULL, `user_id` int(11) unsigned NOT NULL, `display_name` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `first_name` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `last_name` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `updated_on` int(11) unsigned DEFAULT NULL, `phone_1` varchar(12) COLLATE utf8_unicode_ci DEFAULT NULL, `phone_2` varchar(12) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`), KEY `user_id` (`user_id`) ) ENGINE=3DMyISAM DEFAULT CHARSET=3Dutf8 COLLATE=3Dutf8_unicode_ci AUTO_INCREMENT=3D3 ; CREATE TABLE IF NOT EXISTS `default_status` ( `status_id` int(11) NOT NULL AUTO_INCREMENT, `message` text COLLATE utf8_unicode_ci NOT NULL, `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `privacy` enum('Privado','Publico','Amigos','Amigos de mis amigos') COLLATE utf8_unicode_ci DEFAULT NULL, `user_id` int(11) NOT NULL, `device` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `deleted` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`status_id`) ) ENGINE=3DMyISAM DEFAULT CHARSET=3Dutf8 COLLATE=3Dutf8_unicode_ci AUTO_INCREMENT=3D1 ; CREATE TABLE IF NOT EXISTS `default_users` ( `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT, `email` varchar(60) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', `password` varchar(100) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', `salt` varchar(6) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', `group_id` int(11) DEFAULT NULL, `ip_address` varchar(16) COLLATE utf8_unicode_ci DEFAULT NULL, `active` int(1) DEFAULT NULL, `activation_code` varchar(40) COLLATE utf8_unicode_ci DEFAULT NULL, `created_on` int(11) NOT NULL, `last_login` int(11) NOT NULL, `username` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, `forgotten_password_code` varchar(40) COLLATE utf8_unicode_ci DEFAULT NULL, `remember_code` varchar(40) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`), KEY `email` (`email`) ) ENGINE=3DMyISAM DEFAULT CHARSET=3Dutf8 COLLATE=3Dutf8_unicode_ci COMMENT=3D'Registered User Information' AUTO_INCREMENT=3D3 ; Para probar el "performance" de unas consultas que estoy realizando necesito insertar como minimo 30 000 o 40 000 registros en esas tablas pero con alguna que otra particularidad que describo a continuaci=C3=B3n: - En la tabla default_users los campos username y email tienen que ser =C3=BAnicos o sea repetidos no est=C3=A1n permitidos. - En la tabla default_users el campo email deberia ser, en teoria, username@stripped (dominio.com por lo de las pruebas) - Por cada username en la tabla default_users se debe crear un registro en la tabla default_profiles donde el user_id =3D id de la tabla default_users o sea deben coincidir - En la tabla default_profiles se deben llenar de forma aleatoria los campos display_name, first_name, last_name, phone_1 y phone_2 - En la tabla default_users se deben llenar de forma aleatoria los campos group_id con valores entre 2 y 6 y active con valores 0 o 1 - En la tabla default_friend se deben crear la misma cantidad de registros o mas siempre y cuando se cumpla la condicion de que friend_id= y user_id no esten repetidos entiendase por repetido que x,y no puede exis= tir dos veces o sea en dos registros y de existir 1,2 no puede existir 2,1 Como le entrar=C3=ADan a esto? Un procedimiento? Una funci=C3=B3n? Alguien = que me de una ayuda conformando este complejo problema? Intente hacerlo desde PHP pero el script demora demasiado tiempo en ejecuci=C3=B3n y eso en hosting compartidos no est=C3=A1 permitido :( sugerencias? Gracias por adelantado Ing. Reynier Perez Mira eMail: reynierpm@stripped, reynier. perez@stripped= m Website: http://www.reynierpm.com Skype: reynierpm Mobile: +58 424.180.5609 --0015173ff30e591f7004c8402117--