|
| 1 | +//! CREATE INDEX naming, SHOW INDEXES, and parse-time shape tests. |
| 2 | +//! |
| 3 | +//! The "silent no-op" regression mode (DDL parses, audit records |
| 4 | +//! ownership, but the secondary index is never wired into the |
| 5 | +//! collection config) is guarded here at the registration surface. |
| 6 | +//! Deeper behavioral checks (planner, backfill, partial) live in |
| 7 | +//! sibling files. |
| 8 | +
|
| 9 | +use super::common::pgwire_harness::TestServer; |
| 10 | + |
| 11 | +#[tokio::test(flavor = "multi_thread", worker_threads = 4)] |
| 12 | +async fn create_index_named() { |
| 13 | + let server = TestServer::start().await; |
| 14 | + |
| 15 | + server.exec("CREATE COLLECTION idx_named").await.unwrap(); |
| 16 | + server |
| 17 | + .exec("INSERT INTO idx_named { id: 'a', role: 'admin' }") |
| 18 | + .await |
| 19 | + .unwrap(); |
| 20 | + |
| 21 | + // Named index — standard SQL form. |
| 22 | + server |
| 23 | + .exec("CREATE INDEX my_idx ON idx_named(role)") |
| 24 | + .await |
| 25 | + .unwrap(); |
| 26 | +} |
| 27 | + |
| 28 | +#[tokio::test(flavor = "multi_thread", worker_threads = 4)] |
| 29 | +async fn create_index_unnamed_auto_name() { |
| 30 | + let server = TestServer::start().await; |
| 31 | + |
| 32 | + server.exec("CREATE COLLECTION idx_unnamed").await.unwrap(); |
| 33 | + server |
| 34 | + .exec("INSERT INTO idx_unnamed { id: 'a', email: 'a@b.com' }") |
| 35 | + .await |
| 36 | + .unwrap(); |
| 37 | + |
| 38 | + // No name — should auto-generate name and succeed. |
| 39 | + server |
| 40 | + .exec("CREATE INDEX ON idx_unnamed(email)") |
| 41 | + .await |
| 42 | + .unwrap(); |
| 43 | +} |
| 44 | + |
| 45 | +#[tokio::test(flavor = "multi_thread", worker_threads = 4)] |
| 46 | +async fn create_index_fields_keyword() { |
| 47 | + let server = TestServer::start().await; |
| 48 | + |
| 49 | + server.exec("CREATE COLLECTION idx_fields").await.unwrap(); |
| 50 | + server |
| 51 | + .exec("INSERT INTO idx_fields { id: 'a', tag: 'rust' }") |
| 52 | + .await |
| 53 | + .unwrap(); |
| 54 | + |
| 55 | + // FIELDS keyword form — should succeed. |
| 56 | + server |
| 57 | + .exec("CREATE INDEX ON idx_fields FIELDS tag") |
| 58 | + .await |
| 59 | + .unwrap(); |
| 60 | +} |
| 61 | + |
| 62 | +#[tokio::test(flavor = "multi_thread", worker_threads = 4)] |
| 63 | +async fn create_unique_index_unnamed() { |
| 64 | + let server = TestServer::start().await; |
| 65 | + |
| 66 | + server.exec("CREATE COLLECTION idx_unique").await.unwrap(); |
| 67 | + server |
| 68 | + .exec("INSERT INTO idx_unique { id: 'a', code: 'ABC' }") |
| 69 | + .await |
| 70 | + .unwrap(); |
| 71 | + |
| 72 | + // Unnamed UNIQUE index. |
| 73 | + server |
| 74 | + .exec("CREATE UNIQUE INDEX ON idx_unique(code)") |
| 75 | + .await |
| 76 | + .unwrap(); |
| 77 | +} |
| 78 | + |
| 79 | +#[tokio::test(flavor = "multi_thread", worker_threads = 4)] |
| 80 | +async fn show_indexes_lists_created_index() { |
| 81 | + let server = TestServer::start().await; |
| 82 | + |
| 83 | + server.exec("CREATE COLLECTION idx_show").await.unwrap(); |
| 84 | + server |
| 85 | + .exec("CREATE INDEX idx_show_role ON idx_show(role)") |
| 86 | + .await |
| 87 | + .unwrap(); |
| 88 | + |
| 89 | + // Positive lock-in: SHOW INDEXES must list a freshly created index. This |
| 90 | + // is the user-visible confirmation that creation succeeded; without it, |
| 91 | + // operators have no feedback channel. (First-column read of `query_text` |
| 92 | + // returns the index name.) |
| 93 | + let names = server |
| 94 | + .query_text("SHOW INDEXES") |
| 95 | + .await |
| 96 | + .expect("SHOW INDEXES must succeed"); |
| 97 | + assert!( |
| 98 | + names.iter().any(|n| n == "idx_show_role"), |
| 99 | + "SHOW INDEXES must list created index, got: {names:?}" |
| 100 | + ); |
| 101 | +} |
0 commit comments