From fa1695107f820256cd3298067d31c2e4fea8b13c Mon Sep 17 00:00:00 2001 From: n0099 Date: Sat, 18 May 2024 21:02:30 +0800 Subject: [PATCH] * fix https://github.com/n0099/open-tbm/issues/48#issuecomment-2118794316 and https://dba.stackexchange.com/questions/146294/why-does-postgresql-perform-a-seq-scan-when-comparing-a-numeric-value-with-a-big/339617#339617 by explicitly setting column type `bigint` for all entity fields which typed with `ulong` @ c# --- c#/crawler/src/Db/Post/BasePost.cs | 1 + c#/crawler/src/Db/Post/PostContent/ReplyContent.cs | 3 ++- c#/crawler/src/Db/Post/PostContent/SubReplyContent.cs | 3 ++- c#/crawler/src/Db/Post/ReplyPost.cs | 3 ++- c#/crawler/src/Db/Post/SubReplyPost.cs | 4 +++- c#/crawler/src/Db/Post/ThreadMissingFirstReply.cs | 3 ++- c#/crawler/src/Db/Post/ThreadPost.cs | 1 + c#/crawler/src/Db/Revision/Splitting/ReplyRevisions.cs | 1 + c#/crawler/src/Db/Revision/Splitting/SubReplyRevisions.cs | 1 + c#/crawler/src/Db/Revision/Splitting/ThreadRevisions.cs | 1 + c#/shared/src/Db/ReplyContentImage.cs | 3 +++ 11 files changed, 19 insertions(+), 5 deletions(-) diff --git a/c#/crawler/src/Db/Post/BasePost.cs b/c#/crawler/src/Db/Post/BasePost.cs index a5ed3dbc..a8c7eead 100644 --- a/c#/crawler/src/Db/Post/BasePost.cs +++ b/c#/crawler/src/Db/Post/BasePost.cs @@ -4,6 +4,7 @@ namespace tbm.Crawler.Db.Post; public abstract class BasePost : TimestampedEntity, ICloneable { + [Column(TypeName = "bigint")] public ulong Tid { get; set; } public long AuthorUid { get; set; } public uint? LastSeenAt { get; set; } diff --git a/c#/crawler/src/Db/Post/PostContent/ReplyContent.cs b/c#/crawler/src/Db/Post/PostContent/ReplyContent.cs index f698966b..79668049 100644 --- a/c#/crawler/src/Db/Post/PostContent/ReplyContent.cs +++ b/c#/crawler/src/Db/Post/PostContent/ReplyContent.cs @@ -3,5 +3,6 @@ namespace tbm.Crawler.Db.Post.PostContent; public class ReplyContent : BasePostContent { - [Key] public ulong Pid { get; set; } + [Key] [Column(TypeName = "bigint")] + public ulong Pid { get; set; } } diff --git a/c#/crawler/src/Db/Post/PostContent/SubReplyContent.cs b/c#/crawler/src/Db/Post/PostContent/SubReplyContent.cs index 65e12da9..6409b7e2 100644 --- a/c#/crawler/src/Db/Post/PostContent/SubReplyContent.cs +++ b/c#/crawler/src/Db/Post/PostContent/SubReplyContent.cs @@ -3,5 +3,6 @@ namespace tbm.Crawler.Db.Post.PostContent; public class SubReplyContent : BasePostContent { - [Key] public ulong Spid { get; set; } + [Key] [Column(TypeName = "bigint")] + public ulong Spid { get; set; } } diff --git a/c#/crawler/src/Db/Post/ReplyPost.cs b/c#/crawler/src/Db/Post/ReplyPost.cs index 501cea12..f4baf6ce 100644 --- a/c#/crawler/src/Db/Post/ReplyPost.cs +++ b/c#/crawler/src/Db/Post/ReplyPost.cs @@ -3,7 +3,8 @@ namespace tbm.Crawler.Db.Post; public class ReplyPost : PostWithAuthorExpGrade { - [Key] public ulong Pid { get; set; } + [Key] [Column(TypeName = "bigint")] + public ulong Pid { get; set; } public uint Floor { get; set; } public required ReplyContent Content { get; set; } diff --git a/c#/crawler/src/Db/Post/SubReplyPost.cs b/c#/crawler/src/Db/Post/SubReplyPost.cs index 9da554b0..ff8fd48a 100644 --- a/c#/crawler/src/Db/Post/SubReplyPost.cs +++ b/c#/crawler/src/Db/Post/SubReplyPost.cs @@ -3,8 +3,10 @@ namespace tbm.Crawler.Db.Post; public class SubReplyPost : PostWithAuthorExpGrade { + [Column(TypeName = "bigint")] public ulong Pid { get; set; } - [Key] public ulong Spid { get; set; } + [Key] [Column(TypeName = "bigint")] + public ulong Spid { get; set; } public required SubReplyContent Content { get; set; } [JsonConverter(typeof(ProtoBufRepeatedFieldJsonConverter))] diff --git a/c#/crawler/src/Db/Post/ThreadMissingFirstReply.cs b/c#/crawler/src/Db/Post/ThreadMissingFirstReply.cs index 269c3075..040f631c 100644 --- a/c#/crawler/src/Db/Post/ThreadMissingFirstReply.cs +++ b/c#/crawler/src/Db/Post/ThreadMissingFirstReply.cs @@ -3,7 +3,8 @@ namespace tbm.Crawler.Db.Post; public class ThreadMissingFirstReply : RowVersionedEntity { - [Key] public ulong Tid { get; set; } + [Key] [Column(TypeName = "bigint")] + public ulong Tid { get; set; } public ulong? Pid { get; set; } public byte[]? Excerpt { get; set; } public uint? LastSeenAt { get; set; } diff --git a/c#/crawler/src/Db/Post/ThreadPost.cs b/c#/crawler/src/Db/Post/ThreadPost.cs index 6b66e86f..2c67a1ea 100644 --- a/c#/crawler/src/Db/Post/ThreadPost.cs +++ b/c#/crawler/src/Db/Post/ThreadPost.cs @@ -9,6 +9,7 @@ public class ThreadPost : BasePost [JsonConverter(typeof(ProtoBufRepeatedFieldJsonConverter))] [NotMapped] public RepeatedField? FirstReplyExcerpt { get; set; } + [Column(TypeName = "bigint")] public ulong ThreadType { get; set; } public string? StickyType { get; set; } public string? TopicType { get; set; } diff --git a/c#/crawler/src/Db/Revision/Splitting/ReplyRevisions.cs b/c#/crawler/src/Db/Revision/Splitting/ReplyRevisions.cs index d01b85d4..d77be7ff 100644 --- a/c#/crawler/src/Db/Revision/Splitting/ReplyRevisions.cs +++ b/c#/crawler/src/Db/Revision/Splitting/ReplyRevisions.cs @@ -5,6 +5,7 @@ namespace tbm.Crawler.Db.Revision.Splitting; public abstract class BaseReplyRevision : RevisionWithSplitting { + [Column(TypeName = "bigint")] public ulong Pid { get; set; } } diff --git a/c#/crawler/src/Db/Revision/Splitting/SubReplyRevisions.cs b/c#/crawler/src/Db/Revision/Splitting/SubReplyRevisions.cs index 0f514fd2..d1a47b7e 100644 --- a/c#/crawler/src/Db/Revision/Splitting/SubReplyRevisions.cs +++ b/c#/crawler/src/Db/Revision/Splitting/SubReplyRevisions.cs @@ -5,6 +5,7 @@ namespace tbm.Crawler.Db.Revision.Splitting; public abstract class BaseSubReplyRevision : RevisionWithSplitting { + [Column(TypeName = "bigint")] public ulong Spid { get; set; } } diff --git a/c#/crawler/src/Db/Revision/Splitting/ThreadRevisions.cs b/c#/crawler/src/Db/Revision/Splitting/ThreadRevisions.cs index 6764c6ae..e99393f3 100644 --- a/c#/crawler/src/Db/Revision/Splitting/ThreadRevisions.cs +++ b/c#/crawler/src/Db/Revision/Splitting/ThreadRevisions.cs @@ -5,6 +5,7 @@ namespace tbm.Crawler.Db.Revision.Splitting; public abstract class BaseThreadRevision : RevisionWithSplitting { + [Column(TypeName = "bigint")] public ulong Tid { get; set; } } diff --git a/c#/shared/src/Db/ReplyContentImage.cs b/c#/shared/src/Db/ReplyContentImage.cs index 6892fde8..be069f1c 100644 --- a/c#/shared/src/Db/ReplyContentImage.cs +++ b/c#/shared/src/Db/ReplyContentImage.cs @@ -1,8 +1,11 @@ // ReSharper disable PropertyCanBeMadeInitOnly.Global +using System.ComponentModel.DataAnnotations.Schema; + namespace tbm.Shared.Db; public class ReplyContentImage : EntityWithImageId { + [Column(TypeName = "bigint")] public ulong Pid { get; set; } public required ImageInReply ImageInReply { get; set; } }