Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Database schema issue missing index 'id' (not unique (id)) #81

Open
ScottVerbeek opened this issue Jan 31, 2024 · 1 comment
Open

Database schema issue missing index 'id' (not unique (id)) #81

ScottVerbeek opened this issue Jan 31, 2024 · 1 comment

Comments

@ScottVerbeek
Copy link

ScottVerbeek commented Jan 31, 2024

Database PostgreSQL 14.0.

root@2886180ea26f:/var/www/vanilla-401# php admin/cli/check_database_schema.php 
-------------------------------------------------------------------------------
block_grade_me
 * Missing index 'id' (not unique (id)). 
CREATE INDEX mdl_blocgradme_id_ix ON mdl_block_grade_me (id);
-------------------------------------------------------------------------------

Inspecting the table mdl_block_grade_me with psql (PostgreSQL interactive terminal) we see that a index does actually already exist, however instead of the expected name mdl_blocgradme_id_ix it is actually called mdl_blocgradme_id3_ix.

vanilla-401=# \dS+ mdl_block_grade_me
                                                                   Table "public.mdl_block_grade_me"
     Column     |          Type          | Collation | Nullable |                    Default                     | Storage  | Compression | Stats target | Description 
----------------+------------------------+-----------+----------+------------------------------------------------+----------+-------------+--------------+-------------
 id             | bigint                 |           | not null | nextval('mdl_block_grade_me_id_seq'::regclass) | plain    |             |              | 
 itemname       | character varying(255) |           |          |                                                | extended |             |              | 
 itemtype       | character varying(30)  |           | not null | ''::character varying                          | extended |             |              | 
 itemmodule     | character varying(30)  |           |          |                                                | extended |             |              | 
 iteminstance   | bigint                 |           |          |                                                | plain    |             |              | 
 itemsortorder  | bigint                 |           | not null | 0                                              | plain    |             |              | 
 courseid       | bigint                 |           | not null | 0                                              | plain    |             |              | 
 coursename     | character varying(255) |           | not null | ''::character varying                          | extended |             |              | 
 coursemoduleid | bigint                 |           | not null | 0                                              | plain    |             |              | 
Indexes:
    "mdl_blocgradme_id_pk" PRIMARY KEY, btree (id)
    "mdl_blocgradme_cou2_ix" btree (coursemoduleid)
    "mdl_blocgradme_cou_ix" btree (courseid)
    "mdl_blocgradme_couite_ix" btree (courseid, itemmodule)
    "mdl_blocgradme_id3_ix" btree (id)                         <-- NOTE:  The missing index
    "mdl_blocgradme_ite_ix" btree (itemsortorder)
Access method: heap

@ScottVerbeek
Copy link
Author

ScottVerbeek commented Jan 31, 2024

At this point the index appear redundant. db/install.xml specifies a foreign key, however postgres creates a index instead of a constraint (foreign key).

Given this, then the primary key would suffice and the index mdl_blocgradme_id3_ix can be removed. Alternatively the mdl_blocgradme_id_pk is removed and the index mdl_blocgradme_id3_ix is extended to be unique.

ScottVerbeek added a commit to catalyst/moodle-block_grade_me that referenced this issue Feb 1, 2024
Syxton pushed a commit to Syxton/moodle-block_grade_me that referenced this issue Jun 14, 2024
Syxton pushed a commit to Syxton/moodle-block_grade_me that referenced this issue Nov 13, 2024
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

No branches or pull requests

1 participant