-
Notifications
You must be signed in to change notification settings - Fork 436
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
Index with expression is missing in UI although it exists in DB #1922
Comments
HeidiSQL uses such a query to retrieve indexes of a table. Note only the simple indexes appear in the result. Probably you can help to change that query so it includes expression indexes: WITH
ndx_list AS (
SELECT
pg_index.indexrelid,
pg_class.oid
FROM
pg_index,
pg_class
WHERE
pg_class.relname = 'A'
AND pg_class.oid = pg_index.indrelid
),
ndx_cols AS (
SELECT
pg_class.relname,
UNNEST(i.indkey) AS col_ndx,
CASE i.indisprimary WHEN TRUE THEN 'PRIMARY' ELSE CASE i.indisunique WHEN TRUE THEN 'UNIQUE' ELSE 'KEY' END END AS CONSTRAINT_TYPE,
pg_class.oid
FROM
pg_class
JOIN pg_index i ON (pg_class.oid = i.indexrelid)
JOIN ndx_list ON (
pg_class.oid = ndx_list.indexrelid
)
WHERE
pg_table_is_visible(pg_class.oid)
)
SELECT
ndx_cols.relname AS CONSTRAINT_NAME,
ndx_cols.CONSTRAINT_TYPE,
a.attname AS COLUMN_NAME
FROM
pg_attribute a
JOIN ndx_cols ON (a.attnum = ndx_cols.col_ndx)
JOIN ndx_list ON (
ndx_list.oid = a.attrelid
AND ndx_list.indexrelid = ndx_cols.oid
); |
This Considering the above, SQL query to get the list should be rewritten to allow NULL as COLUMN_NAME. And then the GUI is required to take into consideration there can be no column for the index. It should work for the indices, where an expression is combined with static columns. These work in current HeidiSQL, however you will see the static columns only under such index. Maybe you could show to user there is unspecified column. You should be able to get the expression from the Postgres as well (I could elaborate). I've got query to get the list correctly, but it's completely different from yours (it's a side product from finding an issue). I'll try to modify your query later. Note1: Auto-generated CREATE table code in GUI skips the expression index as well. Note2: The relname is required to be lowercased. |
Thanks a lot @damucz ! |
WITH
ndx_list AS (
SELECT
pg_index.indexrelid,
pg_class.oid
FROM
pg_index,
pg_class
WHERE
pg_class.relname = 'a'
AND pg_class.oid = pg_index.indrelid
)
SELECT
pg_class.relname AS constraint_name,
CASE i.indisprimary WHEN TRUE THEN 'PRIMARY' ELSE CASE i.indisunique WHEN TRUE THEN 'UNIQUE' ELSE 'KEY' END END AS CONSTRAINT_TYPE,
pg_get_indexdef(i.indexrelid, T.ord::INT, TRUE) AS column_name
FROM
pg_class
JOIN pg_index i ON (pg_class.oid = i.indexrelid)
JOIN ndx_list ON (
pg_class.oid = ndx_list.indexrelid
),
UNNEST(i.indkey) WITH ORDINALITY AS T (indkey,ord)
WHERE
pg_table_is_visible(pg_class.oid); This should work. Compatibility: Hope it helps and I didn't make a mistake. 🍀 |
Same query as above, but using ROW_NUMBER instead of WITH ORDINALITY: WITH
ndx_list AS (
SELECT
pg_index.indexrelid,
pg_class.oid
FROM
pg_index,
pg_class
WHERE
pg_class.relname = 'a'
AND pg_class.oid = pg_index.indrelid
)
SELECT
pg_class.relname AS constraint_name,
CASE i.indisprimary WHEN TRUE THEN 'PRIMARY' ELSE CASE i.indisunique WHEN TRUE THEN 'UNIQUE' ELSE 'KEY' END END AS CONSTRAINT_TYPE,
pg_get_indexdef(i.indexrelid, (ROW_NUMBER() OVER (PARTITION BY pg_class.relname))::int, TRUE) AS COLUMN_NAME
FROM
pg_class
JOIN pg_index i ON (pg_class.oid = i.indexrelid)
JOIN ndx_list ON (
pg_class.oid = ndx_list.indexrelid
),
UNNEST(i.indkey)
WHERE
pg_table_is_visible(pg_class.oid); |
Preconditions
Describe the bug
The index using expression is not visible in UI (Table/Indices). All other indices are shown. Index is shown using SQL query directly. I'd expect all the indices are in the list of the indices in table management UI.
To Reproduce
Minimal repro SQL:
Click on table A in the left list, select
Table: A
tab, selectIndices (0)
.There is no index in the list. There should be one - idx.
Actually any expression causes the index is not shown. Try
(id+id)
.Following correctly shows the single index
idx
:Output (copied from Heidi as delimited text):
Screenshots or Crash reports
None.
The text was updated successfully, but these errors were encountered: