Skip to content
Open
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
31 changes: 16 additions & 15 deletions src/ast/dml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ use super::{
pub struct Insert {
/// Token for the `INSERT` keyword (or its substitutes)
pub insert_token: AttachedToken,
/// A query optimizer hint
/// Query optimizer hints
///
/// [MySQL](https://dev.mysql.com/doc/refman/8.4/en/optimizer-hints.html)
/// [Oracle](https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/Comments.html#GUID-D316D545-89E2-4D54-977F-FC97815CD62E)
pub optimizer_hint: Option<OptimizerHint>,
pub optimizer_hints: Vec<OptimizerHint>,
/// Only for Sqlite
pub or: Option<SqliteOnConflict>,
/// Only for mysql
Expand Down Expand Up @@ -133,7 +133,7 @@ impl Display for Insert {

if let Some(on_conflict) = self.or {
f.write_str("INSERT")?;
if let Some(hint) = self.optimizer_hint.as_ref() {
for hint in &self.optimizer_hints {
write!(f, " {hint}")?;
}
write!(f, " {on_conflict} INTO {table_name} ")?;
Expand All @@ -147,7 +147,7 @@ impl Display for Insert {
"INSERT"
}
)?;
if let Some(hint) = self.optimizer_hint.as_ref() {
for hint in &self.optimizer_hints {
write!(f, " {hint}")?;
}
if let Some(priority) = self.priority {
Expand Down Expand Up @@ -267,11 +267,11 @@ impl Display for Insert {
pub struct Delete {
/// Token for the `DELETE` keyword
pub delete_token: AttachedToken,
/// A query optimizer hint
/// Query optimizer hints
///
/// [MySQL](https://dev.mysql.com/doc/refman/8.4/en/optimizer-hints.html)
/// [Oracle](https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/Comments.html#GUID-D316D545-89E2-4D54-977F-FC97815CD62E)
pub optimizer_hint: Option<OptimizerHint>,
pub optimizer_hints: Vec<OptimizerHint>,
/// Multi tables delete are supported in mysql
pub tables: Vec<ObjectName>,
/// FROM
Expand All @@ -291,7 +291,7 @@ pub struct Delete {
impl Display for Delete {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("DELETE")?;
if let Some(hint) = self.optimizer_hint.as_ref() {
for hint in &self.optimizer_hints {
f.write_str(" ")?;
hint.fmt(f)?;
}
Expand Down Expand Up @@ -345,11 +345,11 @@ impl Display for Delete {
pub struct Update {
/// Token for the `UPDATE` keyword
pub update_token: AttachedToken,
/// A query optimizer hint
/// Query optimizer hints
///
/// [MySQL](https://dev.mysql.com/doc/refman/8.4/en/optimizer-hints.html)
/// [Oracle](https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/Comments.html#GUID-D316D545-89E2-4D54-977F-FC97815CD62E)
pub optimizer_hint: Option<OptimizerHint>,
pub optimizer_hints: Vec<OptimizerHint>,
/// TABLE
pub table: TableWithJoins,
/// Column assignments
Expand All @@ -368,11 +368,12 @@ pub struct Update {

impl Display for Update {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("UPDATE ")?;
if let Some(hint) = self.optimizer_hint.as_ref() {
hint.fmt(f)?;
f.write_str("UPDATE")?;
for hint in &self.optimizer_hints {
f.write_str(" ")?;
hint.fmt(f)?;
}
f.write_str(" ")?;
if let Some(or) = &self.or {
or.fmt(f)?;
f.write_str(" ")?;
Expand Down Expand Up @@ -419,10 +420,10 @@ impl Display for Update {
pub struct Merge {
/// The `MERGE` token that starts the statement.
pub merge_token: AttachedToken,
/// A query optimizer hint
/// Query optimizer hints
///
/// [Oracle](https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/Comments.html#GUID-D316D545-89E2-4D54-977F-FC97815CD62E)
pub optimizer_hint: Option<OptimizerHint>,
pub optimizer_hints: Vec<OptimizerHint>,
/// optional INTO keyword
pub into: bool,
/// Specifies the table to merge
Expand All @@ -440,7 +441,7 @@ pub struct Merge {
impl Display for Merge {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("MERGE")?;
if let Some(hint) = self.optimizer_hint.as_ref() {
for hint in &self.optimizer_hints {
write!(f, " {hint}")?;
}
if self.into {
Expand Down
16 changes: 13 additions & 3 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11579,12 +11579,19 @@ pub struct ResetStatement {
/// `SELECT`, `INSERT`, `UPDATE`, `REPLACE`, `MERGE`, and `DELETE` keywords in
/// the corresponding statements.
///
/// See [Select::optimizer_hint]
/// See [Select::optimizer_hints]
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub struct OptimizerHint {
/// the raw test of the optimizer hint without its markers
/// An optional prefix between the comment marker and `+`.
///
/// Standard optimizer hints like `/*+ ... */` have an empty prefix,
/// while system-specific hints like `/*abc+ ... */` have `prefix = "abc"`.
/// The prefix is any sequence of ASCII alphanumeric characters
/// immediately before the `+` marker.
pub prefix: String,
/// the raw text of the optimizer hint without its markers
pub text: String,
/// the style of the comment which `text` was extracted from,
/// e.g. `/*+...*/` or `--+...`
Expand Down Expand Up @@ -11614,11 +11621,14 @@ impl fmt::Display for OptimizerHint {
match &self.style {
OptimizerHintStyle::SingleLine { prefix } => {
f.write_str(prefix)?;
f.write_str(&self.prefix)?;
f.write_str("+")?;
f.write_str(&self.text)
}
OptimizerHintStyle::MultiLine => {
f.write_str("/*+")?;
f.write_str("/*")?;
f.write_str(&self.prefix)?;
f.write_str("+")?;
f.write_str(&self.text)?;
f.write_str("*/")
}
Expand Down
6 changes: 3 additions & 3 deletions src/ast/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,11 +445,11 @@ impl SelectModifiers {
pub struct Select {
/// Token for the `SELECT` keyword
pub select_token: AttachedToken,
/// A query optimizer hint
/// Query optimizer hints
///
/// [MySQL](https://dev.mysql.com/doc/refman/8.4/en/optimizer-hints.html)
/// [Oracle](https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/Comments.html#GUID-D316D545-89E2-4D54-977F-FC97815CD62E)
pub optimizer_hint: Option<OptimizerHint>,
pub optimizer_hints: Vec<OptimizerHint>,
/// `SELECT [DISTINCT] ...`
pub distinct: Option<Distinct>,
/// MySQL-specific SELECT modifiers.
Expand Down Expand Up @@ -521,7 +521,7 @@ impl fmt::Display for Select {
}
}

if let Some(hint) = self.optimizer_hint.as_ref() {
for hint in &self.optimizer_hints {
f.write_str(" ")?;
hint.fmt(f)?;
}
Expand Down
10 changes: 5 additions & 5 deletions src/ast/spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ impl Spanned for Delete {
fn span(&self) -> Span {
let Delete {
delete_token,
optimizer_hint: _,
optimizer_hints: _,
tables,
from,
using,
Expand Down Expand Up @@ -931,7 +931,7 @@ impl Spanned for Update {
fn span(&self) -> Span {
let Update {
update_token,
optimizer_hint: _,
optimizer_hints: _,
table,
assignments,
from,
Expand Down Expand Up @@ -1295,7 +1295,7 @@ impl Spanned for Insert {
fn span(&self) -> Span {
let Insert {
insert_token,
optimizer_hint: _,
optimizer_hints: _,
or: _, // enum, sqlite specific
ignore: _, // bool
into: _, // bool
Expand Down Expand Up @@ -2243,7 +2243,7 @@ impl Spanned for Select {
fn span(&self) -> Span {
let Select {
select_token,
optimizer_hint: _,
optimizer_hints: _,
distinct: _, // todo
select_modifiers: _,
top: _, // todo, mysql specific
Expand Down Expand Up @@ -2837,7 +2837,7 @@ WHERE id = 1
// ~ individual tokens within the statement
let Statement::Merge(Merge {
merge_token,
optimizer_hint: _,
optimizer_hints: _,
into: _,
table: _,
source: _,
Expand Down
2 changes: 1 addition & 1 deletion src/dialect/snowflake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1752,7 +1752,7 @@ fn parse_multi_table_insert(

Ok(Statement::Insert(Insert {
insert_token: insert_token.into(),
optimizer_hint: None,
optimizer_hints: vec![],
or: None,
ignore: false,
into: false,
Expand Down
4 changes: 2 additions & 2 deletions src/parser/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl Parser<'_> {

/// Parse a `MERGE` statement
pub fn parse_merge(&mut self, merge_token: TokenWithSpan) -> Result<Merge, ParserError> {
let optimizer_hint = self.maybe_parse_optimizer_hint()?;
let optimizer_hints = self.maybe_parse_optimizer_hints()?;
let into = self.parse_keyword(Keyword::INTO);

let table = self.parse_table_factor()?;
Expand All @@ -60,7 +60,7 @@ impl Parser<'_> {

Ok(Merge {
merge_token: merge_token.into(),
optimizer_hint,
optimizer_hints,
into,
table,
source,
Expand Down
Loading
Loading