optimization question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • siliconmike

    #1

    optimization question

    I've got a table T with 20 columns (fixed length) and one column C
    which is varchar.

    Somehow C has to be varchar.

    T may have millions of records.

    Is there a way to optimize this situation ?

    Any ideas?

  • Bill Karwin

    #2
    Re: optimization question

    siliconmike wrote:[color=blue]
    > I've got a table T with 20 columns (fixed length) and one column C
    > which is varchar.
    >
    > Somehow C has to be varchar.
    >
    > T may have millions of records.
    >
    > Is there a way to optimize this situation ?[/color]

    Optimize for what task or goal? Space efficiency? Import speed? Query
    speed? If query speed, what kind of queries do you need to make against
    the data?

    It sounds to me like someone gave you an order like, "store all these
    millions of text strings in a database, and make sure it's *optimized*."
    Only they didn't tell you the the criteria I ask for above.

    Regards,
    Bill K.

    Comment

    • siliconmike

      #3
      Re: optimization question

      [color=blue]
      > Optimize for what task or goal? Space efficiency? Import speed?[/color]
      Query[color=blue]
      > speed? If query speed, what kind of queries do you need to make[/color]
      against[color=blue]
      > the data?[/color]

      Import speed, but without making C fixed length. For example, would
      taking C to a different table help?
      [color=blue]
      > It sounds to me like someone gave you an order like, "store all these[/color]
      [color=blue]
      > millions of text strings in a database, and make sure it's[/color]
      *optimized*."[color=blue]
      > Only they didn't tell you the the criteria I ask for above.[/color]

      Sounds wrong.

      Comment

      • Bill Karwin

        #4
        Re: optimization question

        siliconmike wrote:[color=blue]
        > Import speed, but without making C fixed length. For example, would
        > taking C to a different table help?[/color]

        I'd recommend using the LOAD DATA INFILE statement. The docs suggest it
        can up to 20 times faster than inserting using INSERT.

        LOAD DATA INFILE uses field delimiters; it does not require the input
        data formatted in fixed length. See examples at
        http://dev.mysql.com/doc/mysql/en/load-data.html

        Also read the suggestions for speeding up inserts and LOAD DATA on this
        page: http://dev.mysql.com/doc/mysql/en/insert-speed.html
        Disabling the keys during import will probably help a lot.

        Regards,
        Bill K.

        Comment

        • siliconmike

          #5
          Re: optimization question


          Bill Karwin wrote:[color=blue]
          > siliconmike wrote:[color=green]
          > > Import speed, but without making C fixed length. For example, would
          > > taking C to a different table help?[/color]
          >
          > I'd recommend using the LOAD DATA INFILE statement. The docs suggest[/color]
          it[color=blue]
          > can up to 20 times faster than inserting using INSERT.[/color]

          Also query speeds..
          Queries like:

          select * from T where PRIMARY_KEY=45

          It is only column C (varchar) that forces the whole table to be dynamic
          format.
          If I make C fixed length, it would waste lot of space.

          I presume here that queries on fixed length format tables would execute
          much faster than variable length ones.

          Maybe I can remove column C from T and write the data intended for C in
          separate files named by the PRIMARY_KEY.

          Or other ideas ?

          Comment

          • Bill Karwin

            #6
            Re: optimization question

            siliconmike wrote:[color=blue]
            > I presume here that queries on fixed length format tables would execute
            > much faster than variable length ones.[/color]

            Not always. There is reportedly a tradeoff between fixed-length of CHAR
            and simply the lesser average size of VARCHAR. Variable length fields
            mean more data fits into the same amount of RAM. So it depends on the
            physical characteristics of a given dataset.

            To be sure, you should try some tests using both CHAR and VARCHAR for a
            representative dataset, and run some timings (avoid presuming if you can
            actually measure!).

            http://dev.mysql.com/doc/mysql/en/cu...enchmarks.html

            Regards,
            Bill K.

            Comment

            Working...