-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathndbapi-list-indexes.lisp
More file actions
54 lines (42 loc) · 3.63 KB
/
ndbapi-list-indexes.lisp
File metadata and controls
54 lines (42 loc) · 3.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
;;; Copyright (c) 2022 Max-Gerd Retzlaff <mgr@matroid.org>, Datagraph GmbH.
;;; Distributed under the terms of the GNU General Public License, Version 2.0,
;;; see file LICENSE in the top level directory of this repository.
(in-package :ndb.list-indexes)
#|
Given the database as defined in the beginning commet of the
file ndbapi-simple-scan.lisp, here is a example session:
CL-USER> (ndb.list-indexes:list-indexes :connection-string "localhost:1186,localhost:1187" :database-name "mgr" :table-name "test")
((:ID 26 :NAME "spog" :SCHEMA "def" :DATABASE "sys" :TYPE :+OTY-ORDERED-INDEX+)
(:ID 25 :NAME "gosp" :SCHEMA "def" :DATABASE "sys" :TYPE :+OTY-ORDERED-INDEX+)
(:ID 23 :NAME "gspo" :SCHEMA "def" :DATABASE "sys" :TYPE :+OTY-ORDERED-INDEX+)
(:ID 22 :NAME "s" :SCHEMA "def" :DATABASE "sys" :TYPE :+OTY-ORDERED-INDEX+)
(:ID 24 :NAME "gpos" :SCHEMA "def" :DATABASE "sys" :TYPE :+OTY-ORDERED-INDEX+)
(:ID 27 :NAME "posg" :SCHEMA "def" :DATABASE "sys" :TYPE :+OTY-ORDERED-INDEX+)
(:ID 28 :NAME "ospg" :SCHEMA "def" :DATABASE "sys" :TYPE :+OTY-ORDERED-INDEX+))
The type of the index with name "s" is a surprise.
I suspected it should return :+UniqueHashIndex+.
But Mysql also reports it as such:
mysql> show indexes from test where Key_name = "s";
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Visible | Expression |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+
| test | 0 | s | 1 | s | A | NULL | NULL | NULL | | BTREE | | | YES | NULL |
| test | 0 | s | 2 | p | A | NULL | NULL | NULL | | BTREE | | | YES | NULL |
| test | 0 | s | 3 | o | A | NULL | NULL | NULL | | BTREE | | | YES | NULL |
| test | 0 | s | 4 | g | A | 10 | NULL | NULL | | BTREE | | | YES | NULL |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+
4 rows in set (0.01 sec)
|#
(defun list-indexes (&key connection-string database-name table-name)
(ndbapi:ensure-ndb-api-initialisation)
(ndbapi:with-ndb-cluster-connection (ndbapi:*connection* (connection-string)
:name "ndbapi-list-indexes")
(ndbapi:with-ndb (ndb (ndbapi:*connection* database-name))
(ndbapi:with-foreign-struct (list (list :count 0) '(:struct ndbapi.ffi:list))
(ndbapi:dictionary-list-indexes (ndbapi:ndb-get-dictionary ndb) list table-name)
(loop with count = (cffi:foreign-slot-value list '(:struct ndbapi.ffi:list) :count)
with elements = (cffi:foreign-slot-value list '(:struct ndbapi.ffi:list) :elements)
for i below count
for element = (cffi:mem-aptr elements '(:struct ndbapi.ffi:element) i)
collect (loop for field in '(:id :name :schema :database :type)
nconc (list field (cffi:foreign-slot-value element '(:struct ndbapi.ffi:element) field))))))))