Skip to content

Commit db1c3ea

Browse files
committed
rewrite pg_locks
1 parent 26779fc commit db1c3ea

File tree

2 files changed

+27
-31
lines changed

2 files changed

+27
-31
lines changed

src/frontend/src/catalog/system_catalog/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ prepare_sys_catalog! {
371371
{ BuiltinCatalog::Table(&PG_TABLES), read_pg_tables_info },
372372
{ BuiltinCatalog::View(&PG_PROC) },
373373
{ BuiltinCatalog::Table(&PG_SHADOW), read_user_info_shadow },
374-
{ BuiltinCatalog::Table(&PG_LOCKS), read_locks_info },
374+
{ BuiltinCatalog::View(&PG_LOCKS) },
375375
{ BuiltinCatalog::Table(&INFORMATION_SCHEMA_COLUMNS), read_columns_info },
376376
{ BuiltinCatalog::Table(&INFORMATION_SCHEMA_TABLES), read_tables_info },
377377
{ BuiltinCatalog::Table(&RW_DATABASES), read_rw_database_info },

src/frontend/src/catalog/system_catalog/pg_catalog/pg_locks.rs

+26-30
Original file line numberDiff line numberDiff line change
@@ -12,43 +12,39 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
use std::sync::LazyLock;
16+
1517
use risingwave_common::catalog::PG_CATALOG_SCHEMA_NAME;
16-
use risingwave_common::error::Result;
17-
use risingwave_common::row::OwnedRow;
1818
use risingwave_common::types::DataType;
1919

20-
use crate::catalog::system_catalog::{BuiltinTable, SysCatalogReaderImpl};
20+
use crate::catalog::system_catalog::{infer_dummy_view_sql, BuiltinView, SystemCatalogColumnsDef};
21+
22+
pub const PG_LOCKS_COLUMNS: &[SystemCatalogColumnsDef<'_>] = &[
23+
(DataType::Varchar, "locktype"),
24+
(DataType::Int32, "database"), // oid
25+
(DataType::Int32, "relation"), // oid
26+
(DataType::Int32, "page"),
27+
(DataType::Int16, "tuple"),
28+
(DataType::Varchar, "virtualxid"),
29+
(DataType::Int32, "transactionid"), // xid
30+
(DataType::Int32, "classid"), // oid
31+
(DataType::Int32, "objid"), // oid
32+
(DataType::Int16, "objsubid"),
33+
(DataType::Varchar, "virtualtransaction"),
34+
(DataType::Int32, "pid"),
35+
(DataType::Varchar, "mode"),
36+
(DataType::Boolean, "granted"),
37+
(DataType::Boolean, "fastpath"),
38+
(DataType::Timestamptz, "waitstart"),
39+
];
2140

2241
/// The catalog `pg_locks` provides access to information about the locks held by active processes
2342
/// within the database server.
2443
/// Reference: [`https://www.postgresql.org/docs/current/view-pg-locks.html`].
2544
/// Currently, we don't have any type of lock.
26-
pub const PG_LOCKS: BuiltinTable = BuiltinTable {
45+
pub static PG_LOCKS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
2746
name: "pg_locks",
2847
schema: PG_CATALOG_SCHEMA_NAME,
29-
columns: &[
30-
(DataType::Varchar, "locktype"),
31-
(DataType::Int32, "database"), // oid
32-
(DataType::Int32, "relation"), // oid
33-
(DataType::Int32, "page"),
34-
(DataType::Int16, "tuple"),
35-
(DataType::Varchar, "virtualxid"),
36-
(DataType::Int32, "transactionid"), // xid
37-
(DataType::Int32, "classid"), // oid
38-
(DataType::Int32, "objid"), // oid
39-
(DataType::Int16, "objsubid"),
40-
(DataType::Varchar, "virtualtransaction"),
41-
(DataType::Int32, "pid"),
42-
(DataType::Varchar, "mode"),
43-
(DataType::Boolean, "granted"),
44-
(DataType::Boolean, "fastpath"),
45-
(DataType::Timestamptz, "waitstart"),
46-
],
47-
pk: &[],
48-
};
49-
50-
impl SysCatalogReaderImpl {
51-
pub fn read_locks_info(&self) -> Result<Vec<OwnedRow>> {
52-
Ok(vec![])
53-
}
54-
}
48+
columns: PG_LOCKS_COLUMNS,
49+
sql: infer_dummy_view_sql(PG_LOCKS_COLUMNS),
50+
});

0 commit comments

Comments
 (0)