On 2018/04/17 4:10, Alvaro Herrera wrote:
> Amit Langote wrote:
>
>> The solution I came up with is to call map_variable_attnos() directly,
>> instead of going through map_partition_varattnos() every time, after first
>> creating the attribute map ourselves.
>
> Yeah, sounds good. I added a tweak: if the tupledescs are equal, there
> should be no need to do any mapping.
Thanks for the commit!
About the equalTupleDescs()-based optimization you added -- It seems to me
that that *always* returns false if you pass it tupledescs of two
different tables, which in this case, we do. That's because
equalTupleDescs has this:
if (tupdesc1->tdtypeid != tupdesc2->tdtypeid)
return false;
So, it fails to optimize as you were hoping it would.
Instead of doing this, I think we should try to make
convert_tuples_by_name_map() a bit smarter by integrating the logic in
convert_tuples_by_name() that's used conclude if no tuple conversion is
necessary. So, if it turns that the tuples descriptors passed to
convert_tuples_by_name_map() contain the same number of attributes and the
individual attributes are at the same positions, we signal to the caller
that no conversion is necessary by returning NULL.
Attached find a patch that does that. When working on this, I noticed
that when recursing for inheritance children, ATPrepAlterColumnType()
would use a AlterTableCmd (cmd) that's already scribbled on as if it were
the original.
Thanks,
Amit