Query to gather Metadata not optimized
Query to gather Metadata not optimized
Hello, I noticed that this query is passed to mysql server to gather Metadata about tables columns "SELECT cast('' as char(1)) TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, ORDINAL_POSITION POSITION, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH DATA_LENGTH, NUMERIC_PRECISION DATA_PRECISION, NUMERIC_SCALE DATA_SCALE, (case IS_NULLABLE when 'YES' then 1 else 0 end) NULLABLE, COLUMN_DEFAULT DEFAULT_VALUE FROM information_schema.COLUMNS WHERE TABLE_NAME = 'realtablename' ORDER BY TABLE_SCHEMA, TABLE_NAME, ORDINAL_POSITION". Since a server can contain several (in our case more 100) schemas with the same table name, the gathered rows can be very big. is it possible that the query is more specific and include in in the where part of it " and TABLE_SCHEMA='realschemaname', so it does not return unwanted column names from other tables not in the required schema.
Thanks in advance you for your reply.
Thanks in advance you for your reply.
Last edited by chihebbs on Mon 13 Oct 2008 07:54, edited 1 time in total.
-
eduardosic
- Posts: 387
- Joined: Fri 18 Nov 2005 00:26
- Location: Brazil
Re: Query not optimized to gather Metadata
You can try
or
with mi work's fine
Code: Select all
Show Fields from TableName
Code: Select all
SELECT
cast('' as char(1)) TABLE_CATALOG,
TABLE_SCHEMA,
TABLE_NAME,
COLUMN_NAME,
ORDINAL_POSITION POSITION,
DATA_TYPE,
CHARACTER_MAXIMUM_LENGTH DATA_LENGTH,
NUMERIC_PRECISION DATA_PRECISION,
NUMERIC_SCALE DATA_SCALE,
(case IS_NULLABLE when 'YES' then 1 else 0 end) NULLABLE,
COLUMN_DEFAULT DEFAULT_VALUE
FROM
information_schema.COLUMNS
WHERE
TABLE_SCHEMA = 'DataBaseName' AND
TABLE_NAME = 'TableName'
ORDER BY TABLE_SCHEMA, TABLE_NAME, ORDINAL_POSITION
-
eduardosic
- Posts: 387
- Joined: Fri 18 Nov 2005 00:26
- Location: Brazil
If you are using TMyMetadata you can make this:chihebbs wrote:The Query is passed to mysql server by MyDAC component. It should be optimized at the component level.
Code: Select all
MyMetaData1.Close;
MyMetaData1.Restrictions.Values[ 'TABLE_SCHEMA' ] := 'DataBaseName';
MyMetaData1.Open;
-
Challenger
- Devart Team
- Posts: 925
- Joined: Thu 17 Nov 2005 10:53
Maybe to Optimize more gathering of Metadata, the Result Set of the query sent to Mysql server to gather information about columns should be Cached for future use, since seldom tables would be changing between queries in real life applications and it would cost a lot less to query the Status of the table from information_schema.`TABLES` (CREATE_TIME,UPDATE_TIME columns), if the table structure has changed since the last query, than to ask for the details of all columns for each query. Thank you in advance for your answer.
-
Challenger
- Devart Team
- Posts: 925
- Joined: Thu 17 Nov 2005 10:53
Re: Query to gather Metadata not optimized
It is not about caching the results, please read the quoted description. As far as 5.80.0.48 is concerned nothing has been done to fine-graine the implicit query.chihebbs wrote:Hello, I noticed that this query is passed to mysql server to gather Metadata about tables columns "SELECT cast('' as char(1)) TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, ORDINAL_POSITION POSITION, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH DATA_LENGTH, NUMERIC_PRECISION DATA_PRECISION, NUMERIC_SCALE DATA_SCALE, (case IS_NULLABLE when 'YES' then 1 else 0 end) NULLABLE, COLUMN_DEFAULT DEFAULT_VALUE FROM information_schema.COLUMNS WHERE TABLE_NAME = 'realtablename' ORDER BY TABLE_SCHEMA, TABLE_NAME, ORDINAL_POSITION". Since a server can contain several (in our case more 100) schemas with the same table name, the gathered rows can be very big. is it possible that the query is more specific and include in in the where part of it " and TABLE_SCHEMA='realschemaname', so it does not return unwanted column names from other tables not in the required schema.
Thanks in advance you for your reply.