8000 MySQL: upload, document listing and root-folder lookup scale with dataset size (v1.0.0) · Issue #22805 · infiniflow/ragflow · GitHub
[go: up one dir, main page]

Skip to content

MySQL: upload, document listing and root-folder lookup scale with dataset size (v1.0.0) #22805

Backlog

Description

@loispostula

Environment: RAGFlow v1.0.0 (Go server built from db1cd592), MySQL 8.4 Group Replication, Elasticsearch. One dataset with ~37,000 documents. The code below is unchanged on main at bb7b3c2.

1. The duplicate-name check reads the whole dataset on every upload

DocumentDAO.NameExistsInKB (internal/dao/document.go) runs WHERE LOWER(name) = LOWER(?) AND kb_id = ?. LOWER(name) prevents the use of the index on name, so MySQL reads every document of the dataset through idx_document_kb_id (EXPLAIN: type: ref, rows: 33695). It took 10 to 14 s per call for us.

UniqueFileName repeats it for every name(N) candidate, so an attachment name that is already common (for example image001.png) costs N+1 full reads and the upload exceeds client timeouts.

Workaround that worked for us:

ALTER TABLE document ADD INDEX idx_document_kb_lower_name (kb_id, (LOWER(name)));

The check dropped to 10 ms and our upload throughput went from ~37 to ~225 documents per minute. Shipping that index with the schema, or relying on the column's case-insensitive collation (name = ?), would fix it for everyone.

2. LatestEventsByPipelineLogIDs reads all of ingestion_task_log

WHERE id IN (SELECT MAX(id) ... WHERE pipeline_log_id IN (...) GROUP BY pipeline_log_id) (internal/dao/ingestion_log.go). MySQL can't turn a subquery with GROUP BY into a semijoin, so it reads the whole table and checks each row against the subquery's result. With 1.08 million rows: 2.15 s for the bare query (EXPLAIN ANALYZE), and 10.9 s on average in the slow log. This query runs for every page of GET /datasets/:id/documents.

Suggested fix: run the MAX(id) query first, then WHERE id IN (<ids>) on the primary key.

3. GetRootFolder reads every file of the tenant

WHERE tenant_id = ? AND parent_id = id (internal/dao/file.go). No index can serve a comparison between two columns, so it read 11,016 rows (99 ms) per upload, inside ensureKBFolder's transaction, which holds SELECT ... FOR UPDATE on the knowledgebase row. That serializes the uploads into a dataset behind this lookup.

Suggested fix: identify the root folder by an indexed column, or cache it.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0