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 8765315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:14:59+00:00 2026-06-13T16:14:59+00:00

I have these tables: CREATE TABLE `cstat` ( `id_cstat` bigint(20) NOT NULL, `lang_code` varchar(3)

  • 0

I have these tables:

CREATE TABLE  `cstat` (
  `id_cstat` bigint(20) NOT NULL,
  `lang_code` varchar(3) NOT NULL,
  `description` varchar(255) NOT NULL,
  `description_tr` varchar(255) NOT NULL,
  `id_ccountry` varchar(3) NOT NULL,
  `geometry_point` point DEFAULT NULL,
  `geometry_poly` polygon DEFAULT NULL,
  `name_type` varchar(1) NOT NULL,
  `bb_min_lat` double DEFAULT NULL,
  `bb_min_lon` double DEFAULT NULL,
  `bb_max_lat` double DEFAULT NULL,
  `bb_max_lon` double DEFAULT NULL,
  `has_ex` tinyint(1) NOT NULL DEFAULT '0',
  `order` int(11) DEFAULT NULL,
  PRIMARY KEY (`id_cstat`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

CREATE TABLE  `dstat` (
  `id_cstat` bigint(20) NOT NULL,
  `lang_code` varchar(3) NOT NULL,
  `word` varchar(30) NOT NULL,
  `word_no` tinyint(3) unsigned NOT NULL,
  `word_cnt` tinyint(3) unsigned NOT NULL,
  `word_grp` tinyint(3) unsigned NOT NULL,
  `name_type` char(1) CHARACTER SET ascii NOT NULL,
  `cstat_order` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

I need to select a record from cstat using conditions from dstat and in order of cstat.order or dstat.cstat_order.

My query look like this:

SELECT cstat.ID_CSTAT, cstat.LANG_CODE, cstat.DESCRIPTION, cstat.DESCRIPTION_TR, cstat.ID_CCOUNTRY, AsBinary(cstat.GEOMETRY_POINT) AS GEOMETRY_POINT, cstat.NAME_TYPE, cstat.BB_MIN_LAT, cstat.BB_MIN_LON, cstat.BB_MAX_LAT, cstat.BB_MAX_LON, cstat.HAS_EX
FROM cstat cstat
JOIN dstat W0
ON (W0.ID_CSTAT = cstat.ID_CSTAT)
where
  (W0.WORD = 'ceska') AND
  (W0.NAME_TYPE = 'B')
ORDER BY W0.CSTAT_ORDER;

Can anybody help me what index to create to prevent using filesort? I believe I’ve tried almost everything, but I failed. There are more modifications of this base query (another one or more joins of table dstat, but thats not important right now).

Thanks a lot for your help.

EDIT: To be honest – I’ve tried a lot of indexes. The base one I’ve declared is a primary key on cstat_id_cstat. At the moment I have following indexes:

KEY `ix_dstat_nt_word_id_order` (`name_type`,`word`,`id_cstat`,`cstat_order`);
KEY `ix_dstat_word_id_order` (`word`,`id_cstat`,`cstat_order`);
KEY `ix_dstat_nt_grp_no_word_id_order` (`name_type`,`word_grp`,`word_no`,`word`,`id_cstat`,`cstat_order`);
KEY `ix_dstat_grp_no_word_id_order` (`word_grp`,`word_no`,`word`,`id_cstat`,`cstat_order`);
KEY `ix_dstat_nt_grp_word_id_order` (`name_type`,`word_grp`,`word`,`id_cstat`,`cstat_order`);

which partly solves my problem with indexed reading. But sort is always made by using filesort.

EXPLAIN

1, 'SIMPLE', 'W0', 'ref', 'ix_dstat_nt_word_id_order,ix_dstat_word_id_order,ix_dstat_nt_grp_no_word_id_ord‌​er,ix_dstat_nt_grp_word_id_order', 'ix_dstat_nt_word_id_order', '93', 'const,const', 1, 'Using where; Using index; Using filesort' 
1, 'SIMPLE', 'cstat', 'eq_ref', 'PRIMARY,ix_cstat_id_order', 'PRIMARY', '8', 'search_2012_q3_cze_svk_dev.W0.id_cstat', 1, ''
  • 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-06-13T16:15:01+00:00Added an answer on June 13, 2026 at 4:15 pm

    Problem is solved by adding following indexes:

    KEY `ix_dstat_nt_word_order_id_grp_no` (`name_type`,`word`,`cstat_order`,`id_cstat`,`word_grp`,`word_no`);
    KEY `ix_dstat_word_order_id_grp_no` (`word`,`cstat_order`,`id_cstat`,`word_grp`,`word_no`);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have these tables: CREATE TABLE User( Username varchar(15) NOT NULL, Name varchar(20) DEFAULT
I have these tables: CREATE TABLE [EDR_SECURITY].[Person]( [ixPerson] [bigint] IDENTITY(1,1) NOT NULL, [sName] [nvarchar](200)
The tables CREATE TABLE `pending` ( `auto_id` int(10) unsigned NOT NULL AUTO_INCREMENT, `username` varchar(255)
I have these tables CREATE TABLE parent ( id NUMBER(10, 0) NOT NULL, name
Let's say we have these tables: CREATE TABLE A ( id SERIAL NOT NULL
I have two tables: CREATE TABLE dbo.country ( cntry_id VARCHAR(2) NOT NULL, name VARCHAR(50)
I have these two tables: CREATE TABLE x ( id INT NOT NULL, exclude
Strange situation. If I have these tables: CREATE TABLE t1 (id INT, title VARCHAR(20),
These are my 2 tables: CREATE TABLE `documents` ( `Document_ID` int(10) NOT NULL auto_increment,
I have these two tables in mysql: create table a ( id INT NOT

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.