kayak / pypika

PyPika is a python SQL query builder that exposes the full richness of the SQL language using a syntax that reflects the resulting query. PyPika excels at all sorts of SQL queries but is especially useful for data analysis.
http://pypika.readthedocs.io/en/latest/
Apache License 2.0
2.5k stars 295 forks source link

feat: Support creating/dropping indices on tables #753

Closed tazarov closed 1 year ago

tazarov commented 1 year ago
AzisK commented 1 year ago

Could you also add this possibility in the documentation in the README?

tazarov commented 1 year ago

@AzisK done, sorry for the oversight :)

AzisK commented 1 year ago

Good job in general, left one more comment

AzisK commented 1 year ago

It would be great to test on probably to most popular database, i.e. MySQL

tazarov commented 1 year ago

It would be great to test on probably to most popular database, i.e. MySQL

let me do that real quick.

tazarov commented 1 year ago

MySQL seems to work:

mysql> CREATE DATABASE my_database;
Query OK, 1 row affected (0.01 sec)

mysql> USE my_database;
Database changed
mysql> CREATE TABLE person (
    ->     id INT PRIMARY KEY AUTO_INCREMENT,
    ->     first_name VARCHAR(50),
    ->     last_name VARCHAR(50),
    ->     email VARCHAR(100),
    ->     date_of_birth DATE
    -> );
Query OK, 0 rows affected (0.05 sec)

mysql> INSERT INTO person (first_name, last_name, email, date_of_birth) VALUES
    -> ('John', 'Doe', 'john.doe@example.com', '1980-01-01'),
    -> ('Jane', 'Doe', 'jane.doe@example.com', '1985-05-15');
Query OK, 2 rows affected (0.03 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> CREATE INDEX my_index
    ->     ON person (first_name, last_name)
    -> ;
Query OK, 0 rows affected (0.09 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> EXPLAIN SELECT * FROM person WHERE first_name = 'John' AND last_name = 'Doe';
+----+-------------+--------+------------+------+---------------+----------+---------+-------------+------+----------+-------+
| id | select_type | table  | partitions | type | possible_keys | key      | key_len | ref         | rows | filtered | Extra |
+----+-------------+--------+------------+------+---------------+----------+---------+-------------+------+----------+-------+
|  1 | SIMPLE      | person | NULL       | ref  | my_index      | my_index | 106     | const,const |    1 |   100.00 | NULL  |
+----+-------------+--------+------------+------+---------------+----------+---------+-------------+------+----------+-------+
1 row in set, 1 warning (0.05 sec)
tazarov commented 1 year ago

@AzisK do you want me to fix the lining issues?

AzisK commented 1 year ago

You mean linting, right? It would be good. You can also setup https://pre-commit.com/ and it will do it for you automatically

tazarov commented 1 year ago

You mean linting, right? It would be good. You can also setup https://pre-commit.com/ and it will do it for you automatically

let me do that now.

tazarov commented 1 year ago

I have the following pre-commit hooks yaml if you want I can commit that too for those that want linting locally:

repos:
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v4.4.0
    hooks:
      - id: trailing-whitespace
      - id: mixed-line-ending
      - id: end-of-file-fixer
      - id: requirements-txt-fixer
      - id: check-yaml
        args: ["--allow-multiple-documents"]
      - id: check-xml
      - id: check-merge-conflict
      - id: check-case-conflict
      - id: check-docstring-first

  - repo: https://github.com/psf/black
    # https://github.com/psf/black/issues/2493
    rev: "refs/tags/23.3.0:refs/tags/23.3.0"
    hooks:
      - id: black

  - repo: https://github.com/PyCQA/flake8
    rev: 6.0.0
    hooks:
      - id: flake8
        args:
          - "--extend-ignore=E203,E501,E503"
          - "--max-line-length=88"
AzisK commented 1 year ago

I believe there is no need since the repo already has pre-commit-config defined

tazarov commented 1 year ago

@AzisK I think we're good to go then

AzisK commented 1 year ago

Yes, everything looks good. I am merging this but the version bump will happen later. Thanks for your work again