Foros del Web » Programación para mayores de 30 ;) » Bases de Datos General » Mysql »

Acelerar más resultados

Estas en el tema de Acelerar más resultados en el foro de Mysql en Foros del Web. Hola a todos! He leido y leido acerca de como mostrar resultados de forma más rápida y es utilizando indices porque evita que tenga que ...
  #1 (permalink)  
Antiguo 23/04/2013, 21:22
Avatar de WinGFX  
Fecha de Ingreso: mayo-2006
Ubicación: Bogotá
Mensajes: 86
Antigüedad: 17 años, 11 meses
Puntos: 3
Acelerar más resultados

Hola a todos!

He leido y leido acerca de como mostrar resultados de forma más rápida y es utilizando indices porque evita que tenga que hacer un full scan en toda la tabla pero veo que la velocidad en traer los resultados no es la que se espera, así que en una consulta SQL donde todos los campos usan indice para brindar un resultado mas rapido, les voy a compartir una estructura:

Código PHP:
CREATE TABLE IF NOT EXISTS `index_site` (
  `
id_buildingchar(32NOT NULL COMMENT 'Id MD5 de oferta',
  `
id_clientchar(32NOT NULL COMMENT 'Id MD5 de publicador',
  `
id_brokersmallint(5unsigned NOT NULL,
  `
kind_clientchar(1NOT NULL,
  `
citysmallint(6unsigned NOT NULL,
  `
latfloat(10,6NOT NULL,
  `
lngfloat(10,6NOT NULL,
  `
zonesmallint(2unsigned NOT NULL,
  `
sectorsmallint(4unsigned NOT NULL,
  `
subregionsmallint(6unsigned NOT NULL,
  `
countrychar(2NOT NULL,
  `
habssmallint(5unsigned NOT NULL,
  `
bathsmallint(5unsigned NOT NULL,
  `
personssmallint(5unsigned NOT NULL,
  `
include_elevatorenum('1','0'NOT NULL,
  `
build_levelvarchar(20NOT NULL,
  `
areamediumint(8unsigned NOT NULL,
  `
area_umenum('1','2','3','4','5'NOT NULL,
  `
area_strvarchar(10NOT NULL,
  `
codechar(10NOT NULL,
  `
titletinytext NOT NULL,
  `
type_offervarchar(50NOT NULL,
  `
offer_namevarchar(20NOT NULL,
  `
commentstext NOT NULL,
  `
type_buildingvarchar(50NOT NULL,
  `
addresstinytext NOT NULL,
  `
sector_nametinytext NOT NULL,
  `
city_namevarchar(50NOT NULL,
  `
subregion_namevarchar(50NOT NULL,
  `
area_terrainvarchar(10NOT NULL,
  `
area_um_terraintinyint(4NOT NULL,
  `
imagevarchar(70NOT NULL,
  `
image_totaltinyint(2unsigned NOT NULL,
  `
build_statustinyint(3unsigned NOT NULL,
  `
tagstext NOT NULL COMMENT 'Etiquetas de oferta',
  `
urlvarchar(200NOT NULL,
  `
include_offer_valueenum('1','0'NOT NULL,
  `
offer_valuevarchar(15NOT NULL,
  `
offer_value_formatvarchar(20NOT NULL,
  `
prc_comissionvarchar(5NOT NULL,
  `
date_addeddatetime NOT NULL,
  `
date_updateddatetime NOT NULL,
  `
date_expiredatetime NOT NULL,
  `
date_suspendeddate NOT NULL,
  `
visitsint(11NOT NULL,
  `
kind_offertinyint(4NOT NULL,
  `
kind_buildingtinyint(5unsigned NOT NULL,
  `
kind_building_typetinyint(5unsigned NOT NULL,
  `
mark_bldtinyint(3unsigned NOT NULL,
  `
mark_bld_colorchar(7NOT NULL,
  `
statustinyint(1unsigned NOT NULL,
  `
is_madeenum('0','1'NOT NULL,
  `
is_projectenum('0','1'NOT NULL,
  `
is_bmenum('0','1'NOT NULL COMMENT 'Incluida en Broker Market',
  `
is_demoenum('0','1'NOT NULL,
  `
is_leadingenum('0','1'NOT NULL COMMENT 'Es destacado',
  `
visible_in_metasearchmediumtext NOT NULL,
  `
visible_in_webmediumtext NOT NULL,
  `
seller_imagevarchar(150NOT NULL,
  `
seller_namevarchar(50NOT NULL,
  
KEY `id_broker` (`id_broker`),
  
KEY `id_client` (`id_client`),
  
KEY `kind_building` (`kind_building`),
  
KEY `city` (`city`),
  
KEY `offer_value` (`offer_value`),
  
KEY `is_bm` (`is_bm`),
  
KEY `status` (`status`),
  
KEY `sector` (`sector`),
  
KEY `zone` (`zone`),
  
KEY `area` (`area`),
  
KEY `prc_comission` (`prc_comission`),
  
KEY `is_made` (`is_made`),
  
KEY `is_leading` (`is_leading`),
  
KEY `id_building` (`id_building`),
  
KEY `date_added` (`date_added`),
  
KEY `code` (`code`),
  
KEY `country` (`country`),
  
KEY `habs` (`habs`),
  
KEY `kind_offer` (`kind_offer`),
  
FULLTEXT KEY `tags` (`tags`)
ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='Indizador de sitio'
Ok, lo admito, algo grande!

Bueno el tema es como se pueden dar cuenta estoy usando varios indices de los cuales cuando hago una búsqueda usando varios indices, hasta ahi normal; el paso siguiente es cuando hago la siguiente consulta:

Código PHP:
SELECT FROM `index_siteWHERE kind_building='1' AND kind_offer='1' AND city='1' 
Y esta se tomó 0.0179 segundos, ahora cuando le hago EXPLAIN aqui es donde verdaderamente no entiendo muy bien:

Código PHP:
EXPLAIN SELECT FROM `index_siteWHERE kind_building='1' AND kind_offer='1' AND city='1' 
Lo que me genera es:

Código PHP:
+----+-------------+------------+-------------+-------------------------------+-------------------------------+---------+------+------+-------------------------------------------------------------+
id select_type table      type        possible_keys                 key                           key_len ref  rows Extra                                                       |
+----+-------------+------------+-------------+-------------------------------+-------------------------------+---------+------+------+-------------------------------------------------------------+
|  
SIMPLE      index_site index_merge kind_building,city,kind_offer kind_offer,city,kind_building 1,2,1   NULL |  184 Using intersect(kind_offer,city,kind_building); Using where |
+----+-------------+------------+-------------+-------------------------------+-------------------------------+---------+------+------+-------------------------------------------------------------+ 
Tengo claro que esté usando claves (indexes) pero en el Extra según lo que leí en MySQL que cuando se obtiene "Using where" parece que algo hay mal, y si tengo claves y si la consulta en el tiempo que dije es correcto.

¿Qué tengo mal?

Espero alguien pueda entender mi pregunta. Gracias!
__________________
"Si piensas en que harás mañana, mejor hazlo hoy!"

Consejos para las buenas preguntas

Etiquetas: acelerar, campo, resultados, select, sql, tabla
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 06:03.