@@ -732,6 +732,8 @@ void INI_format(thread_db* tdbb, const string& charset)
732
732
}
733
733
END_STORE
734
734
735
+ HalfStaticArray<QualifiedName, 2> predefinedSchemas;
736
+
735
737
// Store SYSTEM schema
736
738
737
739
handle.reset();
@@ -749,13 +751,14 @@ void INI_format(thread_db* tdbb, const string& charset)
749
751
}
750
752
END_STORE
751
753
752
- storeGrant(tdbb, attachment->getUserName().c_str(), obj_user, QualifiedName(SYSTEM_SCHEMA),
753
- obj_schema, USAGE_PRIVILEGES, false );
754
+ const QualifiedName systemSchema (SYSTEM_SCHEMA);
755
+ predefinedSchemas.add(systemSchema );
754
756
755
- storeGrant(tdbb, "PUBLIC" , obj_user, QualifiedName(SYSTEM_SCHEMA) ,
757
+ storeGrant(tdbb, ownerName.c_str() , obj_user, systemSchema ,
756
758
obj_schema, USAGE_PRIVILEGES, false);
757
759
758
- GRANT_privileges(tdbb, QualifiedName(SYSTEM_SCHEMA), obj_schema, transaction);
760
+ storeGrant(tdbb, "PUBLIC", obj_user, systemSchema,
761
+ obj_schema, USAGE_PRIVILEGES, false);
759
762
760
763
if (!attachment->isGbak() || !(attachment->att_flags & ATT_gbak_restore_has_schema))
761
764
{
@@ -774,19 +777,26 @@ void INI_format(thread_db* tdbb, const string& charset)
774
777
}
775
778
END_STORE
776
779
777
- storeGrant(tdbb, attachment->getUserName().c_str(), obj_user, QualifiedName(PUBLIC_SCHEMA),
778
- obj_schema, USAGE_PRIVILEGES, true );
780
+ const QualifiedName publicSchema (PUBLIC_SCHEMA);
781
+ predefinedSchemas.add(publicSchema );
779
782
780
- storeGrant(tdbb, "PUBLIC" , obj_user, QualifiedName(PUBLIC_SCHEMA) ,
783
+ storeGrant(tdbb, ownerName.c_str() , obj_user, publicSchema ,
781
784
obj_schema, USAGE_PRIVILEGES, true);
782
785
783
- GRANT_privileges(tdbb, QualifiedName(PUBLIC_SCHEMA), obj_schema, transaction);
786
+ storeGrant(tdbb, "PUBLIC", obj_user, publicSchema,
787
+ obj_schema, USAGE_PRIVILEGES, true);
784
788
}
785
789
786
790
// Create indices for system relations
787
791
788
792
store_indices(tdbb);
789
793
794
+ // Grant schema privileges. This is defered until system indices are created
795
+ // to avoid some system queries being badly optimized.
796
+
797
+ for (const auto& schema : predefinedSchemas)
798
+ GRANT_privileges(tdbb, schema, obj_schema, transaction);
799
+
790
800
// Create parameter types
791
801
792
802
handle.reset();
0 commit comments