I must agree with herveus, indexes should really be crafted to the situation.

That being said, you could analyze your queries for what is being joined on in tables to build yourself a list of candidates, then address them each by hand. That would at least give you a starting point, I suppose.

Be warned, however, I am not sure if there are any kind of CPAN modules, but having written my own code to parse SQL (poorly) in the past, it is not for the faint of heart, especially if you a going cross-platform.

Write something and use it as a guide to narrow your options, but make the changes yourself, and test them. I have made slight changes to MySQL and actually slowed down a query because the optimizer got confused. EXPLAIN is your friend.

HINTS:

You may have to put something into DBI. If the queries don't specify what database the tables are in explicitly, and you have tables of the same name in different databases, then you will need a preliminary query to get your context.

Parse the from, get a list of tables and their aliases (if any), describe the tables into a hash for lookup if you have fields that don't have a table specified.

Parse through the where, check any comparitors that are simple field to field comparisons and ignore any others, this will get you most of your key situations and simplify your life.

Keep track of how many times a table is accessed and how many times each field in that table is accessed, if you have 20 accesses to a table, but a field is accessed only once in those 20, it is less likely to need keying.

Good Luck.

                - Ant
                - Some of my best work - (1 2 3)


In reply to Re: Autogenerate SQL Indexes? by suaveant
in thread Autogenerate SQL Indexes? by knoebi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.