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

Improve performance of sys.sp_column_privileges by removing an unutilized check #3349

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 17 additions & 42 deletions contrib/babelfishpg_tsql/sql/babelfishpg_tsql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1354,7 +1354,7 @@ BEGIN
JOIN information_schema.column_privileges t5 ON t1.relname = t5.table_name AND t2.nspname = t5.table_schema
JOIN pg_attribute t6 ON t6.attrelid = t1.oid AND t6.attname = t5.column_name;
END;
$$ LANGUAGE plpgsql;
$$ LANGUAGE plpgsql STABLE PARALLEL SAFE;

CREATE OR REPLACE VIEW sys.sp_column_privileges_view AS
SELECT
Expand Down Expand Up @@ -1385,46 +1385,21 @@ BEGIN

IF (COALESCE(@table_owner, '') = '')
BEGIN

IF EXISTS (
SELECT * FROM sys.sp_column_privileges_view
WHERE pg_catalog.lower(@table_name) = pg_catalog.lower(table_name) and pg_catalog.lower(SCHEMA_NAME()) = pg_catalog.lower(table_qualifier)
)
BEGIN
SELECT
TABLE_QUALIFIER,
TABLE_OWNER,
TABLE_NAME,
COLUMN_NAME,
GRANTOR,
GRANTEE,
PRIVILEGE,
IS_GRANTABLE
FROM sys.sp_column_privileges_view
WHERE pg_catalog.lower(@table_name) = pg_catalog.lower(table_name)
AND (pg_catalog.lower(SCHEMA_NAME()) = pg_catalog.lower(table_owner))
AND ((SELECT COALESCE(@table_qualifier,'')) = '' OR pg_catalog.lower(table_qualifier) = pg_catalog.lower(@table_qualifier))
AND ((SELECT COALESCE(@column_name,'')) = '' OR pg_catalog.lower(column_name) LIKE pg_catalog.lower(@column_name))
ORDER BY table_qualifier, table_owner, table_name, column_name, privilege, grantee;
END
ELSE
BEGIN
SELECT
TABLE_QUALIFIER,
TABLE_OWNER,
TABLE_NAME,
COLUMN_NAME,
GRANTOR,
GRANTEE,
PRIVILEGE,
IS_GRANTABLE
FROM sys.sp_column_privileges_view
WHERE pg_catalog.lower(@table_name) = pg_catalog.lower(table_name)
AND (pg_catalog.lower('dbo')= pg_catalog.lower(table_owner))
AND ((SELECT COALESCE(@table_qualifier,'')) = '' OR pg_catalog.lower(table_qualifier) = pg_catalog.lower(@table_qualifier))
AND ((SELECT COALESCE(@column_name,'')) = '' OR pg_catalog.lower(column_name) LIKE pg_catalog.lower(@column_name))
ORDER BY table_qualifier, table_owner, table_name, column_name, privilege, grantee;
END
SELECT
TABLE_QUALIFIER,
TABLE_OWNER,
TABLE_NAME,
COLUMN_NAME,
GRANTOR,
GRANTEE,
PRIVILEGE,
IS_GRANTABLE
FROM sys.sp_column_privileges_view
WHERE pg_catalog.lower(@table_name) = pg_catalog.lower(table_name)
AND (pg_catalog.lower('dbo')= pg_catalog.lower(table_owner))
AND ((SELECT COALESCE(@table_qualifier,'')) = '' OR pg_catalog.lower(table_qualifier) = pg_catalog.lower(@table_qualifier))
AND ((SELECT COALESCE(@column_name,'')) = '' OR pg_catalog.lower(column_name) LIKE pg_catalog.lower(@column_name))
ORDER BY table_qualifier, table_owner, table_name, column_name, privilege, grantee;
END
ELSE
BEGIN
Expand Down Expand Up @@ -1475,7 +1450,7 @@ BEGIN
JOIN information_schema.table_privileges t4 ON t1.relname = t4.table_name
WHERE t4.privilege_type = 'DELETE';
END;
$$ LANGUAGE plpgsql;
$$ LANGUAGE plpgsql STABLE PARALLEL SAFE;

CREATE OR REPLACE VIEW sys.sp_table_privileges_view AS
-- Will use sp_column_priivleges_view to get information from SELECT, INSERT and REFERENCES (only need permission from 1 column in table)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ BEGIN
JOIN information_schema.column_privileges t5 ON t1.relname = t5.table_name AND t2.nspname = t5.table_schema
JOIN pg_attribute t6 ON t6.attrelid = t1.oid AND t6.attname = t5.column_name;
END;
$$ LANGUAGE plpgsql;
$$ LANGUAGE plpgsql STABLE PARALLEL SAFE;

CREATE OR REPLACE VIEW sys.sp_column_privileges_view AS
SELECT
Expand Down Expand Up @@ -802,46 +802,21 @@ BEGIN

IF (COALESCE(@table_owner, '') = '')
BEGIN

IF EXISTS (
SELECT * FROM sys.sp_column_privileges_view
WHERE pg_catalog.lower(@table_name) = pg_catalog.lower(table_name) and pg_catalog.lower(SCHEMA_NAME()) = pg_catalog.lower(table_qualifier)
)
BEGIN
SELECT
TABLE_QUALIFIER,
TABLE_OWNER,
TABLE_NAME,
COLUMN_NAME,
GRANTOR,
GRANTEE,
PRIVILEGE,
IS_GRANTABLE
FROM sys.sp_column_privileges_view
WHERE pg_catalog.lower(@table_name) = pg_catalog.lower(table_name)
AND (pg_catalog.lower(SCHEMA_NAME()) = pg_catalog.lower(table_owner))
AND ((SELECT COALESCE(@table_qualifier,'')) = '' OR pg_catalog.lower(table_qualifier) = pg_catalog.lower(@table_qualifier))
AND ((SELECT COALESCE(@column_name,'')) = '' OR pg_catalog.lower(column_name) LIKE pg_catalog.lower(@column_name))
ORDER BY table_qualifier, table_owner, table_name, column_name, privilege, grantee;
END
ELSE
BEGIN
SELECT
TABLE_QUALIFIER,
TABLE_OWNER,
TABLE_NAME,
COLUMN_NAME,
GRANTOR,
GRANTEE,
PRIVILEGE,
IS_GRANTABLE
FROM sys.sp_column_privileges_view
WHERE pg_catalog.lower(@table_name) = pg_catalog.lower(table_name)
AND (pg_catalog.lower('dbo')= pg_catalog.lower(table_owner))
AND ((SELECT COALESCE(@table_qualifier,'')) = '' OR pg_catalog.lower(table_qualifier) = pg_catalog.lower(@table_qualifier))
AND ((SELECT COALESCE(@column_name,'')) = '' OR pg_catalog.lower(column_name) LIKE pg_catalog.lower(@column_name))
ORDER BY table_qualifier, table_owner, table_name, column_name, privilege, grantee;
END
SELECT
TABLE_QUALIFIER,
TABLE_OWNER,
TABLE_NAME,
COLUMN_NAME,
GRANTOR,
GRANTEE,
PRIVILEGE,
IS_GRANTABLE
FROM sys.sp_column_privileges_view
WHERE pg_catalog.lower(@table_name) = pg_catalog.lower(table_name)
AND (pg_catalog.lower('dbo')= pg_catalog.lower(table_owner))
AND ((SELECT COALESCE(@table_qualifier,'')) = '' OR pg_catalog.lower(table_qualifier) = pg_catalog.lower(@table_qualifier))
AND ((SELECT COALESCE(@column_name,'')) = '' OR pg_catalog.lower(column_name) LIKE pg_catalog.lower(@column_name))
ORDER BY table_qualifier, table_owner, table_name, column_name, privilege, grantee;
END
ELSE
BEGIN
Expand Down Expand Up @@ -892,7 +867,7 @@ BEGIN
JOIN information_schema.table_privileges t4 ON t1.relname = t4.table_name
WHERE t4.privilege_type = 'DELETE';
END;
$$ LANGUAGE plpgsql;
$$ LANGUAGE plpgsql STABLE PARALLEL SAFE;

CREATE OR REPLACE VIEW sys.sp_table_privileges_view AS
-- Will use sp_column_priivleges_view to get information from SELECT, INSERT and REFERENCES (only need permission from 1 column in table)
Expand Down