If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > query design (2 tables - same structure)

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-07-08, 06:07
Zamolxe Zamolxe is offline
Registered User
 
Join Date: Feb 2004
Location: Bucharest
Posts: 37
Post query design (2 tables - same structure)

hello

here are the facts:
- 2 tables: `table1` and `table2` that have the SAME structure
- `table1` about 30.000 rows
- `table2` about 170.000 rows - this table is updated more often
- i have to display the data in a grid with pagination with results from both `table1` and `table2`

i've did the following:
CREATE TEMPORARY TABLE `table_tmp` LIKE `table1`;
ALTER TABLE `table_tmp` ENGINE=MERGE UNION=(`table1`,`table2`);
ANALYZE TABLE `table_tmp`;

SELECT SQL_CALC_FOUND_ROWS
[...]
FROM `table_tmp`
WHERE
[...]
LIMIT 0, 20


is this the best method to work with the tables?
i find it kind of slow. please share your thoughts.
sometime i get this kind of error: Table 'table_tmp' is marked as crashed and should be repaired
thanks!
__________________
My Blog
Reply With Quote
  #2 (permalink)  
Old 04-07-08, 07:30
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
Code:
SELECT * FROM table1
UNION ALL
SELECT * FROM table2
__________________
George
Twitter | Blog
Reply With Quote
  #3 (permalink)  
Old 04-21-08, 10:39
Zamolxe Zamolxe is offline
Registered User
 
Join Date: Feb 2004
Location: Bucharest
Posts: 37
Thumbs down re

actually with UNION ALL the query is much slower

with temporary table MERGE i get the following results:

CREATE TEMPORARY TABLE 0.001532
ALTER TABLE UNION 0.002059
mysql_query = 2.613590
mysql_num_rows 0.000009
FOUND_ROWS 0.000086
mysql_result 0.000019
mysql_free_result 0.000008
119496 rows returned


I dont like the fact that the mysql_query has the execution time of 2.6 seconds
__________________
My Blog
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On