Skip to content

Conversation

@vonzshik
Copy link
Contributor

@vonzshik vonzshik commented Jan 21, 2023

Closes #4481
Closes #4429

The main reason for this PR is to unblock #4899. In that PR ranges are resolved by a separate resolver, which isn't compatible with NodaTime resolver. Specifically, while reading a range of timestamptz right now we first attempt to find the type by it's full name (which fails), then by it's name (at which point NodaTime's resolver gives the handler back). After, if everything else fails, we have a special logic for complex types (including ranges). In #4899 range's resolver finds the type by it's full name and because it's a range type it gives the range handler back. With this PR we'll be able to immediately check in NodaTime's resolver by name.

@vonzshik vonzshik requested a review from roji as a code owner January 21, 2023 20:13
@vonzshik vonzshik force-pushed the 4481-rewrite-type-handler-lookup branch from a29fbd0 to f905188 Compare January 22, 2023 13:14
@vonzshik vonzshik force-pushed the 4481-rewrite-type-handler-lookup branch from f905188 to 98a4e9a Compare February 11, 2023 16:33
@vonzshik vonzshik force-pushed the 4481-rewrite-type-handler-lookup branch from 98a4e9a to 47fa852 Compare February 26, 2023 17:40
_handlersByOID[oid] = handler;
return true;
}
if ((handler = ResolveByPostgresType(pgType)) is not null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember all the nuances any more, but...

Does this intentionally change our behavior for resolving by Name vs. FullName? Previously we tried twice (FullName, then Name), whereas now we just call ResolveByPostgresType with pgType; this caches by FullName, but the new resolvers' ResolveByPostgresType looks at Name (is that discrepancy intentional too?).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's intentional. The reason we were doing it twice it because some resolvers (like builtin) don't care about FullName. I'm pretty sure none of out resolvers actually need FullName.
The point with ResolveByPostgresType is that we pass the type to the resolver, which will decide whether it can handle this type or not. To make it a bit easier, by default resolver's ResolveByPostgresType just calls ResolveByDataTypeName with a short name, and users have an option to override this.
As for the caching, we cache by FullName because it's unique (technically more correct is to cache by PgType, but this looks like an overkill).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure none of out resolvers actually need FullName.

Yeah, that makes sense. The only types which need a full name (i.e. in non-pg_catalog schemas) are extensions, and those can be in any schema, based on how the user adds the extension.


if (!DatabaseInfo.ByOID.TryGetValue(oid, out var pgType))
return false;
return TryResolveLong(oid, out handler);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good optimization - we can do it in ResolveByClrType as well (maybe other methods?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, only if ResolveByClrType, everything else is already done.

@vonzshik vonzshik enabled auto-merge (squash) February 26, 2023 21:46
@vonzshik vonzshik merged commit d110eef into main Feb 26, 2023
@vonzshik vonzshik deleted the 4481-rewrite-type-handler-lookup branch February 26, 2023 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clean up our type name lookup logic Clean up internal lookups by type name (with/without schema)

2 participants