Page 1 of 1

Mysql table indexes

Posted: Wed May 06, 2020 5:30 pm
by vilian
Hi Guys,
How could I know the indexes of a mysql table has ?

Re: Mysql table indexes

Posted: Wed May 06, 2020 8:31 pm
by FranciscoA
Try this way:

Code: Select all

oVer := oServer:Query("SHOW INDEX FROM " + cTable + ";")
Regards.

Re: Mysql table indexes

Posted: Wed May 06, 2020 8:47 pm
by FranciscoA
Otra manera:

Code: Select all

//Para una tabla
SELECT DISTINCT
    TABLE_NAME,
    INDEX_NAME
FROM INFORMATION_SCHEMA.STATISTICS 
WHERE TABLE_NAME = 'retalcal';

//Para todas las tablas de una BDD
SELECT DISTINCT
    TABLE_NAME,
    INDEX_NAME
FROM INFORMATION_SCHEMA.STATISTICS
WHERE TABLE_SCHEMA = 'fapsoftware';
Saludos.

Re: Mysql table indexes

Posted: Wed May 06, 2020 11:24 pm
by vilian
Thank you ;)

Re: Mysql table indexes

Posted: Thu May 07, 2020 2:47 am
by nageswaragunupudi
vilian wrote:Hi Guys,
How could I know the indexes of a mysql table has ?

Code: Select all

aIndexes := oCn:ListIndexes( cTable )
 

Re: Mysql table indexes

Posted: Thu May 07, 2020 11:13 am
by vilian
Thank you ;)

Re: Mysql table indexes

Posted: Thu May 07, 2020 12:07 pm
by Horizon
nageswaragunupudi wrote:
vilian wrote:Hi Guys,
How could I know the indexes of a mysql table has ?

Code: Select all

aIndexes := oCn:ListIndexes( cTable )
 
Hi Mr. Rao,
Is there any function to create index?

Re: Mysql table indexes

Posted: Thu May 07, 2020 12:24 pm
by nageswaragunupudi
Is there any function to create index?
No.

Not exactly but this function automatically creates a primary key index:

Code: Select all

METHOD MakePrimaryKey( cTable, cCol )

Re: Mysql table indexes

Posted: Thu May 07, 2020 12:32 pm
by Horizon
nageswaragunupudi wrote:
Is there any function to create index?
No.

Not exactly but this function automatically creates a primary key index:

Code: Select all

METHOD MakePrimaryKey( cTable, cCol )
Hi Mr. Rao,

Do you mean we don't need index other than a primary key? Wouldn't it be better to index the connection variables of detail tables and master table?

Re: Mysql table indexes

Posted: Thu May 07, 2020 1:16 pm
by nageswaragunupudi
Do you mean we don't need index other than a primary key?
a) We need to create unique indexes for enforcing unique constraint for a column or set of columns. If we want to create unique constraint to a single column, we can either create while creating the table or later create a unique index by:

Code: Select all

oCn:Execute( "CREATE UNIQUE INDEX cust_name_uidx ON cust( name )" )
 
b) In large tables we may need to create indexes on some columns to optimize queries. It is normally better to keep such indexes to minimum or none. Note: Optimizing queries is a subject by itself.

Code: Select all

oCn:Execute( "CREATE INDEX ON employee___idx ON employee( _ )" )
 
Wouldn't it be better to index the connection variables of detail tables and master table?
We do it by creating foreign key relationships. Our library provides special features to deal with parent-child relationships and you can find samples in the samples folder as well in the forum if you search.