Jump to content

Is this possible?


Andy-H

Recommended Posts

Basically, I have a table with over 20k rows, when I query it, despite the results being paginated to 20 per result set, the query takes around a second to run, I want to know if its possible to create a MySQL view, with the keys of one table and a limit field which will always remain in natural order and in increments of 1. This way I can join the tables and do:

 

 

SELECT p.* FROM view v INNER JOIN premises p USING ( id ) WHERE v.incremental_field >= 0 AND v.incremental_field < 20 ORDER BY v.id ASC

 

 

Anyone know if this is possible? Whether it would improve performance or whether there is a better alternative?

 

 

My current query is


SELECT CONCAT(p.id, ':', p.branch_name) AS branch_name, p.addr, p.postcode, CONCAT(c.first_name, ' ', c.last_name) AS contact, c1.info AS mob, c2.info AS email, p.disabled
                                          FROM premises p LEFT JOIN ( contacts c ) ON ( c.prem_id = p.id )
                                          LEFT JOIN ( contact_info c1 ) ON ( c1.contact_id = c.id AND c1.type_id = (SELECT id FROM types WHERE type = 'Mobile' ) )
                                          LEFT JOIN ( contact_info c2 ) ON ( c2.contact_id = c.id AND c2.type_id = (SELECT id FROM types WHERE type = 'Email'  ) )
                                          ". $append ." ORDER BY p.id ASC LIMIT $low, 20

Link to comment
Share on other sites

 

 

id[/color]select_type[/color]table[/color]type[/color]possible_keys[/color]key[/color]key_len[/color]ref[/color]rows[/color]Extra

1[/t]PRIMARYpindexNULLPRIMARY4NULL20

1PRIMARYcrefprem_idprem_id4phantom.p.id1

1PRIMARYc1refcontact_idcontact_id8phantom.c.id,const1

1PRIMARYc2refcontact_idcontact_id8phantom.c.id,const1

[/color]3SUBQUERYtypesALLNULLNULLNULLNULL4Using where

2SUBQUERYtypesALLNULLNULLNULLNULL4Using where

I don't get any of that lol

Link to comment
Share on other sites

 

id select_type table type possible_keys key key_len ref rows Extra

1 PRIMARY p index NULL PRIMARY 4 NULL 20

1 PRIMARY c ref prem_id prem_id 4 phantom.p.id 1

1 PRIMARY c1 ref contact_id contact_id 8 phantom.c.id,const 1

1 PRIMARY c2 ref contact_id contact_id 8 phantom.c.id,const 1

3 SUBQUERY types ALL NULL NULL NULL NULL 4 Using where

2 SUBQUERY types ALL NULL NULL NULL NULL 4 Using where

 

 

I don't get any of that lol

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.