Sto creando un sito di e-commerce, utilizzando MySQL per l'archiviazione dei dati. Ecco il mio ERD:
CREATETABLE'admins'('id'int(10)UNSIGNEDNOTNULL,'shop_id'int(10)UNSIGNEDDEFAULTNULL,'name'varchar(75)COLLATEutf8mb4_unicode_ciNOTNULL,'username'varchar(50)COLLATEutf8mb4_unicode_ciNOTNULL,'phone'int(11)NOTNULL,'email'varchar(100)COLLATEutf8mb4_unicode_ciNOTNULL,'email_verified_at'timestampNULLDEFAULTNULL,'password'varchar(255)COLLATEutf8mb4_unicode_ciNOTNULL,'remember_token'varchar(100)COLLATEutf8mb4_unicode_ciDEFAULTNULL)ENGINE=InnoDBDEFAULTCHARSET=utf8mb4COLLATE=utf8mb4_unicode_ci;CREATETABLE'brands'('id'int(10)UNSIGNEDNOTNULL,'name'varchar(255)COLLATEutf8mb4_unicode_ciNOTNULL)ENGINE=InnoDBDEFAULTCHARSET=utf8mb4COLLATE=utf8mb4_unicode_ci;CREATETABLE'brand_models'('id'int(10)UNSIGNEDNOTNULL,'brand_id'int(10)UNSIGNEDDEFAULTNULL,'product_type_id'int(10)UNSIGNEDDEFAULTNULL,'name'varchar(255)COLLATEutf8mb4_unicode_ciNOTNULL)ENGINE=InnoDBDEFAULTCHARSET=utf8mb4COLLATE=utf8mb4_unicode_ci;CREATETABLE'categories'('id'int(10)UNSIGNEDNOTNULL,'_lft'int(10)UNSIGNEDNOTNULLDEFAULT'0','_rgt'int(10)UNSIGNEDNOTNULLDEFAULT'0','parent_id'int(10)UNSIGNEDDEFAULTNULL,'top'tinyint(4)NOTNULL,'sort_order'int(11)NOTNULL,'status'tinyint(4)NOTNULL)ENGINE=InnoDBDEFAULTCHARSET=utf8mb4COLLATE=utf8mb4_unicode_ci;CREATETABLE'countries'('id'int(10)UNSIGNEDNOTNULL,'name'varchar(255)COLLATEutf8mb4_unicode_ciNOTNULL)ENGINE=InnoDBDEFAULTCHARSET=utf8mb4COLLATE=utf8mb4_unicode_ci;CREATETABLE'markets'('id'int(10)UNSIGNEDNOTNULL,'name'varchar(255)COLLATEutf8mb4_unicode_ciNOTNULL,'address'varchar(255)COLLATEutf8mb4_unicode_ciNOTNULL,'shops_count'int(11)NOTNULL,'products_count'int(11)NOTNULL,'photo'varchar(255)COLLATEutf8mb4_unicode_ciNOTNULL,'status'tinyint(4)NOTNULL)ENGINE=InnoDBDEFAULTCHARSET=utf8mb4COLLATE=utf8mb4_unicode_ci;CREATETABLE'migrations'('id'int(10)UNSIGNEDNOTNULL,'migration'varchar(255)COLLATEutf8mb4_unicode_ciNOTNULL,'batch'int(11)NOTNULL)ENGINE=InnoDBDEFAULTCHARSET=utf8mb4COLLATE=utf8mb4_unicode_ci;CREATETABLE'm_options'('id'int(10)UNSIGNEDNOTNULL,'name'varchar(255)COLLATEutf8mb4_unicode_ciNOTNULL)ENGINE=InnoDBDEFAULTCHARSET=utf8mb4COLLATE=utf8mb4_unicode_ci;CREATETABLE'm_option_values'('id'int(10)UNSIGNEDNOTNULL,'m_option_id'int(10)UNSIGNEDDEFAULTNULL)ENGINE=InnoDBDEFAULTCHARSET=utf8mb4COLLATE=utf8mb4_unicode_ci;CREATETABLE'options'('id'int(10)UNSIGNEDNOTNULL,'product_type_id'int(10)UNSIGNEDDEFAULTNULL,'name'varchar(255)COLLATEutf8mb4_unicode_ciNOTNULL)ENGINE=InnoDBDEFAULTCHARSET=utf8mb4COLLATE=utf8mb4_unicode_ci;CREATETABLE'option_values'('id'int(10)UNSIGNEDNOTNULL,'option_id'int(10)UNSIGNEDDEFAULTNULL)ENGINE=InnoDBDEFAULTCHARSET=utf8mb4COLLATE=utf8mb4_unicode_ci;CREATETABLE'password_resets'('email'varchar(255)COLLATEutf8mb4_unicode_ciNOTNULL,'token'varchar(255)COLLATEutf8mb4_unicode_ciNOTNULL)ENGINE=InnoDBDEFAULTCHARSET=utf8mb4COLLATE=utf8mb4_unicode_ci;CREATETABLE'products'('id'int(10)UNSIGNEDNOTNULL,'product_type_id'int(10)UNSIGNEDDEFAULTNULL,'category_id'int(10)UNSIGNEDDEFAULTNULL,'market_id'int(10)UNSIGNEDDEFAULTNULL,'shop_id'int(10)UNSIGNEDDEFAULTNULL,'country_id'int(10)UNSIGNEDDEFAULTNULL,'name'varchar(255)COLLATEutf8mb4_unicode_ciNOTNULL,'price'int(11)NOTNULL,'discount_price'int(11)NOTNULL,'discount'int(11)NOTNULL,'quantity'int(11)NOTNULL,'views'int(11)NOTNULL,'likes'int(11)NOTNULL,'sort_order'int(11)NOTNULL,'status'tinyint(4)NOTNULL)ENGINE=InnoDBDEFAULTCHARSET=utf8mb4COLLATE=utf8mb4_unicode_ci;CREATETABLE'product_m_option_values'('id'int(10)UNSIGNEDNOTNULL,'product_type_id'int(10)UNSIGNEDDEFAULTNULL,'m_option_id'int(10)UNSIGNEDDEFAULTNULL)ENGINE=InnoDBDEFAULTCHARSET=utf8mb4COLLATE=utf8mb4_unicode_ci;CREATETABLE'product_option_values'('id'int(10)UNSIGNEDNOTNULL,'product_id'int(10)UNSIGNEDDEFAULTNULL,'option_id'int(10)UNSIGNEDDEFAULTNULL,'option_value_id'int(10)UNSIGNEDDEFAULTNULL)ENGINE=InnoDBDEFAULTCHARSET=utf8mb4COLLATE=utf8mb4_unicode_ci;CREATETABLE'product_types'('id'int(10)UNSIGNEDNOTNULL,'category_id'int(10)UNSIGNEDDEFAULTNULL,'name'varchar(255)COLLATEutf8mb4_unicode_ciNOTNULL)ENGINE=InnoDBDEFAULTCHARSET=utf8mb4COLLATE=utf8mb4_unicode_ci;CREATETABLE'product_type_m_options'('id'int(10)UNSIGNEDNOTNULL,'product_type_id'int(10)UNSIGNEDDEFAULTNULL,'m_option_id'int(10)UNSIGNEDDEFAULTNULL,'m_option_value_id'int(10)UNSIGNEDDEFAULTNULL)ENGINE=InnoDBDEFAULTCHARSET=utf8mb4COLLATE=utf8mb4_unicode_ci;CREATETABLE'shops'('id'int(10)UNSIGNEDNOTNULL,'market_id'int(10)UNSIGNEDDEFAULTNULL,'name'varchar(255)COLLATEutf8mb4_unicode_ciNOTNULL,'address'varchar(255)COLLATEutf8mb4_unicode_ciNOTNULL,'product_types_count'int(11)NOTNULL,'products_count'int(11)NOTNULL,'views'int(11)NOTNULL,'photo'varchar(255)COLLATEutf8mb4_unicode_ciNOTNULL,'status'tinyint(4)NOTNULL)ENGINE=InnoDBDEFAULTCHARSET=utf8mb4COLLATE=utf8mb4_unicode_ci;ALTERTABLE'admins'ADDPRIMARYKEY('id'),ADDUNIQUEKEY'admins_username_unique'('username'),ADDUNIQUEKEY'admins_phone_unique'('phone'),ADDUNIQUEKEY'admins_email_unique'('email'),ADDKEY'admins_shop_id_foreign'('shop_id');ALTERTABLE'brands'ADDPRIMARYKEY('id');ALTERTABLE'brand_models'ADDPRIMARYKEY('id'),ADDKEY'brand_models_brand_id_foreign'('brand_id'),ADDKEY'brand_models_product_type_id_foreign'('product_type_id');ALTERTABLE'categories'ADDPRIMARYKEY('id'),ADDKEY'categories__lft__rgt_parent_id_index'('_lft','_rgt','parent_id');ALTERTABLE'countries'ADDPRIMARYKEY('id');ALTERTABLE'markets'ADDPRIMARYKEY('id');ALTERTABLE'migrations'ADDPRIMARYKEY('id');ALTERTABLE'm_options'ADDPRIMARYKEY('id');ALTERTABLE'm_option_values'ADDPRIMARYKEY('id'),ADDKEY'm_option_values_m_option_id_foreign'('m_option_id');ALTERTABLE'options'ADDPRIMARYKEY('id'),ADDKEY'options_product_type_id_foreign'('product_type_id');ALTERTABLE'option_values'ADDPRIMARYKEY('id'),ADDKEY'option_values_option_id_foreign'('option_id');ALTERTABLE'password_resets'ADDKEY'password_resets_email_index'('email');ALTERTABLE'products'ADDPRIMARYKEY('id'),ADDKEY'products_product_type_id_foreign'('product_type_id'),ADDKEY'products_category_id_foreign'('category_id'),ADDKEY'products_market_id_foreign'('market_id'),ADDKEY'products_shop_id_foreign'('shop_id'),ADDKEY'products_country_id_foreign'('country_id');ALTERTABLE'product_m_option_values'ADDPRIMARYKEY('id'),ADDKEY'product_m_option_values_product_type_id_foreign'('product_type_id'),ADDKEY'product_m_option_values_m_option_id_foreign'('m_option_id');ALTERTABLE'product_option_values'ADDPRIMARYKEY('id'),ADDKEY'product_option_values_product_id_foreign'('product_id'),ADDKEY'product_option_values_option_id_foreign'('option_id'),ADDKEY'product_option_values_option_value_id_foreign'('option_value_id');ALTERTABLE'product_types'ADDPRIMARYKEY('id'),ADDKEY'product_types_category_id_foreign'('category_id');ALTERTABLE'product_type_m_options'ADDPRIMARYKEY('id'),ADDKEY'product_type_m_options_product_type_id_foreign'('product_type_id'),ADDKEY'product_type_m_options_m_option_id_foreign'('m_option_id'),ADDKEY'product_type_m_options_m_option_value_id_foreign'('m_option_value_id');ALTERTABLE'shops'ADDPRIMARYKEY('id'),ADDKEY'shops_market_id_foreign'('market_id');
Inprecedenzahoutilizzatosolo%diricerchebasatesu%co_de,manell'e-commercedovròutilizzarelaricercaditestocompleto.LaricercadeveesseredallacolonnaLIKE
diognitabellaincuièpresentelacolonnaname
.
PeroravoglioindicizzareilmiodatabasesoloinMySQLmanonsonosicurodipoterlofareeseèaddiritturapossibileconquestotipodistruttura.
Piùavanti,quandoavròabbastanzatempoperimparareElasticsearch,hointenzionediusarloperl'indicizzazione.
Voglioconoscereletueopinionisulmiodatabaseericevereituoiconsigliperlamiaricerca.
- ÈlamigliorestrutturadelDBodovreicambiarequalcosa?
- Saràbuonoperlaricerca?
- QuestastrutturaDBèindicizzabileinMySQL?
- QuestastrutturaDBèindicizzabileinElasticsearch?
Modifica
Nonvoglioordinietuttociòcheèrelativoadesso.Perchénonriescoagestirloenonpensochesaràutilenellanostracittà,perora.Ilmiositosaràpropriocomeuncatalogo,dovepuoivederequaleprodottoinqualenegozioaqualeprezzo.Quindisevuoipuoiandareacomprarlodalì.Mahointenzionediaggiungere"Ordine" più tardi.