Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sql: make the lookup of built-in functions smarted wrt
pg_catalog
.
Prior to this patch, there were two sorts of functions: - functions defined with a "`pg_catalog.`" prefix. These functions could be found either when used with their prefix, or without their prefix as long as `pg_catalog` was in the search path (and the session was defined to include `pg_catalog` in the search path by default). - functions defined without a "`pg_catalog.`" prefix. These functions could only be found when used without a prefix. This created a lurking bug with regards to compatibility: in PostgreSQL, *all* built-in functions reside in namespace `pg_catalog`, not only those fews that have motivated the "`pg_catalog.`" prefix in CockroachDB so far. For example, `SELECT pg_catalog.count(*) FROM foo` is valid, and so is `SELECT pg_catalog.length(name) FROM users`. It was just a matter of time before a user would demand compatibility with a tool producing pg queries automatically using this form. To address this, three solutions were considered: - move all built-in functions supported by CockroachDB to the namespace `pg_catalog`. Since `pg_catalog` is always searched (it's always part of the search path), unqualified names would still be found. This would achieve compatibility but make the name "`pg_catalog`" much more prominent in error messages, which use the fully qualified name of the function in all cases. - move all built-in functions supported by CockroachDB to a new namespace with a more generic name, say "`sql`", then tweak the lookup rules so that whenever the prefix "`pg_catalog`" is used, it would be substituted implicitly by "`sql`". This would achieve compatibility and also make the error messages less pg-flavored. The drawback of this approach is that it introduces a mandatory prefix "`sql.`" in many places in the code and error messages where it was not present before. - move all built-in functions supported by both CockroachDB and PostgreSQL to the global namespace (the one with no prefix), then tweak the lookup rules so that whenever the prefix "`pg_catalog`" is used, it would be removed to look up the remainder of the name in the global namespace. This also achieves compatibility and has the least impact on the code and error messages. The drawback of this approach is that those functions that are really pg-specific and merely present to please ORMs looking at `pg_proc` now also appear in the auto-generated docs for the global namespace. The last solution was deemed to offer the best trade-off and was thus adopted for the time being. Remaining issues with documentation, if any, can be addressed in a subsequent patch by adding a boolean to mark the builtin definition of those pg compatibility functions we do not want to promote.
- Loading branch information
Showing
7 changed files
with
46 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters