diff --git a/Cargo.lock b/Cargo.lock index 134f1b0c1b..15480055cd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1359,6 +1359,7 @@ dependencies = [ "chrono", "crc32c", "hex", + "lazy_static", "log", "rand", "regex", diff --git a/postgres_ffi/Cargo.toml b/postgres_ffi/Cargo.toml index f14b3f8954..0c829d4b7f 100644 --- a/postgres_ffi/Cargo.toml +++ b/postgres_ffi/Cargo.toml @@ -15,6 +15,7 @@ byteorder = "1.4.3" anyhow = "1.0" crc32c = "0.6.0" hex = "0.4.3" +lazy_static = "1.4" log = "0.4.14" thiserror = "1.0" workspace_hack = { path = "../workspace_hack" } diff --git a/postgres_ffi/src/relfile_utils.rs b/postgres_ffi/src/relfile_utils.rs index 80992ce71c..ef022aed95 100644 --- a/postgres_ffi/src/relfile_utils.rs +++ b/postgres_ffi/src/relfile_utils.rs @@ -2,6 +2,7 @@ //! Common utilities for dealing with PostgreSQL relation files. //! use crate::pg_constants; +use lazy_static::lazy_static; use regex::Regex; #[derive(Debug, Clone, thiserror::Error, PartialEq)] @@ -63,9 +64,11 @@ pub fn forknumber_to_name(forknum: u8) -> Option<&'static str> { /// See functions relpath() and _mdfd_segpath() in PostgreSQL sources. /// pub fn parse_relfilename(fname: &str) -> Result<(u32, u8, u32), FilePathError> { - let re = Regex::new(r"^(?P\d+)(_(?P[a-z]+))?(\.(?P\d+))?$").unwrap(); - - let caps = re.captures(fname).ok_or(FilePathError::InvalidFileName)?; + lazy_static! { + static ref RELFILE_RE: Regex = + Regex::new(r"^(?P\d+)(_(?P[a-z]+))?(\.(?P\d+))?$").unwrap(); + } + let caps = RELFILE_RE.captures(fname).ok_or(FilePathError::InvalidFileName)?; let relnode_str = caps.name("relnode").unwrap().as_str(); let relnode = relnode_str.parse::()?;