ryan19961996

洗数据:如何将 Contact 和 ContactTag 多对多关联起来

  •  
  •   ryan19961996 · Jan 24, 2024 · 1323 views
    This topic created in 847 days ago, the information mentioned may be changed or developed.
    model Contact {
      id               String              @id @default(cuid())
      metadata         Json?               @db.JsonB
      contactTags      ContactTag[]
      ...
      @@index([metadata(ops: JsonbPathOps)], type: Gin)
    }
    
    model ContactTag {
      id          String      @id @default(cuid())
      slug        String
      contacts    Contact[]
      ...
    }
    

    由于历史遗留原因,Contact 和 ContactTag 之前没有关联关系。Contact 的 metadata 里面冗余了一份 tags,类似 {tags:["newsletter","new-customer"]}。通过标签筛选 Contact 的时候,是通过 查找 metadata 的 tags 。但是效率确实太低了, Contact 表的数量很多,大概是 1350 万行。所以我们想额外加一个表存储关联关系。请教一下各位大佬,相应的 sql 怎么写?

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1361 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 17:13 · PVG 01:13 · LAX 10:13 · JFK 13:13
    ♥ Do have faith in what you're doing.