Skip to content
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
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pgdog/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ toml = "0.8"
pgdog-plugin.workspace = true
tokio-util = { version = "0.7", features = ["rt"] }
fnv = "1"
itoa = "1"
ryu = "1"
scram = { git = "https://github.com/pgdogdev/scram.git", rev = "053e108210a35232efe60023ec43288fd601d8c4" }
base64 = "0.22"
md5 = "0.7"
Expand Down
4 changes: 3 additions & 1 deletion pgdog/src/frontend/router/parser/rewrite/statement/offset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ impl OffsetPlan {
let fmt = bind.parameter_format(idx)?;
let param = match fmt {
Format::Binary => Parameter::new(&(new_limit as i64).to_be_bytes()),
Format::Text => Parameter::new(new_limit.to_string().as_bytes()),
Format::Text => {
Parameter::new(itoa::Buffer::new().format(new_limit).as_bytes())
}
};
bind.set_param(idx, param);
}
Expand Down
2 changes: 1 addition & 1 deletion pgdog/src/frontend/router/parser/rewrite/statement/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl RewritePlan {
let id = generator.next_id();
let param = match format {
Format::Binary => Parameter::new(&id.to_be_bytes()),
Format::Text => Parameter::new(id.to_string().as_bytes()),
Format::Text => Parameter::new(itoa::Buffer::new().format(id).as_bytes()),
};
bind.push_param(param, format);
}
Expand Down
14 changes: 8 additions & 6 deletions pgdog/src/frontend/router/parser/rewrite/statement/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,15 +353,17 @@ impl Insert {
bind.push_param(param.parameter().clone(), param.format())
}

Value::Integer(int) => {
bind.push_param(Parameter::new(int.to_string().as_bytes()), Format::Text)
}
Value::Integer(int) => bind.push_param(
Parameter::new(itoa::Buffer::new().format(int).as_bytes()),
Format::Text,
),

Value::String(s) => bind.push_param(Parameter::new(s.as_bytes()), Format::Text),

Value::Float(f) => {
bind.push_param(Parameter::new(f.to_string().as_bytes()), Format::Text)
}
Value::Float(f) => bind.push_param(
Parameter::new(ryu::Buffer::new().format(f).as_bytes()),
Format::Text,
),

Value::Boolean(b) => bind.push_param(
Parameter::new(if b { "t".as_bytes() } else { "f".as_bytes() }),
Expand Down
7 changes: 2 additions & 5 deletions pgdog/src/frontend/router/sharding/hasher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl Hasher {
pub fn bigint(&self, value: i64) -> u64 {
match self {
Hasher::Postgres => bigint(value),
Hasher::Sha1 => Self::sha1(value.to_string().as_bytes()),
Hasher::Sha1 => Self::sha1(itoa::Buffer::new().format(value).as_bytes()),
}
}

Expand All @@ -38,10 +38,7 @@ impl Hasher {
hasher.update(bytes);
let hash = hasher.finalize();

let hex = format!("{:x}", hash);
let key = i64::from_str_radix(&hex[hex.len() - 8..], 16).unwrap();

key as u64
u32::from_be_bytes([hash[16], hash[17], hash[18], hash[19]]) as u64
}
}

Expand Down
4 changes: 3 additions & 1 deletion pgdog/src/net/parameter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ impl ToBytes for ParameterValue {
.join(", ".as_bytes());
bytes.put(Bytes::from(values));
}
Self::Integer(integer) => bytes.put_slice(integer.to_string().as_bytes()),
Self::Integer(integer) => {
bytes.put_slice(itoa::Buffer::new().format(*integer).as_bytes())
}
}
bytes.put_u8(0);

Expand Down
Loading