List:Internals« Previous MessageNext Message »
From:Michael Widenius Date:May 14 2009 1:39am
Subject:Re: MySQL Reengineering Project
View as plain text  
Hi!

>>>>> "Alaric" == Alaric Snell-Pym <alaric@stripped> writes:

<cut>

Alaric> That, combined with the fact that in my recent foray into UDFs I found
Alaric> that string UDFs are passed a buffer with room for 255 characters to
Alaric> put their result into, and then have the choice of using it and
Alaric> returning a pointer to it or mallocing their own buffer and returning
Alaric> a pointer to that (meaning that the caller, somewhere, must have code
Alaric> to the effect of "if (returned_ptr != allocated_buffer)
Alaric> free(returned_ptr)" to clear up, I guess?),

Actually the idea was that you would in your object remember the
malloc you did and then free it.

So the code would be in the destructor:

x_free(malloc_pointer);

Alaric> led me to suspect that
Alaric> there was an ingrained culture of functions plopping their results
Alaric> into spaces left for them somewhere.

The idea was to help the UDF to avoid doing mallocs during query
execution for most common queries.  The assumption was that for most
UDF's 255 byte would be enough for their result.

Alric> Ok, there's often good reasons
Alaric> for string-processing functions to put their results into preallocated
Alaric> buffers, but I suspect in this case somebody originally wrote it that
Alaric> way because it was the ingrained culture, and then later had to add
Alaric> the ability to malloc your own buffer (wasting the pre-allocated
Alaric> buffer) in order to handle strings of more than 255 characters :-)

No, the design was there from the start.  One of the basic design of
the MySQL code base is to try to avoid calls to malloc during query
execution; We should instead try to do as much as possible when
at query exceution startup.

Alaric> Although I may have found the only examples of this sort of thing in a
Alaric> very large and otherwise much more cleanly-structured codebase for all
Alaric> I know!

Regards,
Monty
Thread
MySQL Reengineering ProjectManyi Lu - Sun Norway12 May 2009
  • Re: MySQL Reengineering ProjectJay Pipes12 May 2009
  • Re: MySQL Reengineering ProjectMARK CALLAGHAN12 May 2009
    • Re: MySQL Reengineering ProjectMats Kindahl12 May 2009
      • Re: MySQL Reengineering ProjectManyi Lu - Sun Norway12 May 2009
        • Re: MySQL Reengineering ProjectMats Kindahl12 May 2009
    • Re: MySQL Reengineering ProjectStewart Smith13 May 2009
  • Re: MySQL Reengineering ProjectMikiya Okuno18 May 2009
    • Re: MySQL Reengineering ProjectSergei Golubchik18 May 2009
      • Re: MySQL Reengineering ProjectRoy Lyseng18 May 2009
Re: MySQL Reengineering ProjectAlaric Snell-Pym12 May 2009
  • Re: MySQL Reengineering ProjectMats Kindahl12 May 2009
    • Re: MySQL Reengineering ProjectJay Pipes12 May 2009
      • Re: MySQL Reengineering ProjectJay Pipes12 May 2009
        • Re: MySQL Reengineering ProjectAlex Esterkin12 May 2009
          • Re: MySQL Reengineering ProjectBrian Aker12 May 2009
      • Re: MySQL Reengineering ProjectSergei Golubchik12 May 2009
        • Re: MySQL Reengineering ProjectBrian Aker12 May 2009
          • Re: MySQL Reengineering ProjectSergei Golubchik12 May 2009
            • Re: MySQL Reengineering ProjectAlex Esterkin12 May 2009
              • Re: MySQL Reengineering ProjectBrian Aker12 May 2009
            • Re: MySQL Reengineering ProjectJay Pipes12 May 2009
              • Re: MySQL Reengineering ProjectDavi Arnaut13 May 2009
              • Re: MySQL Reengineering ProjectAlex Esterkin13 May 2009
                • Re: MySQL Reengineering ProjectJay Pipes13 May 2009
            • Re: MySQL Reengineering ProjectMichael Widenius14 May 2009
          • Re: MySQL Reengineering ProjectJonas Oreland13 May 2009
        • Re: MySQL Reengineering ProjectRoy Lyseng12 May 2009
      • Re: MySQL Reengineering ProjectMats Kindahl12 May 2009
    • Re: MySQL Reengineering ProjectAlaric Snell-Pym12 May 2009
      • Re: MySQL Reengineering ProjectMats Kindahl12 May 2009
      • Re: MySQL Reengineering ProjectMichael Widenius14 May 2009
        • Re: MySQL Reengineering ProjectAlaric Snell-Pym15 May 2009
          • Re: MySQL Reengineering ProjectKristian Nielsen15 May 2009
            • Re: MySQL Reengineering ProjectBrian Aker15 May 2009
            • Re: MySQL Reengineering ProjectAlaric Snell-Pym15 May 2009
          • Re: MySQL Reengineering ProjectMichael Widenius6 Jun 2009
Re: MySQL Reengineering ProjectMats Kindahl12 May 2009
Re: MySQL Reengineering ProjectAlex Esterkin12 May 2009
  • Re: MySQL Reengineering ProjectMasood Mortazavi13 May 2009
    • Re: MySQL Reengineering ProjectBrian Aker13 May 2009
    • Re: MySQL Reengineering ProjectAlex Esterkin13 May 2009
      • Re: MySQL Reengineering ProjectBaron Schwartz13 May 2009
        • Re: MySQL Reengineering ProjectStewart Smith13 May 2009
          • Re: MySQL Reengineering ProjectBaron Schwartz13 May 2009
    • Re: MySQL Reengineering ProjectAlex Esterkin13 May 2009
    • Re: MySQL Reengineering ProjectStewart Smith13 May 2009
  • Re: MySQL Reengineering ProjectMichael Widenius14 May 2009