mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-10-20 04:54:24 +02:00
* filer: escape LIKE wildcards in SQL list prefixes ListDirectoryPrefixedEntries bound prefix+"%" straight into a LIKE clause, so '_' and '%' in object names (e.g. Langfuse keys like call_03_...) acted as wildcards: wrong results and a ~40x slower range scan because (dirhash, name) can no longer be narrowed. Escape '!'/'%'/'_' in the prefix and declare ESCAPE '!' in the generated list SQL so every abstract_sql backend (mysql, mysql2, postgres, postgres2, sqlite) matches literally with identical semantics. '!' is used instead of '\' because SQLite shares SqlGenMysql but would reject the MySQL-style '\\' literal, and '\' would still need escaping itself. * filer: escape LIKE wildcards in YDB list prefixes Same wildcard-in-prefix bug as the abstract_sql backends: YQL LIKE treated '_' and '%' in the prefix as wildcards. Apply the shared LikePattern helper and declare ESCAPE '!' (YQL allows any escape char except '%', '_' and '\'). * test: cover literal '_'/'%'/'!' prefixes in sqlite filer listing End-to-end regression test through SqliteStore against a real database; runs in CI under the sqlite build tag.
74 lines
2.0 KiB
Go
74 lines
2.0 KiB
Go
//go:build ydb
|
|
|
|
package ydb
|
|
|
|
import asql "github.com/seaweedfs/seaweedfs/weed/filer/abstract_sql"
|
|
|
|
const (
|
|
upsertQuery = `
|
|
PRAGMA TablePathPrefix("%v");
|
|
DECLARE $dir_hash AS int64;
|
|
DECLARE $directory AS Utf8;
|
|
DECLARE $name AS Utf8;
|
|
DECLARE $meta AS String;
|
|
DECLARE $expire_at AS Optional<uint32>;
|
|
|
|
UPSERT INTO ` + asql.DEFAULT_TABLE + `
|
|
(dir_hash, name, directory, meta, expire_at)
|
|
VALUES
|
|
($dir_hash, $name, $directory, $meta, $expire_at);`
|
|
|
|
deleteQuery = `
|
|
PRAGMA TablePathPrefix("%v");
|
|
DECLARE $dir_hash AS int64;
|
|
DECLARE $directory AS Utf8;
|
|
DECLARE $name AS Utf8;
|
|
|
|
DELETE FROM ` + asql.DEFAULT_TABLE + `
|
|
WHERE dir_hash = $dir_hash AND directory = $directory AND name = $name;`
|
|
|
|
findQuery = `
|
|
PRAGMA TablePathPrefix("%v");
|
|
DECLARE $dir_hash AS int64;
|
|
DECLARE $directory AS Utf8;
|
|
DECLARE $name AS Utf8;
|
|
|
|
SELECT meta
|
|
FROM ` + asql.DEFAULT_TABLE + `
|
|
WHERE dir_hash = $dir_hash AND directory = $directory AND name = $name;`
|
|
|
|
deleteFolderChildrenQuery = `
|
|
PRAGMA TablePathPrefix("%v");
|
|
DECLARE $dir_hash AS int64;
|
|
DECLARE $directory AS Utf8;
|
|
|
|
DELETE FROM ` + asql.DEFAULT_TABLE + `
|
|
WHERE dir_hash = $dir_hash AND directory = $directory;`
|
|
|
|
listDirectoryQuery = `
|
|
PRAGMA TablePathPrefix("%v");
|
|
DECLARE $dir_hash AS int64;
|
|
DECLARE $directory AS Utf8;
|
|
DECLARE $start_name AS Utf8;
|
|
DECLARE $prefix AS Utf8;
|
|
DECLARE $limit AS Uint64;
|
|
|
|
SELECT name, meta
|
|
FROM ` + asql.DEFAULT_TABLE + `
|
|
WHERE dir_hash = $dir_hash AND directory = $directory and name > $start_name and name LIKE $prefix ESCAPE '!'
|
|
ORDER BY name ASC LIMIT $limit;`
|
|
|
|
listInclusiveDirectoryQuery = `
|
|
PRAGMA TablePathPrefix("%v");
|
|
DECLARE $dir_hash AS int64;
|
|
DECLARE $directory AS Utf8;
|
|
DECLARE $start_name AS Utf8;
|
|
DECLARE $prefix AS Utf8;
|
|
DECLARE $limit AS Uint64;
|
|
|
|
SELECT name, meta
|
|
FROM ` + asql.DEFAULT_TABLE + `
|
|
WHERE dir_hash = $dir_hash AND directory = $directory and name >= $start_name and name LIKE $prefix ESCAPE '!'
|
|
ORDER BY name ASC LIMIT $limit;`
|
|
)
|