Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6227859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:17:31+00:00 2026-05-24T09:17:31+00:00

This is my table CREATE TABLE IF NOT EXISTS `results_stock_all` ( `Result_Id` varchar(50) NOT

  • 0

This is my table

CREATE TABLE IF NOT EXISTS `results_stock_all` (
  `Result_Id` varchar(50) NOT NULL,
  `Stock_Date` date NOT NULL,
  `Stock_Code` varchar(20) NOT NULL,
  `Prev_Close` float(10,3) NOT NULL DEFAULT '0.000',
  `Open` float(10,3) NOT NULL DEFAULT '0.000',
  `Close` float(10,3) NOT NULL DEFAULT '0.000',
  `High` float(10,3) NOT NULL DEFAULT '0.000',
  `Low` float(10,3) NOT NULL DEFAULT '0.000',
  `Volume` int(11) NOT NULL DEFAULT '0',
  `Change` float(10,3) NOT NULL DEFAULT '0.000',
  `Change_Percent` float(10,3) NOT NULL
  PRIMARY KEY (`Result_Id`),
  KEY `Stock_Date` (`Stock_Date`),
  KEY `Stock_Code_Stock_Date` (`Stock_Code`,`Stock_Date`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

3,150,236 rows, MYISAM, data size: 255.1MB, index size: 209.5MB, Stock_Code: 1468

I have 2 type of query that use often,

1) SELECT cols FROM results_stock_all WHERE Stock_Date = ‘2011-08-06’ ORDER BY cols;

(No problem, pretty fast)

2) SELECT cols FROM results_stock_all WHERE Stock_Code = ‘1234’ ORDER BY Stock_Date DESC LIMIT 3000;

id  select_type table   type    possible_keys   key key_len ref rows    Extra
1   SIMPLE  results_stock_all   ref Stock_Code_Stock_Date   Stock_Code_Stock_Date   22  const   5173    Using where

I need to query latest 3000 rows and send the results to charting software.
But this query takes about 17 secs at first run for each different Stock_Code.

How to make it faster ? I am thinking to partition this table, but I really don’t have idea how to do it , by Date or by Stock_Code ?

If partition by Stock_Code, I believe it will speed up query #2, then how about query #1

Thanks.

EDITED

I tried to add an index Stock_Code,
it is faster in this query

SELECT cols FROM results_stock_all WHERE Stock_Code = ‘1234’ ORDER BY Stock_Date DESC LIMIT 3000;

but when i tried to run on smaller results set,

mysql> set session query_cache_type = 0;

mysql> select * from results_stock_all ignore index(stock_code) where stock_code = ‘1234’ order by stock_date desc;
100 rows in set (0.00 sec)

mysql> select * from results_stock_all ignore index(stock_code_stock_date) where
stock_code = ‘1234’ order by stock_date desc limit 100;
100 rows in set (0.02 sec)

I believe using where is faster than using file sort.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T09:17:31+00:00Added an answer on May 24, 2026 at 9:17 am

    Indexes are used for WHERE, but not for ORDER. So you need to add index for Stock_Code only:

    alter table results_stock_all add index `Stock_Code` (`Stock_Code`);
    

    This should make your query much faster.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this table CREATE TABLE [dbo].[friend_blocked_list]( [subdomain] [varchar](50) NOT NULL, [un] [nvarchar](50) NOT
Query was this: CREATE TABLE `query` ( `id` int(11) NOT NULL auto_increment, `searchquery` varchar(255)
I have this table: CREATE TABLE IF NOT EXISTS `produtos` ( `id` int(11) NOT
With this code: var db = google.gears.factory.create('beta.database'); db.open('cominar'); db.execute('CREATE TABLE IF NOT EXISTS Ajax
I have this database structure, SET SQL_MODE=NO_AUTO_VALUE_ON_ZERO; CREATE TABLE IF NOT EXISTS `announces` (
I have this table: CREATE TABLE `test` ( `ID` int(11) NOT NULL auto_increment, `text`
I have this table: CREATE TABLE `point` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `siteid`
i have this table create table eveniment( + evenimentId bigint not null auto_increment primary
I have this table CREATE TABLE `codes` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
This is my table: CREATE TABLE `users` ( `id` int(10) unsigned NOT NULL auto_increment,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.