Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

smaller table, same rows of data but less columns

Posted on 2013-12-09
5
Medium Priority
?
252 Views
Last Modified: 2013-12-09
I have a query that takes a long time to run so I want to make the table smaller to test to see if the query can run quicker

CREATE TABLE `a_messages2` (
  `a_messages_id` int(11) NOT NULL AUTO_INCREMENT,
  `conversation_id` bigint(20) DEFAULT NULL,
  `profile_id` varchar(20) DEFAULT NULL,
  `sender` varchar(20) DEFAULT NULL,
  `message_id` bigint(20) DEFAULT NULL,
  `message_text` varchar(1000) DEFAULT NULL,
  `dateAgo` varchar(20) DEFAULT NULL,
  `message_read` tinyint(4) DEFAULT NULL,
  `this_user` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`a_messages_id`),
  UNIQUE KEY `unique_message_id` (`message_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

Open in new window



I want to create a similar smaller table (less columns, no primary key, no unique key) and copy the rows of data

CREATE TABLE `a_messages2_smaller` (
  `profile_id` varchar(20) DEFAULT NULL,
  `sender` varchar(20) DEFAULT NULL,
  `message_id` bigint(20) DEFAULT NULL,
  `this_user` varchar(20) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

Open in new window

0
Comment
Question by:rgb192
  • 3
5 Comments
 
LVL 12

Expert Comment

by:Radek Baranowski
ID: 39705996
and the question is ?

so far it looks legit.
0
 

Author Comment

by:rgb192
ID: 39706373
there is already data in a_messages_2
I want to create a smaller table a_messages_2_smaller and insert the same data
0
 
LVL 32

Accepted Solution

by:
Daniel Wilson earned 2000 total points
ID: 39707127
insert into a_messages2_smaller (profile_id, sender, message_id, this_user)
(Select profile_id, sender, message_id, this_user from a_messages2);

However, I don't anticipate that will help your query speed. What is the query that's giving you trouble?  And approximately how many rows do you have?  Some careful index design is more likely to help.
0
 

Author Comment

by:rgb192
ID: 39707594
your insert worked and the query ran much quicker but maybe index would be better, which will be another question.
0
 

Author Closing Comment

by:rgb192
ID: 39707595
thanks
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month10 days, 18 hours left to enroll

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question