{"slug": "ann-search-where-clause-causing-full-table-scan-in-oceanbase-4", "title": "ANN_SEARCH + WHERE clause causing full table scan in OceanBase 4.", "summary": "A multi-tenant enterprise RAG system using OceanBase 4.3.x (MySQL mode) experiences a full table scan when combining ANN_SEARCH with a WHERE clause for tenant isolation, despite having a native VSAG vector index on 1536-dimensional embeddings and B-tree indexes on tenant_id and status. The query SELECT doc_id, chunk_text FROM enterprise_knowledge_base WHERE tenant_id = 10025 AND status = 'ACTIVE' ORDER BY APPROX_DISTANCE(embedding_data, [0.015, -0.023, 0.112, 0.045]) APPROX_TOP 5 fails to use the vector index efficiently, causing high latency on a dataset of a few million rows. Users report that restructuring the query with a subquery or derived table resolves the issue.", "body_md": "# ANN_SEARCH + WHERE clause causing full table scan in OceanBase 4.\n\nWe are building a multi-tenant enterprise\n\n[RAG](/en/tags/rag/)system and just hit a gnarly performance issue with OceanBase 4.3.x (MySQL mode). The setup is pretty straightforward: a large table that holds 1536-dimensional embeddings (FLOAT array) with a native VSAG vector index, plus a`tenant_id`\n\ninteger column with a standard B-tree index and a `status`\n\ncolumn. The idea was to combine vector similarity search with a scalar WHERE clause for tenant isolation — a very common hybrid query pattern in production RAG.Here’s the exact query we’re stuck with:\n\n```\nSELECT doc_id, chunk_text\nFROM enterprise_knowledge_base\nWHERE tenant_id = 10025 AND status = 'ACTIVE'\nORDER BY APPROX_DISTANCE(embedding_data, [0.015, -0.023, 0.112, 0.045])\nAPPROX_TOP 5;\n```\n\nWe expected OceanBase to pre‑filter on `tenant_id`\n\nand `status`\n\nfirst, then run the ANN search only on the matching rows. That would make the vector index work on a much smaller set, keeping latency low even as the total dataset grows. But when we tested it against a realistic dataset (a few million rows across\n\n[Next My AI Agent Task Organization System →](/en/threads/4441/)\n\n## All Replies （4）\n\nA\n\nDoes the vector index get used after the query is restructured?\n\n0\n\nR\n\nThat's a good question — I've seen cases where restructuring helps, but OceanBase still struggles with hybrid queries.\n\n0\n\nD\n\nWe hit the same problem; splitting the WHERE into a subquery fixed it for us.\n\n0\n\nR\n\nWe experienced this as well; rewriting the query with a derived table fixed it.\n\n0", "url": "https://wpnews.pro/news/ann-search-where-clause-causing-full-table-scan-in-oceanbase-4", "canonical_source": "https://promptcube3.com/en/threads/4453/", "published_at": "2026-07-31 00:07:14+00:00", "updated_at": "2026-07-31 00:42:11.672087+00:00", "lang": "en", "topics": ["artificial-intelligence"], "entities": ["OceanBase", "RAG", "VSAG"], "alternates": {"html": "https://wpnews.pro/news/ann-search-where-clause-causing-full-table-scan-in-oceanbase-4", "markdown": "https://wpnews.pro/news/ann-search-where-clause-causing-full-table-scan-in-oceanbase-4.md", "text": "https://wpnews.pro/news/ann-search-where-clause-causing-full-table-scan-in-oceanbase-4.txt", "jsonld": "https://wpnews.pro/news/ann-search-where-clause-causing-full-table-scan-in-oceanbase-4.jsonld"}}