Thread: Why does array_position_common bitwise NOT an Oid type?
Hi, I was puzzled to see the following code: my_extra->element_type = ~element_type; It looks quite wrong, but if its right then I think it needs a comment to explain it. I don't see any in the area which mentions it. My best guess would be that it's using this to know if the type data has been cached, but then why would it not use InvalidOid for that? -- David Rowley http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services
David Rowley <david.rowley@2ndquadrant.com> writes: > I was puzzled to see the following code: > my_extra->element_type = ~element_type; > It looks quite wrong, but if its right then I think it needs a comment > to explain it. I don't see any in the area which mentions it. My best > guess would be that it's using this to know if the type data has been > cached, but then why would it not use InvalidOid for that? If memory serves, the idea was to force the subsequent datatype-lookup path to be taken, even if for some reason element_type is InvalidOid. If we take the lookup path then the bogus element_type will be detected and reported; if we don't, it won't be. We could instead add an explicit test for element_type == InvalidOid, but that's just more duplicative code. regards, tom lane
On 17 December 2017 at 14:53, Tom Lane <tgl@sss.pgh.pa.us> wrote: > David Rowley <david.rowley@2ndquadrant.com> writes: >> I was puzzled to see the following code: > >> my_extra->element_type = ~element_type; > > If memory serves, the idea was to force the subsequent datatype-lookup > path to be taken, even if for some reason element_type is InvalidOid. > If we take the lookup path then the bogus element_type will be detected > and reported; if we don't, it won't be. That makes sense. I'd just have expected more documentation on that. Although, perhaps I just didn't look hard enough. I did fail to notice the fact that the same thing does occur over and over when I sent this originally. -- David Rowley http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services