Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQLModel creates an index for every field in SQLite #152

Closed
8 tasks done
rabinadk1 opened this issue Nov 6, 2021 · 2 comments
Closed
8 tasks done

SQLModel creates an index for every field in SQLite #152

rabinadk1 opened this issue Nov 6, 2021 · 2 comments
Labels
question Further information is requested

Comments

@rabinadk1
Copy link
Contributor

First Check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn't find it.
  • I searched the SQLModel documentation, with the integrated search.
  • I already searched in Google "How to X in SQLModel" and didn't find any information.
  • I already read and followed all the tutorial in the docs and didn't find an answer.
  • I already checked if it is not related to SQLModel but to Pydantic.
  • I already checked if it is not related to SQLModel but to SQLAlchemy.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

from typing import Optional

from sqlmodel import Field, SQLModel

# Data Models


class HeroCreate(SQLModel):
    """
    Data Model for Hero Creation
    """

    name: str
    secret_name: str
    age: Optional[int] = None


class HeroRead(HeroCreate):
    """
    Data Model for Hero Read
    """

    id: int


class HeroUpdate(SQLModel):
    """
    Data Model for Hero Update
    """

    name: Optional[str] = None
    secret_name: Optional[str] = None
    age: Optional[int] = None


# Table Models


class Hero(HeroCreate, table=True):
    """
    Table Model for Hero
    """

    id: Optional[int] = Field(default=None, primary_key=True)

Description

  • Create a Hero Model
  • Save it to the database using SQLModel.metadata.create_all(engine)
  • The database has an index for every field.
    The default option should be no index, if not specified explicitly.

Operating System

Linux

Operating System Details

Kernel version: 5.14.14-arch1-1

SQLModel Version

0.0.4

Python Version

3.9.7

Additional Context

The output from the terminal when echo=True is shown below.

2021-11-06 15:45:40,513 INFO sqlalchemy.engine.Engine BEGIN (implicit)
2021-11-06 15:45:40,513 INFO sqlalchemy.engine.Engine PRAGMA main.table_info("user")
2021-11-06 15:45:40,513 INFO sqlalchemy.engine.Engine [raw sql] ()
2021-11-06 15:45:40,514 INFO sqlalchemy.engine.Engine PRAGMA temp.table_info("user")
2021-11-06 15:45:40,514 INFO sqlalchemy.engine.Engine [raw sql] ()
2021-11-06 15:45:40,515 INFO sqlalchemy.engine.Engine PRAGMA main.table_info("hero")
2021-11-06 15:45:40,515 INFO sqlalchemy.engine.Engine [raw sql] ()
2021-11-06 15:45:40,515 INFO sqlalchemy.engine.Engine PRAGMA temp.table_info("hero")
2021-11-06 15:45:40,515 INFO sqlalchemy.engine.Engine [raw sql] ()
2021-11-06 15:45:40,517 INFO sqlalchemy.engine.Engine 
CREATE TABLE user (
	username VARCHAR NOT NULL, 
	email VARCHAR, 
	full_name VARCHAR NOT NULL, 
	id INTEGER, 
	hashed_password VARCHAR NOT NULL, 
	PRIMARY KEY (id)
)


2021-11-06 15:45:40,517 INFO sqlalchemy.engine.Engine [no key 0.00026s] ()
2021-11-06 15:45:40,601 INFO sqlalchemy.engine.Engine CREATE INDEX ix_user_email ON user (email)
2021-11-06 15:45:40,601 INFO sqlalchemy.engine.Engine [no key 0.00030s] ()
2021-11-06 15:45:40,693 INFO sqlalchemy.engine.Engine CREATE INDEX ix_user_full_name ON user (full_name)
2021-11-06 15:45:40,693 INFO sqlalchemy.engine.Engine [no key 0.00037s] ()
2021-11-06 15:45:40,783 INFO sqlalchemy.engine.Engine CREATE INDEX ix_user_id ON user (id)
2021-11-06 15:45:40,783 INFO sqlalchemy.engine.Engine [no key 0.00049s] ()
2021-11-06 15:45:40,871 INFO sqlalchemy.engine.Engine CREATE INDEX ix_user_username ON user (username)
2021-11-06 15:45:40,872 INFO sqlalchemy.engine.Engine [no key 0.00035s] ()
2021-11-06 15:45:40,961 INFO sqlalchemy.engine.Engine CREATE INDEX ix_user_hashed_password ON user (hashed_password)
2021-11-06 15:45:40,961 INFO sqlalchemy.engine.Engine [no key 0.00029s] ()
2021-11-06 15:45:41,040 INFO sqlalchemy.engine.Engine 
CREATE TABLE hero (
	name VARCHAR NOT NULL, 
	secret_name VARCHAR NOT NULL, 
	age INTEGER, 
	id INTEGER, 
	PRIMARY KEY (id)
)


2021-11-06 15:45:41,040 INFO sqlalchemy.engine.Engine [no key 0.00029s] ()
2021-11-06 15:45:41,151 INFO sqlalchemy.engine.Engine CREATE INDEX ix_hero_secret_name ON hero (secret_name)
2021-11-06 15:45:41,151 INFO sqlalchemy.engine.Engine [no key 0.00029s] ()
2021-11-06 15:45:41,263 INFO sqlalchemy.engine.Engine CREATE INDEX ix_hero_age ON hero (age)
2021-11-06 15:45:41,263 INFO sqlalchemy.engine.Engine [no key 0.00028s] ()
2021-11-06 15:45:41,375 INFO sqlalchemy.engine.Engine CREATE INDEX ix_hero_id ON hero (id)
2021-11-06 15:45:41,375 INFO sqlalchemy.engine.Engine [no key 0.00050s] ()
2021-11-06 15:45:41,487 INFO sqlalchemy.engine.Engine CREATE INDEX ix_hero_name ON hero (name)
2021-11-06 15:45:41,487 INFO sqlalchemy.engine.Engine [no key 0.00050s] ()
2021-11-06 15:45:41,597 INFO sqlalchemy.engine.Engine COMMIT
@rabinadk1 rabinadk1 added the question Further information is requested label Nov 6, 2021
@rabinadk1 rabinadk1 changed the title SQLModel create an index for every field in SQLite SQLModel creates an index for every field in SQLite Nov 6, 2021
@rabinadk1
Copy link
Contributor Author

I think this issue is related to #11

@rabinadk1
Copy link
Contributor Author

Resolved by #205

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant