Conversation
…rong impure cache usage
|
Are comments supported for constants? I didn't see this in the documentation. Comments are simply supported for packaged procedures and functions. It would make sense to do the same for constants (and any package objects, for that matter). |
No, I didn't plan to implement comments, but I think it's possible. I will take a look |
Ok, it wasn't that hard, I implemented the feature as suggested. Examples: |
AlexPeshkoff
left a comment
There was a problem hiding this comment.
Generally OK, just minor correction please
| { | ||
| QualifiedName constantName(subName, name.schema, name.object); // name is a package | ||
| if (constantName.schema.isEmpty()) | ||
| constantName.schema = PUBLIC_SCHEMA; |
There was a problem hiding this comment.
This was not necessary in any other command in DdlNodes.
Looks incorrect here.
There was a problem hiding this comment.
Actuality, as I can see, something similar (but more more complicated) is happening for procedures and functions in resolveRoutineOrRelation(...). Without the check, scheme will remain NULL.
| class SysFunction | ||
| { | ||
| public: | ||
| enum Flags : UCHAR |
There was a problem hiding this comment.
enum class, please.
SysFunction::NONE is completely misleading.
There was a problem hiding this comment.
enum class is problematic for flags. You have to redefine bit operations or cast the type each time. IMHO, simple enum inside a class is a good choice in such case
There was a problem hiding this comment.
And could you clarify what exactly is confusing about SysFunction::NONE?
| #include "../jrd/Attachment.h" | ||
| #include "../jrd/scl_proto.h" | ||
|
|
||
| #include "../common/dsc_proto.h" // DSC_make_descriptor |
There was a problem hiding this comment.
I left the review of this file for last, and given the amount of things I saw, didn't read it.
I think the amout of changes in this file and your initial comments about it seems not correctly.
The file was maintanable and it required no extra efforts or such things in what I'm doing now (LTTs in packages).
Your approach seems incorrect for me and is making things more complicate.
There was a problem hiding this comment.
I was prepared for the changes to this file to be criticized. But if things remain as is, technical debt will accumulate, and over time, everything will become unmaintainable. If @AlexPeshkoff and @dyemanov also think this changes is outside the scope of the PR, I will revert the changes to this file.
Co-authored-by: Adriano dos Santos Fernandes <529415+asfernandes@users.noreply.github.com>
dyemanov
left a comment
There was a problem hiding this comment.
It's the first part of the review, PackageNodes.epp will be reviewed separately.
|
|
||
| bool constant() const override | ||
| { | ||
| return true; |
There was a problem hiding this comment.
It should be false for RecordKeyNode.
src/dsql/Nodes.h
Outdated
| virtual bool unmappable(const MapNode* mapNode, StreamType shellStream) const; | ||
|
|
||
| // Check if expression returns constant result | ||
| virtual bool constant() const; |
There was a problem hiding this comment.
I'd define it as returning false here and override only in nodes where true should be returned. No need to pollute the codebase with the default implementation.
There was a problem hiding this comment.
It actually depends on meaning of "constant result" here. For me it looks like complete duplication of deterministic(). If I'm wrong, what's the difference?
There was a problem hiding this comment.
Changed to false. The logic moved to the isChildrenConstant() method. Child methods will call it when needed.
| case obj_schemas: | ||
| return "SQL$SCHEMAS"; | ||
| case obj_package_constant: | ||
| return "SQL$PACKAGE_CONSTANT"; |
There was a problem hiding this comment.
Constants belong to a package, AFAIU it cannot have it's own privileges, so there're no need in dedicated security classes. Or is it reserved for global constants, if they ever appear in the future?
There was a problem hiding this comment.
Yes, it is reserved for global constants, but to be honest, I haven't looked into the security code so I'm not sure if it's really necessary for global constants
| LCK_idx_rescan, // Index rescan lock | ||
| LCK_prc_rescan, // Procedure rescan lock | ||
| LCK_fun_rescan, // Function existence lock | ||
| LCK_constant_rescan, // Constant existence lock |
There was a problem hiding this comment.
Is it also a preparation for global constants? Because otherwise it's the package (not the constant) that should be cached/locked. Packaged constants are never altered/dropped individually, AFAIU.
There was a problem hiding this comment.
I added this because it is necessary to Routine class
| class DsqlCompilerScratch; | ||
| class dsql_fld; | ||
|
|
||
| class Constant final : public Routine |
There was a problem hiding this comment.
Maybe it should be refactored, so that Routine and Constant have the same base class?
| EVL_field(0, rpb->rpb_record, f_const_id, &desc2); | ||
| id = MOV_get_long(tdbb, &desc2, 0); | ||
|
|
||
| Constant::lookup(tdbb, id); |
There was a problem hiding this comment.
You don't use the result. Is it expected to throw if a constant is not found? Maybe some other method -- e.g. checkExistance() -- is worth adding for readability?
There was a problem hiding this comment.
I'm relying on the rel_funs case, and it simply calls Function::lookup(tdbb, id, 0); So I assume the case where the constant isn't found is impossible. I hope an assert will be enough. Or should I add an exception?
There was a problem hiding this comment.
I should clarify. I think the main purpose of the lookup method isn't to check for existence, but to populate the cache, since it has an auto-create flag. But I could be wrong.
src/dsql/ExprNodes.h
Outdated
| void genBlr(DsqlCompilerScratch* dsqlScratch) override; | ||
| void make(DsqlCompilerScratch* dsqlScratch, dsc* desc) override; | ||
|
|
||
| bool constant() const override |
There was a problem hiding this comment.
I may agree with Adriano from the safety POV (new nodes are never introduced as constant by mistake), but I don't like polluting the every class with the common code.
And this means that deterministic() should also be changed -- not something I object but I'd prefer to see a clearer code.
|
No code for backup and restore the new table? |
This PR adds a new database object - Package Constant (#1036). See README.packages.txt for more information.
Usage examples:
The implementation has three key points: