========== Skip Limit Logic for DUAL Queries ========== skipAddLimit checks if the statement needs a limit clause. For Oracle, we think the statement like "SELECT xxx FROM DUAL" does not need a limit clause. More details, xxx can not be a subquery.
(stmt string)
| 346 | // For Oracle, we think the statement like "SELECT xxx FROM DUAL" does not need a limit clause. |
| 347 | // More details, xxx can not be a subquery. |
| 348 | func skipAddLimit(stmt string) (bool, error) { |
| 349 | list, err := plsqlparser.ParsePLSQLOmni(stmt) |
| 350 | if err != nil { |
| 351 | return false, err |
| 352 | } |
| 353 | if list == nil || len(list.Items) == 0 { |
| 354 | return false, nil |
| 355 | } |
| 356 | // Multiple statements should not skip limit |
| 357 | if len(list.Items) > 1 { |
| 358 | return false, nil |
| 359 | } |
| 360 | raw, ok := list.Items[0].(*oracleast.RawStmt) |
| 361 | if !ok { |
| 362 | return false, nil |
| 363 | } |
| 364 | selectStmt, ok := raw.Stmt.(*oracleast.SelectStmt) |
| 365 | if !ok { |
| 366 | return false, nil |
| 367 | } |
| 368 | if !isSimpleOracleSelect(selectStmt) { |
| 369 | return false, nil |
| 370 | } |
| 371 | if !isOracleSelectFromDual(selectStmt) { |
| 372 | return false, nil |
| 373 | } |
| 374 | return !hasOracleSubqueriesInSelection(selectStmt), nil |
| 375 | } |
| 376 | |
| 377 | func isSimpleOracleSelect(selectStmt *oracleast.SelectStmt) bool { |
| 378 | return selectStmt.WithClause == nil && |
no test coverage detected